Summary

Both NodeIterator and TreeWalker can simplify the traversal of nodes of interest in a document. NodeIterator presents nodes as a one-dimensional list. TreeWalker presents them as a tree. That difference aside, the behavior and purpose of these two interfaces is much the same.

Both NodeIterator and TreeWalker traverse a subtree of the nodes in the document. Exactly which nodes belong in this subtree depends on four factors:

  • The root node of the subtree (which often is not the root node or root element of the document). Only this node and its descendants will be seen by the TreeNodeIterator/Walker.

  • whatToShow, an int constant that contains bit flags identifying which types of nodes to include. The basic bit flags for these constants are ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.