How do you run an xPath query in IE11? How do you run an xPath query in IE11? xml xml

How do you run an xPath query in IE11?


Thanks to @Martin Honnen for pointing out that some ActivXObjects are still supported in IE11!

var doc;try {     doc = new ActiveXObject('Microsoft.XMLDOM');     doc.loadXML(stringVarWithXml);     var node = doc.selectSingleNode('//foo'); } catch (e) { // deal with case that ActiveXObject is not supported }

I've used "Microsoft.XMLDOM" as it is sugested here that it is a more generic call to what ever xml parser is present on the system, where as it sounds like "Msxml2.DOMDocument.6.0" will fail if that exact version is not present. (We do have to support all IE vers back to 6.0 at my place!)

This just works as it always has done. The only problem I had was that the old switch I used to detect IE vs other browsers was if (typeof ActiveXObject !== "undefined") failed as I guess they are trying to discourage it's use!

Thanks all for your help.


To expand on pixelmatt's answer, some results of my tests (Win 7 64bit with IE11) I did in order to get DOMParser to work as it did in IE9 and IE10 (in IE11 it now returns an XMLDocument object which appears to not support xpath queries?).

Turns out I could make it behave like in IE10 with the following meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=10" />

Results without and with above meta:IE11 default modeIE11 in IE10 mode

And here are the XMLDocument's memebers (for reference):enter image description here