XPath

XPath is a language for selecting nodes from an XML document. It can also be used to compute values in the context of an XML document.

XPath is used in XPointer, XInclude, XSD, Schematron, XQuery, XSLT, and XForms. XPath can be evaluated in GUI tools such as XML ValidatorBuddy and online tools such as https://www.videlibri.de/cgi-bin/xidelcgi.

XPath 3.1 (21 Mar 2017) is the last version published as a full W3C Recommendation. It adds support for arrays, maps, and arrow-chaining (=>) of functions. XPath 4.0 is under active development by the W3C's QT4CG (XQuery and XSLT 4.0 Community Group) as a series of Community Group drafts; it is not yet a W3C Recommendation and its details are still evolving. XPath 4.0 is a superset of 3.1, adding native JSON support (rather than only XML) and many new functions.

This section covers:

<?xml version="1.0"?>
<menu restaurant="Golden Outlet">
   <dish id="1">Satay <i>Cooked</i></dish>
   <drink id="2">Cola</drink>
   <dish id="3">Curry Chicken</dish>
</menu>

<!-- Example XPath expressions against the document above -->
<!-- //dish            selects all <dish> nodes anywhere in the document -->
<!-- /menu/@restaurant  selects the restaurant attribute of the root element -->