1

How I use org.w3c.dom.traversal.NodeIterator for iterate Nodes in java using Xpath

I have the follos code but doesn't work.

    import org.w3c.dom.traversal.NodeIterator;

    NodeIterator products = XPathAPI.selectNodeIterator(document, "/ONIXMessage/Product");
    while(products.hasNext()) {
        Node element = products.nextNode(); 
        .......
    }

I don't know what I have to put in the while condition

josepmra
  • 617
  • 9
  • 25

1 Answers1

2

A W3C DOM NodeIterator should be used as follows:

Node node;
while ((node = products.nextNode()) != null)
{
  ...
}

If you still have problems then show us a sample of the XML input. Usually namespaces are the reason that XPath expressions don't select what users want them to select.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110