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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access