In XPath, X stands for nodes and path stands for the nodes from root which has to be passed to reach destination.  Axes of XPath define node set from the perspective of a starting point node called context node. From context node as starting point, the XPath expression is selected.

Consider tree diagram explaining hierarchy of nodes in XML document:

XPath axes illustration

The table below defines axis name and its descendants

AxisName Result
ancestor Selects all ancestors of current node
ancestor-or-self Selects all ancestors of current node and node itself
attribute Selects all attribute of current node
child Selects all children of current node
descendant Selects all descendants of current node
descendant-or-self Selects all descendants of current node and node itself
following Selects everything in the document after the closing tag of current node.
following-sibling Selects all siblings after the current node
namespace Selects all namespaces nodes of current node
parent Selects parent of current node
preceding Selects all nodes that appear before the current node except attribute and namespace node
preceding-sibling Selects all siblings before current node
self Selects current node

Example using axes names

child::Root

This axis selects element nodes from Root node.

child::*[@id]

This axis selects child elements from context node with attribute ‘id‘.

 

›› go to examples ››