What is XPATH?

What Is XPATHThe World Wide Web Consortium (W3C) defines XPATH (1.0, 2.0, 3.0)  as follows: XPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer.

The quoted definition from the W3C is correct, however, we feel that a better definition would be: XPATH is a path addressing language that describes a way to locate and process items or information in an XML document’s hierarchy. The use of XPATH is not limited to only XSLT and XPointer; This is due to the versatility of the XPATH language which allows it to be used in more scenarios than just XSLT and XPointer – Elsewhere on this site you will see examples on how to use XPATH through programming languages and other methods to evaluate an XML document and process/calculate values at the same time.

Summarized: XPATH is a path language for XML documents. In simpler terms: XPATH is to XML as SQL is to a relational database.

The basis of XPATH is the expression. An XPATH expression is a combination of one or more of the following:

  • Expression syntax appears much like a file system path to address the hierarchical nature of an XML document.
  • A standard library of functions for text/string manipulation, math, date, time, Boolean, nodes, sequences and etc.
  • Operators such as math (+, –, *, division), equality (=, !=, <, >,…) and sets (|).
  • Predicates to assist in node selection.
  • Axis to assist in node selection.
  • Wildcards to assist in node selection.

The end-result is a query expression capable of node selections and value computation that is geared specifically for XML documents and the manipulation:

  • XPATH and XSLT together provides a mechanism to interrogate and transform a source XML document into a desired target document (with structure and values).
  • XPATH and a programming language – such as Java, C#, Visual Basic, JavaScript and etc… – provides a method to interrogate and manipulate an XML document in a terse and concise manner.

Posted in XPATH and tagged .

Leave a Reply