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. However, otherwise 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 is often not the root node or root element of the document). Only this node and its descendants will be seen by the NodeIterator/TreeWalker.
whatToShow, an int constant containing bit-flags identifying which types of nodes to include. The basic bit flags for these constants are available as public final static variables in the NodeFilter interface; e.g. NodeFilter.SHOW_ELEMENT, NodeFilter.SHOW_COMMENT, NodeFilter.SHOW_TEXT, etc.
A NodeFilter object whose acceptNode() method returns NodeFilter.FILTER_ACCEPT, NodeFilter.FILTER_REJECT or NodeFilter.FILTER_SKIP for each node passed to it.
A boolean flag specifying whether or not to expand entity references.
Each of these is specified when the NodeIterator or TreeWalker is created by the createNodeIterator()/createTreeWalker() method in the DocumentTraversal interface. In a DOM implementation that supports the traversal module, all classes that implement the Document interface also implement the DocumentTraversal interface, so you can create a NodeIterator or TreeWalker over a document by casting the corresponding Document object to DocumentTraversal.
|Copyright 2001, 2002 Elliotte Rusty Haroldemail@example.com||Last Modified January 20, 2002|
|Up To Cafe con Leche|