XPath Tester
Run an XPath expression against your own XML or HTML and see every matching node with its value and position. Uses the browser native XPath engine, so results match what a real parser returns.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
Testing an expression against the real document
XPath is easy to write and hard to write correctly. An expression that looks right returns nothing because the document has a default namespace, because a predicate index is one based rather than zero based, or because the double slash shortcut searched from the root rather than from the current node. Reasoning about it on paper rarely finds the mistake; running it against the actual document does, immediately.
The namespace trap
The most common reason a correct looking expression returns zero nodes is a default namespace on the root element. An XML document declaring xmlns on its root puts every element into that namespace, and an unprefixed name in XPath 1.0 matches only elements with no namespace. The fix is either to bind a prefix or to match by local name. This tester reports when the document has a default namespace and offers to match on local name so you can confirm that is the cause before rewriting anything.
XML and HTML behave differently
Parsed as HTML, tag names are normalised to lower case and the parser repairs unclosed elements, so an expression matching an upper case tag name will fail. Parsed as XML, the document must be well formed and a single unescaped ampersand causes a parse error with a line number. Choosing the mode that matches how the document is consumed in production is part of getting the expression right.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
Which XPath version is supported?
XPath 1.0, which is what browsers implement and what the DOM evaluate method exposes. That covers axes, predicates, and the core function library. XPath 2.0 and 3.1 additions such as regular expression functions are not available.
Why does my expression return nothing on a namespaced document?
Because an unprefixed element name in XPath 1.0 only matches elements with no namespace. Use local-name() or enable the local name option, which rewrites simple paths to match regardless of namespace.
Should I choose XML or HTML mode?
Match how the document is consumed. HTML mode lower cases tag names and repairs broken markup; XML mode requires well formed input and preserves case. An HTML page scraped with an XML parser will usually fail to parse at all.
Can I select attributes and text nodes?
Yes. An expression ending in @attr returns attribute nodes and one ending in text() returns text nodes; both are listed with their values. Expressions returning a number, string or boolean are shown as scalar results.
Is my document uploaded anywhere?
No. Parsing and evaluation use the XPath engine built into your browser, so the document never leaves the page.
Privacy & Security
Everything runs in your browser; nothing is uploaded.
How to Use
Paste XML or HTML, enter an XPath expression, and press Evaluate to list the matching nodes.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.