O'Reilly logo

Beginning XML, 4th Edition by Andrew Watt, David Hunter, Linda McKinnon, Joe Fawcett, Eric van der Vlist, Jon Duckett, Danny Ayers, Jeff Rafter

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

Appendix B. XPath Reference

XPath is a well-established W3C specification that describes a non-XML syntax for selecting a set of nodes from the in-memory model of an XML document. XPath version 1.0 reached W3C Recommendation status on November 16, 1999. The specification documents for XPath 2.0, which is a subset of XQuery 1.0, were in late Working Draft stage at the time of this writing. XPath, both 1.0 and 2.0, is an essential part of the corresponding XSLT specification. This appendix focuses on XPath 1.0.

An XPath location path contains one or more location steps, separated by forward slashes (/). Each location step has the following form:

axis-name::node-test[predicate]*

In plain English, this is an axis name, followed by two colons, a node test, and, finally, zero or more predicates each contained in square brackets. A predicate can contain literal values (for example, 4 or 'hello'), operators (+, -, =, and so on), and other XPath expressions. XPath also defines a set of functions that can be used in predicates.

An XPath axis defines how to select a part of the model of an XML document, from the perspective of a starting point called the context node. The context node serves as the starting point for selecting the result of an XPath expression. The node test makes a selection from the nodes on the specified axis. In other words, a node test filters the nodes in the specified axis. By adding predicates, it is possible to filter any nodes already selected by selecting a subset of ...

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