XPath, a Query Language for Selecting XML Nodes

XPath provides a common semantics and syntax for functionality shared between XPointer and XSL Transformations. XPath stands for XML Path Language that uses a concise non-XML syntax to ensure a flexible way of addressing various parts of an XML document.  XPath can also be used to identify nodes in a document and determine whether they fit the pattern or not. The name of the XPath language was derived from the path expression which is its most distinctive feature.


XPath is typically used in XSLT but it can be also used to navigate through DOM of any XML-like language document, for example, XUL and HTML. It got its name because it uses a path notation as in URLs to navigate through the hierarchical structure of various XML documents.



The main syntactic construct in XPath is the expression that determines a pattern for selecting a specific set of nodes. Such patterns are used by XPointer to address a purpose and by XSLT to do certain transformations. XPath uses path expressions to choose nodes in an XML document.  


XPath presents an XML document as a tree of different types of nodes, for example, element nodes, text nodes, document nodes, attribute nodes, etc. and determines ways to compute a string-value for every type of node.  


XPath has a rich library of over 200 built-in standard functions that include functions for numeric values, string values, Boolean values, sequence manipulation, node manipulations, date and time comparison, and more.


XPath was developed to support XPointer and XSLT and it is a major element in the XSLT standard. These days, it is also used by XQuery and other applications. Different programming languages support its library. Currently, XPath expressions can be also used in Java, JavaScript, XML Schema, Python, PHP, C, C++, and plenty of other languages.


Related Projects