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:

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 Haroldelharo@metalab.unc.eduLast Modified January 20, 2002
Up To Cafe con Leche