XPath Tester — Test XPath Expressions Online
Paste XML, enter an XPath expression, and see all matching nodes instantly. Free, browser-based, no signup.
XPath Quick Reference
Basic Expressions
| Expression | Selects |
|---|---|
| nodename | All child nodes named "nodename" |
| /root | Root element named "root" |
| //book | All <book> elements anywhere in document |
| . | Current node |
| .. | Parent of current node |
| @lang | Attribute named "lang" |
| * | All element children |
| @* | All attributes |
| text() | Text node children |
Predicates (Filters)
| Expression | Selects |
|---|---|
| //book[1] | First <book> element |
| //book[last()] | Last <book> element |
| //book[@lang] | <book> with a "lang" attribute |
| //book[@lang='en'] | <book> where lang equals "en" |
| //book[price>10] | <book> where price child is > 10 |
| //book[contains(@id,'1')] | <book> whose id contains "1" |
Useful Functions
| Function | Returns |
|---|---|
| count(//book) | Number of <book> elements |
| string(//title) | Text content of first <title> |
| contains(text(),'foo') | True if text contains "foo" |
| starts-with(@id,'a') | True if id attribute starts with "a" |
| normalize-space(//name) | Text with leading/trailing spaces trimmed |
| sum(//price) | Sum of all <price> values |
Frequently Asked Questions
What is XPath?
XPath (XML Path Language) is a query language for selecting nodes from an XML document. It uses path-like expressions to navigate the element and attribute hierarchy. XPath is used in XSLT, XML Schema validation, web scraping, and testing frameworks.
Which XPath version does this support?
This tool uses the browser's built-in XPath 1.0 implementation. XPath 1.0 covers the vast majority of real-world use cases including axes, predicates, and all standard functions.
What is the difference between / and //?
/ selects from the root, requiring you to specify the full path. // selects matching nodes anywhere in the document, regardless of their position in the hierarchy.
Is my data safe?
Yes. All processing happens in your browser. Your XML and XPath expressions are never sent to any server.