XPath Tester
Run XPath 1.0 queries against XML documents interactively. Supports node selection, attribute queries, text nodes, predicates, and XPath functions.
What is XPath?
XPath (XML Path Language) is a query language for selecting nodes from an XML document. Defined by the W3C, it treats an XML document as a tree of nodes and provides a concise syntax for navigating that tree - selecting elements, attributes, text content, and computed values using path expressions similar to filesystem paths.
This tool supports XPath 1.0, the version
universally implemented in browsers via the
document.evaluate() API. XPath 2.0 and 3.1 add richer type
systems and functions but require server-side or native parsers.
XPath Syntax Cheatsheet
| Expression | Selects |
|---|---|
| nodename | All children named "nodename" |
| /root | Root element "root" (absolute path) |
| //book | All <book> elements anywhere in the document |
| . | Current node |
| .. | Parent of the current node |
| @lang | Attribute named "lang" |
| book[1] | First <book> child (XPath is 1-indexed) |
| book[last()] | Last <book> child |
| book[@category] | All <book> elements that have a "category" attribute |
| book[@cat='fiction'] | All <book> elements where category equals "fiction" |
| title/text() | Text content of all <title> children |
| count(//book) | Number of <book> elements in the document |
| * | All child elements (wildcard) |
XPath Functions
Node Functions
count(), last(), position(), name(), local-name(), namespace-uri(), id()
String Functions
string(), concat(), contains(), starts-with(), substring(), string-length(), normalize-space()
Number Functions
number(), sum(), floor(), ceiling(), round()
Boolean Functions
boolean(), not(), true(), false(), lang()
Common Use Cases
XSLT Development
XPath is the expression language inside XSLT stylesheets. Test your match and select expressions here before embedding them in a stylesheet to avoid iterative XSLT compilation cycles.
Web Scraping
Libraries like lxml (Python) and nokogiri (Ruby) use XPath to extract data from HTML and XML. Test your selectors against a real document sample before running your scraper.
Selenium & Test Automation
Selenium WebDriver's By.xpath() locator strategy uses XPath against the live HTML DOM. Prototype your locators here against a saved HTML snippet to verify they match exactly the elements you intend.
XML Schema Exploration
When working with an unfamiliar XML schema, running queries like count(//*)) or //*/name() gives a quick structural inventory without reading the full document.