"> " />
Easy Tutorial

XPath Axes


XML Example Document

We will use the following XML document in the examples below:

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>
  <title lang="en">Harry Potter</title>
  <price>29.99</price>
</book>

<book>
  <title lang="en">Learning XML</title>
  <price>39.95</price>
</book>

</bookstore>

XPath Axes

Axes define a set of nodes relative to the current node.

Axis Name Result
ancestor Selects all ancestors (parent, grandparent, etc.) of the current node.
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself.
attribute Selects all attributes of the current node.
child Selects all child elements of the current node.
descendant Selects all descendant elements (children, grandchildren, etc.) of the current node.
descendant-or-self Selects all descendant elements (children, grandchildren, etc.) of the current node and the current node itself.
following Selects all nodes that appear after the end tag of the current node in the document.
following-sibling Selects all sibling nodes that follow the current node.
namespace Selects all namespace nodes of the current node.
parent Selects the parent node of the current node.
preceding Selects all nodes that appear before the start tag of the current node in the document.
preceding-sibling Selects all sibling nodes that precede the current node.
self Selects the current node.