Search code examples
javascriptxmlxpathxpathnavigator

What's wrong with UNORDERED_NODE_ITERATOR_TYPE with a specific xml document?


I'm having a trouble by retrieving the elements of an xml document. I got it through a request, parsed, and then I did the following:

var results = xDoc.evaluate(
    "pets/pet[@name='Foo']",
    xDoc, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null 
);

var node = results.iterateNext(), i=0;
while (node) {
    node = results.iterateNext();
    i = i++;
}

The xml has:

<pets>
      <pet name='Foo'/>
      <pet name='Bar'/>
      <pet name='Foo'/>
      <pet name='Foo'/>
</pets>

The thing is while statement is never executed. But the nodes in xml does exist and the xDoc is well parsed, cause I can retrieve single nodes values. So, what am I missing?


Solution

  • Don't know why, but for certain operations the xml document wasn't right. I removed the xmlns="http://www.w3.org/1999/xhtml" attribute of every node ant it started working with every operation, even the one posted here.