How do I test XPath expressions against XML online?
Paste your XML into the editor, type an XPath expression like //book[@category='programming']/title, and click Evaluate to see matching nodes instantly. The tool supports element selection, attribute filtering, axes (ancestor, descendant, sibling), and XPath functions (count, contains, starts-with). Click any example query button to try common patterns. Everything runs in your browser using the native XPath 1.0 engine — no data is sent to a server.
XPath: //book/title
XML:
<library>
<book>
<title>Clean Code</title>
</book>
<book>
<title>Refactoring</title>
</book>
</library>Found 2 nodes: 1. <title>Clean Code</title> 2. <title>Refactoring</title> Type: Element nodes
XPath Tester
Test XPath expressions against XML data with real-time evaluation. Extract elements, filter by attributes, and navigate XML document structures.
XPath Reference
| Expression | Description |
|---|---|
/ | Root element |
//element | All matching elements anywhere |
./child | Direct child of context |
@attr | Attribute value |
[1] | First element (1-indexed) |
[last()] | Last element |
[position()<3] | First two elements |
[@attr='val'] | Filter by attribute |
[contains(., 'text')] | Contains text |
[starts-with(@id, 'x')] | Starts with |
text() | Text content |
node() | Any node |
count(//el) | Count elements |
sum(//el) | Sum of numeric values |
string-length(//el) | String length |
ancestor::el | Ancestor axis |
descendant::el | Descendant axis |
following-sibling::el | Following siblings |
parent::el | Parent axis |
el1 | el2 | Union of two node sets |
About XPath
XPath (XML Path Language) is a query language for selecting nodes from XML documents. It uses path expressions to navigate through elements, attributes, and text in an XML tree structure.
- Nodes — elements, attributes, text, comments, and the document itself
- Axes — define the direction of navigation (child, parent, ancestor, descendant, sibling)
- Predicates — filter nodes with conditions inside square brackets
- Functions — built-in string, number, and node functions (contains, count, sum, etc.)
XPath is used in XSLT, XQuery, web scraping (Selenium, Puppeteer), configuration parsing, and XML data extraction. This tool uses your browser's built-in XPath 1.0 engine — no data is sent over the network.
Tips & Best Practices
Use // for deep search, / for direct children only
`//title` finds all title elements anywhere in the document. `/html/head/title` only matches the exact path. Start with // to explore, then tighten to / for precision. // is slower on large documents because it searches the entire tree.
XPath 1.0 has no regex support — use contains() and starts-with()
Browser-native XPath is version 1.0, which lacks regex. For pattern matching, chain string functions: `//a[contains(@href, 'example') and starts-with(@class, 'nav')]`. XPath 2.0+ has matches() with regex, but browsers don't support it natively.
Select elements by text content with text() and contains()
`//button[text()='Submit']` matches exact text. `//button[contains(text(), 'Sign')]` matches partial text like 'Sign In', 'Sign Up', 'Sign Out'. Use normalize-space() to handle whitespace: `//p[normalize-space()='Hello World']`.
User-supplied XPath can enable injection in server-side queries
If you build XPath queries from user input without sanitization, attackers can inject expressions to extract data. `//user[name='admin' or '1'='1']` bypasses authentication. Always parameterize or sanitize XPath inputs on the server side.
Frequently Asked Questions
What is XPath and how does it work?
What is the difference between XPath and JSONPath?
How do I select elements by attribute value in XPath?
Is it safe to paste XML data into this tool?
Related Inspect Tools
Diff Checker
Compare two texts and see differences highlighted
Cron Expression Parser
Parse cron schedules into plain English with next run times
Word & Character Counter
Count words, characters, sentences, and estimate reading time
Chmod Calculator
Calculate Unix file permissions with an interactive permission matrix