Skip to content
{}

XPath Tester

Test XPath 1.0 expressions against XML locally with support for axes, predicates, unions, and core XPath functions.

0 chars | 1 lines
0 chars | 1 lines
0 chars | 0 lines

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.

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.

InputOutputNote
//book[@lang='en']/titleFiltered elementsMatch by attribute value
//book[price > 10]/@idAttribute valuesNumeric predicate + attribute
/catalog/book[last()]/title/text()Text node1-based index with last()
//book[contains(title, 'XML')]Substring matchCore XPath string function
count(//book)Scalar numberCount matched nodes
//book[1]/author | //book[1]/titleCombined node-setUnion 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.xml

Python (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.

Validators workflow

Continue with the data, not the directory

Validate, format, repair, compare, query, and reshape payloads before they ship.

Browse inspect, validate & repair