TreeWalker

The purpose of TreeWalker is much the same as that of NodeIterator—traversing a subtree of a document rooted at a particular node and filtered by both node type and custom logic. TreeWalker differs from NodeIterator in that the traversal model is based on a tree with parents, children, and sibling nodes rather than a linear list with only previous and next nodes. Because the traversal model is very similar to what's already available in the Node interface, tree-walkers aren't as commonly used as NodeIterator. But the ability to filter the nodes that appear in the tree can be very useful on occasion.

Example 12.7 summarizes the TreeWalker interface. It has getter methods that return the configuration of the TreeWalker, methods to get ...

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.