What is XPath?
XPath is a query language for selecting nodes and computing values from XML documents using path expressions to navigate through the hierarchical structure of XML data.
Quick Facts
| Full Name | XML Path Language |
|---|---|
| Created | 2026-02-01 |
| Specification | Official Specification |
How XPath Works
XPath provides a powerful syntax for addressing and extracting data from XML documents. It uses path expressions similar to file system paths to navigate through XML's tree structure, selecting elements, attributes, and text content. XPath supports various node selection methods including absolute paths from the root, relative paths from the current context, and predicates for filtering. The language includes built-in functions for string manipulation, numeric calculations, and boolean operations, making it essential for XML processing, XSLT transformations, and web scraping applications.
Key Characteristics
- Uses path expressions to navigate XML tree structure
- Supports absolute (/) and relative (//) path selection
- Predicates in brackets [] filter node selections
- Axis specifiers define navigation direction (child, parent, sibling)
- Built-in functions for strings, numbers, and node sets
- Wildcards (*) match any element at current level
Common Use Cases
- Extracting data from XML configuration files
- Web scraping and HTML parsing
- XSLT stylesheet transformations
- XML document validation and testing
- Automated UI testing with Selenium
Example
//bookstore/book[@category='fiction']/title/text()