The primary purpose of XPath is to address parts of an XML document. It also provides basic facilities for manipulation of strings, numbers and booleans. XPath uses a compact, non-XML syntax. XPath operates on the abstract, logical structure of an XML document, rather than its surface syntax.
XPath is the result of an effort to provide a common syntax and semantics for functionality shared between XSL Transformations XSLT and XPointer.
The primary purpose of XPath is to address parts of an XML document. In support of this primary purpose, it also provides basic facilities for manipulation of strings, numbers and booleans. XPath uses a compact, non-XML syntax to facilitate use of XPath within URIs and XML attribute values. XPath operates on the abstract, logical structure of an XML document (for example XDM, or DOM), rather than its surface syntax. XPath gets its name from its use of a path notation as in URLs for navigating through the hierarchical structure of an XML document.
Besides XSLT and XPointer, XPath is now used in other host languages such as XQuery, XML Schema, Schematron, and Selenium.
What is XPath?
- XPath is a syntax for defining parts of an XML document.
- XPath uses path expressions to navigate in XML documents.
- XPath contains a library of standard functions.
- XPath is a major element in XSLT.
- XPath is a W3C recommendation.
Tools
The XPath Visualizer is a local HTML and JavaScript application for teaching XPath 1.0 by example. Just load your XML file, repeatedly enter any XPath expression and immediately see the result highlighted in the XML document (if node-set) or in a separate dialog box (otherwise).
XPath Online Tools
There are a number of XPath online tools available including
- PathEnq XPath 2.0 Editor runs Saxon-CE XSLT 2.0 processor, written in XSLT 2.0 (guide)
- Simple XPath tester is an XML, XPath, XQuery, XSLT online tester that supports different XPath versions and custom XML namespaces.
- FreeFormatter.com XPath Tester / Evaluator
- Web Toolkit Online XPath Tester
- and this validator made by Chris Nielsen.
The following online XPath checker can not only be used for testing and evaluation but also for saving and sharing, e.g. sharing samples for Stack Overflow questions:
- videlibri: Template / XPath 3.0 / XQuery 3.0 / CSS 3 Selector / JSONiq Online Tester
- XPath Evaluator supports XPath 3.0 and XQuery 3.0 via Saxon-HE 9.7 and XPath 1.0 via .NET XPath engine (GitHub Project).
- BeautifyConverter XPath Tester (requires free registration to share links)
Browser Addons
- xPath Analyzer Google Chrome Addons - Chrome Webstore
- XPath Checker Mozilla Firefox Addons - Firefox Addons
Online Tutorial
Online Training
A 70-minutes "Crash Course in XPath" module is available as part of the Pluralsight video-course "XSLT 2.0 and 1.0 Foundations"
"The Evolution of XPath: What’s New in XPath 3.0" -- A Pluralsight video-course (4.5h)
External links
- XPath 1.0 specification
- XPath 2.0 specification
- XPath 3.0 specification
- XPath 3.1 specification
- What's New in XPath 2.0
- XPath and XQuery Functions and Operators 3.1
Syntax Highlighting
To add syntax highlighting to a block of XPath code, tag it as lang-xpath