O'Reilly logo

XML Hacks by Michael Fitzgerald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Analyze Nodes with TreeViewer

View nodes in an XML document according to the XPath 1.0 data model.

The XPath 1.0 data model (http://www.w3.org/TR/xpath#data-model) views XML documents as containing seven possible node types:

Mike Brown and Jeni Tennison have created several stylesheets, available at http://skew.org/xml/stylesheets/treeview/, that visually represent all seven of the XPath node types. Such tools can be useful when trying to uncover less obvious nodes (namespace or whitespace-only text nodes) or when just learning about the XPath model. These stylesheets allow you to view an XML tree either in ASCII (ascii-treeview.xsl) or in HTML (tree-view.xml with tree-view.css). All three are available in the working directory where you extracted the file archive for the book.

When you apply ascii-treeview.xsl to time.xml using an XSLT processor such as Xalan by using this command:

xalan time.xml ascii-treeview.xsl

it will produce the text tree view of time.xml shown in Example 3-5.

Example 3-5. Output from ascii-treeview.xsl

root |_ _ _comment ' a time instant ' |_ _ _element 'time' | \_ _ _attribute 'timezone' = 'PST' |_ _ _text '\n ' |_ _ _element 'hour' | |_ _ _text '11' |_ _ _text '\n ' |_ _ _element 'minute' | |_ _ _text '59' |_ _ _text '\n ' |_ _ _element 'second' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required