XPath uses path expressions to select nodes or node sets in an XML document. An XPath location path has one or more location steps, each separated by ‘/’. The location path can be an absolute path or relative path.

Example of XPath syntax

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




            <dept id="accounts">







Absolute location path begins with the root node

For XML document given, the absolute path is:


Relative location path begins from current folder the path is defined from

For XML document given, the relative path from employee node can be:


Each step is defined as:



  • axis-name – is the path between selected nodes and current nodes.
  • node-test – is the node within an axis.
  • predicate – extract the selected node-set. It can contain literal values, operators and other XPath expressions.

The syntax to access elements, attributes are given in following tutorials.


›› go to examples ››