O'Reilly logo

Sams Teach Yourself XML in 10 Minutes by Andrew H. Watt

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

Accessing Elements

A common and important use of XPath involves being able to access elements—or, more precisely, element nodes. XPath provides ways to select element nodes either by their relationship to another node or by name.

Consider a source document of the following structure:

<report> 
 <author>John Smith</author> 
 <date>2002/12/19</date> 
 <title>Safety Assessment for Greenland Tropical Tours</title> 
 <chapter number="1">Some text</chapter> 
 <chapter number="2">Some text</chapter> 
 <chapter number="3">Some text</chapter> 
 <appendix>Some appendix stuff</appendix> 
</report> 

You can select all the child element nodes of the report element node by the following XPath location path:

/report/* 

The / at the beginning of the location path indicates ...

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