XPath Tester
Free online XPath tester tool, query XML documents
About XPath Tester
Evaluates an XPath expression against an XML document entirely in the browser using DOMParser and Document.evaluate. It parses your XML (rejecting malformed input with a parse error), runs the expression, and renders the typed result — strings, numbers, booleans, or serialized node sets — with a match count and per-result type label. Four quick-fill example expressions and a starter XML document ship with the tool.
How to Use
1. Paste your XML into the XML Input card (a three-`<child>` sample document is preloaded). 2. Type an XPath expression into the XPath Expression field, or click one of the four example chips (`//element`, `//element/@attr`, `count(//element)`, `/root/child/text()`) to fill it. 3. Click Execute (or press Enter in the expression field) to evaluate. 4. Read the Results card: it shows the match count ("N matches") and each result with a type label — `Result (string|number|boolean)` for scalar expressions, or `Node 1`, `Node 2`, ... for node-set expressions serialized back to XML. 5. Any parse error (invalid XML) or evaluation error (invalid XPath) appears in a red banner above the results.
Result Types and Evaluation Semantics
The tool calls `doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null)` and dispatches on `resultType`: - STRING_TYPE → one result labeled `Result (string)`. - NUMBER_TYPE → one result labeled `Result (number)`, value coerced to string (this is what `count(//child)` returns). - BOOLEAN_TYPE → one result labeled `Result (boolean)` (e.g. `count(//child) > 0`). - ORDERED_NODE_SNAPSHOT_TYPE / UNORDERED_NODE_SNAPSHOT_TYPE → multiple results, each serialized via XMLSerializer and labeled `Node 1`, `Node 2`, etc. - FIRST_ORDERED_NODE_TYPE → a single node result (or empty string if no node matched). XML is parsed in `application/xml` mode, so HTML-style void tags, unquoted attributes, or entity issues will surface as a parsererror element and be shown as `Invalid XML: ...`. The default `application/xml` mode also means HTML documents are not parsed correctly — feed well-formed XML only.
▶Why do I get an "Invalid XML" error with HTML input?
▶What is the difference between count(//element) and //element?
▶Can I evaluate XPath against an HTML page I have open in another tab?
▶Is my data sent to a server?
If this tool has been helpful to you, consider buying me a coffee.
Buy me a coffee