Tip, Traversing an XML document with a TreeWalker

Navigate your DOM tree while maintaining parental relationships

From the developerWorks archives

Nicholas Chase

Date archived: February 24, 2017 | First published: October 01, 2002

XML's Document Object Model provides objects and methods that enable a developer to navigate a document's tree, but typically the process involves NodeLists and recursive methods that make it easy to get lost within the structure. The DOM Level 2 Traversal module provides a new object, the TreeWalker, which simplifies this process and makes navigation more reliable. This tip demonstrates the process of determining whether a TreeWalker is available and how to use it to extract information from a document.

This content is no longer being updated or maintained. The full article is provided "as is" in a PDF file. Given the rapid evolution of technology, some steps and illustrations may have changed.



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=12175
ArticleTitle=Tip: Traversing an XML document with a TreeWalker
publish-date=10012002