XPath is W3C recommended language which can access nodes or node-sets of an XML document. In large XML documents with numerous nodes, XPath parser helps to point and fetch the right node.

An XPath expression specifies a pattern which can be used to select the XML node. XPath has various kinds of nodes like element, attribute, text, namespace, processing instruction, comment and document nodes. This language provides standard functions for manipulation of string values, numeric values, node and Qname manipulation, sequence manipulation, boolean values etc...

XPath parsing is important to use with XSLT, XQuery and XPointer.

Consider an example below:

Basic example with Xpath in XML

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

<root>

    <employee>       

        <office>

            <dept id="accounts">

            <name>Raju</name>

            </dept>

        </office>       

    </employee>

    <student>

        <school>

            <name>Lucy</name>

        </school>

    </student>

</root>

The expression for selecting a node say, office from root is /root/employee/office. The Xpath syntax is similar to the file system addressed in Windows. The XPath expressions should be used with other languages like XPointer, XSLT, Java, JavaScript…etc to be functional.

 

›› go to examples ››