XPath axes (Axes)
XML instance documents
We will use this XML document in the following example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
XPath axes (Axes)
Axis can be defined with respect to the set of nodes of the current node.
Axis name | result |
---|---|
ancestor | Select all ancestors of the current node (parent, grandparent, etc.). |
ancestor-or-self | Select all ancestors of the current node (parent, grandparent, etc.) and the current node itself. |
attribute | Select all the attributes of the current node. |
child | Selects all child elements of the current node. |
descendant | Select all descendants of the current node elements (promoter, Sun, etc.). |
descendant-or-self | Select all descendants of the current node elements (promoter, Sun, etc.) and the current node itself. |
following | Select all nodes in the document after the closing tag of the current node. |
namespace | Select all namespaces of the current node. |
parent | Select the parent of the current node. |
preceding | Select all the nodes in the document before the start tag of the current node. |
preceding-sibling | Select all siblings before the current node. |
self | Select the current node. |