The NodeIterator utility interface extracts a subset of the nodes in a DOM document and presents them as a list arranged in document order. In other words, the nodes appear in the order in which you would find them in a depth-first, preorder traversal of the tree. That is,

  • The document node comes first.

  • Parents come before their children; ancestors come before their descendants.

  • Sibling nodes appear in the same order as their start-tags in the text representation of the document.

This is pretty much the order you would expect just by reading an XML document from beginning to end. As soon as you see the first character of text from a node, that node is counted.

You can iterate through this list without concerning yourself with the tree ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.