XPath Basics

XPath got its name from its use of path-based syntax for traversing a document's Infoset. XPath syntax is very similar to those used to traverse file systems or other hierarchical structures. The following is an example of an XPath expression that locates all model elements that are children of guitar elements, which are themselves children of the root node guitars in some arbitrary XML document:

/guitars/guitar/model

XPath defines its own data model in parallel with the Infoset. This data model is based on a tree of nodes. As shown in Table 3.1, XPath defines seven node types that can be part of an XPath tree. The node-based tree-model of XPath has obvious parallels to the [parent]/[children] model of the Infoset.

The properties ...

Get Essential XML: Beyond Markup now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.