I have some JavaScript/Xpath which isn't working as I would expect. (available on jsfiddle) It would seem that I'm doing something wrong with an XML namespace, preventing me from querying for my elements by their node (tag) names.
If I try querying for all child nodes of the current node, I find the element myElement
without problem:
var xpathResult = xmlDoc.evaluate( "child::*", rootElement, nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
var queryEl;
if(queryEl = xpathResult.iterateNext()) {
alert("child::* found element " + queryEl.nodeName);
}
else {
alert("child::* found nothing!");
}
... but if I specifically target the nodes with myElement
node (tag) names I get no results:
/* Now try getting only those children with nodeName `myElement` */
xpathResult = xmlDoc.evaluate( "child::myElement", rootElement, nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
var queryEl;
if(queryEl = xpathResult.iterateNext()) {
alert("child::myElement found element " + queryEl.nodeName);
}
else {
alert("child::myElement found nothing!");
}
What am I doing wrong?