XPath Tester
Test XPath 1.0 expressions against XML locally with support for axes, predicates, unions, and core XPath functions.
Conversion payloads stay in this browser tab and are never placed in page URLs - see how local processing works. Privacy-safe analytics record only the tool, outcome, and a coarse input-size bucket. Press Cmd/Ctrl + Enter to convert.
How to Test an XPath Expression
Paste an XML document into the first panel and write an XPath 1.0 expression in the second panel. Every matched node is listed with its 1-based match number, node kind (element, attribute, text, or comment), exact absolute XPath, and serialized markup. Need to inspect a large file and grab a starting path first? Open it in the XML Viewer and click Copy XPath on any element.
XPath 1.0 Quick Reference
Common patterns you can test directly in this workbench.
| Input | Output | Note |
|---|---|---|
| //book[@lang='en']/title | Filtered elements | Match by attribute value |
| //book[price > 10]/@id | Attribute values | Numeric predicate + attribute |
| /catalog/book[last()]/title/text() | Text node | 1-based index with last() |
| //book[contains(title, 'XML')] | Substring match | Core XPath string function |
| count(//book) | Scalar number | Count matched nodes |
| //book[1]/author | //book[1]/title | Combined node-set | Union operator in doc order |
XPath in Code
Once an expression selects the exact nodes you need, run it in your application or CLI:
xmllint (CLI)
xmllint --xpath "//book[@lang='en']/title" catalog.xmlPython (lxml)
from lxml import etree
tree = etree.parse("catalog.xml")
print(tree.xpath("//book[@lang='en']/title/text()"))JavaScript (Browser)
const doc = new DOMParser().parseFromString(xml, "application/xml");
const snap = doc.evaluate("//book[@lang='en']/title", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);Frequently Asked Questions
Which version of XPath is supported?
This tool implements XPath 1.0: absolute and relative location paths (/a/b, //item), wildcards (* and prefix:*), attribute and node tests (@id, text(), comment(), node()), all standard axes (child, descendant, parent, ancestor, following-sibling, preceding-sibling), chained predicates, unions (|), arithmetic/boolean operators, and core functions such as count(), sum(), contains(), starts-with(), normalize-space(), position(), and last().
How are XML namespaces handled in XPath queries?
Element and attribute names match the exact qualified names present in your XML document, such as //media:content or //media:*. That lets you query SOAP envelopes, RSS/Atom feeds, and SVG files immediately without manually configuring a separate namespace map.
Can I evaluate scalar expressions like count() or sum()?
Yes. Expressions that return a number, string, or boolean—such as count(//book), sum(//price), or contains(//book[1]/title, 'XML')—display the scalar result directly along with its XPath return type.
What protects against malformed XML or entity expansion attacks?
The XML document is validated for well-formedness, single-root compliance, and nesting depth before evaluation, and nested DOCTYPE entity definitions ("billion laughs") are refused. Evaluation also enforces a step budget so runaway expressions fail cleanly instead of freezing your tab.
Is my XML sent to a server?
No. Both the XML parser and the XPath 1.0 evaluator run entirely in JavaScript inside your browser tab.
Continue with the data, not the directory
Validate, format, repair, compare, query, and reshape payloads before they ship.
XML Viewer
Open an XML file as a collapsible tree, search elements, attributes and text, and copy the XPath of any element.
XML Validator
Check XML well-formedness and get the exact line and column of the first error.
XML Compare & Diff
Compare two XML documents side by side by structure and XPath, ignoring formatting noise, comments, or attribute order.
JSONPath Tester
Test JSONPath expressions against your own JSON and see what they select.