XPath Tester
Evaluate XPath 1.0 expressions against XML using the browser DOM API. Runs 100% locally.
XPath 1.0 expression anatomy
XPath is a path language for selecting nodes in an XML document. The browser DOM API supports XPath 1.0, which covers the vast majority of practical query needs. Understanding the core syntax unlocks most use cases without needing a full spec.
//book[@genre='fiction']/title
// — anywhere in the document
book — element name
[@genre=…] — attribute predicate
/title — child element
Common XPath patterns
| Expression | Selects | Notes |
|---|---|---|
| //element | All elements anywhere in the document | Two slashes = descendant search |
| /root/child | Direct child only | Single slash = absolute path from root |
| //book[@genre] | Elements with a specific attribute present | Attribute existence predicate |
| //book[@id="3"] | Elements with a specific attribute value | Equality predicate |
| //item[position()=1] | First item in each parent | Position predicate (1-indexed) |
| //book/text() | Direct text content of elements | text() selects text nodes |
| //book/@title | Attribute value | @name selects attributes |
Static expression reference
Query all book titles with genre='fiction'
Input
<library>
<book genre="fiction">
<title>Dune</title>
</book>
<book genre="science">
<title>A Brief History</title>
</book>
</library>Output
XPath: //book[@genre='fiction']/title Result: Dune
What results can look like
- Node set: a list of matching elements or attributes — the most common result type.
- String: when you select text() or @attribute, results are string values.
- Number: XPath functions like count() and sum() return numeric results.
- Boolean: predicates like [contains(.,"x")] produce true/false internally.
Tip: Start with
//elementName to find all matching elements, then add predicates to filter. That iterative approach is faster than writing a complex path from scratch.XPath 1.0 limits and quirks
Your files stay on your computer. Dad promised.