XML : XPath selection not working in Microsoft Edge (works in Chrome and Firefox)

When trying to select a specific row or set of rows from an XML Document Microsoft Edge always returns the first row. The other browser handle the selection just fine.

I've made a small demonstration using the exact same code and XML as on the website in question.

https://jsbin.com/wufoyisudi/edit?html,output

when entering 'aar' in the textbox en pressing submit the first PortERPID of the first row is returnerd. However when entering 'abi' in the textbox the PortERPID of the second row should be returned. This works fine in Chrome and Firefox but doesn't work in Microsoft edge.

XML:

  <ROOT>  <FAKE>      <row PortERPID="DKAAR" PortName="AARHUS"/>      <row PortERPID="CIABJ" PortName="ABIDJAN"/>  </FAKE>  </ROOT>    

JavaScript:

  var val = document.getElementById("filter").value;  var xml = '<ROOT><FAKE>' +             '<row PortERPID="DKAAR" PortName="AARHUS"/>' +             '<row PortERPID="CIABJ" PortName="ABIDJAN"/>' +             '</FAKE></ROOT>';    var parser=new DOMParser();  xmlDoc=document.implementation.createDocument("","",null);  xmlDoc.async="false";                 xmlDoc = parser.parseFromString(xml,"text/xml");    var portsERPIDXpath = "//row[@PortName[contains(translate(.,'abcdefghijklmnopqrstuvwxyz'," + " 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'" + val.toUpperCase() + "')]]/@PortERPID";  var ERPIDS = xmlDoc.evaluate(portsERPIDXpath, xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);  var ERPID = ERPIDS.snapshotItem(0).value;  document.getElementById("result").innerHTML = ERPID;    

Keep in mind that this is old code that's going to get replaced by a new system so completely rewriting is not an option.

Any ideas on a possible fix/workaround?

No comments:

Post a Comment