Is it the case that IE11 doesn't like the location axis in an XPath query? I'm trying to run the following command in that browser:
DOMDocument.selectNodes('//library/ancestor::stores')
and the error that IE11 gives me is
Expected token 'eof' found ':'.
//library/ancestor-->:<--:stores
Chrome and other browsers have no problem with it but IE11 cries like a baby? I've been searching around and can't really find a reason why this is happening apart from a vague allusion to the fact that the browser might be using an old version of MSXML. Is there something I can do to get it working in that browser? If not is there an alternative axis that can be used?
EDIT: One thing I want to point out -- the issue isn't necessarily related to whether or not the xpath query is valid. IE11 isn't complaining about the validity of the query, it's complaining about the "::" location axis.
thnx,
Christoph
The issue is related with the MSXML version you used in IE. If you use MSXML 3.0, it will use the old XSLPattern language as the query language which will cause the issue.
As a workaround, you can use MSXML 6.0 which uses XPath language by default. The working sample in IE 11 is like below. My books.xml is the same as this example.:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var txt = "";
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.6.0"); //use MSXML 6.0
xmlDoc.async = false;
xmlDoc.load("books.xml");
var nodes = xmlDoc.selectNodes('/bookstore/book/child::title');
for (i = 0; i < nodes.length; i++) {
txt += nodes[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
If you're using MSXML 3.0, you can use SelectionLanguage Property like below. It will also work in IE 11:
var xmlDoc = new ActiveXObject("MSXML.DOMDocument");
xmlDoc.setProperty("SelectionLanguage", "XPath");