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 ...
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