CruxDevCruxDev Tools Prompts
dev Utility • Zero-Server Privacy • 100% Client-Side

XPath Tester & Evaluator

Run XPath expressions against any XML document in your browser - snapshot matches, serialized nodes, and precise error reporting for bad XML or bad expressions.

Overview

Run XPath expressions against any XML document right in the browser. Paste your XML, type an expression such as //book[price>30]/title, and see every matching node with a live count - element nodes serialized in full, text and attribute values shown as strings, and real error messages when the XML or the expression is wrong.

How It Works

Paste the XML document into the left panel and the XPath into the expression field. Evaluation runs on every change. Matches are listed in document order with the total count; click any match to copy it. If the XML is malformed, the parser's own error text is surfaced; if the expression is invalid, the engine's XPath error is shown rather than an empty result.

Step-by-Step Usage Guide

  1. Paste a well-formed XML document, or start from the catalog sample to learn the syntax.
  2. Type an absolute path like /catalog/book/title or the more forgiving //title.
  3. Add predicates to filter, such as //book[price>30] or //book[@id='2'].
  4. Click a result to copy it, and adjust the expression until the count is what you expect.

Technical Specifications & Standards

The tool uses the platform's native XML stack: DOMParser to build the document and Document.evaluate with an ORDERED_NODE_SNAPSHOT_TYPE result, which is the browser's genuine XPath 1.0 engine - the same one Selenium and browser devtools expose. That choice matters for fidelity: axes, predicates, functions like position() and contains(), and attribute steps all behave exactly as they will in your production parser, because it is the production parser. Element matches are serialized with XMLSerializer so you see the node with its attributes and children; attribute and text matches print their value. Two boundaries are worth knowing: the engine is XPath 1.0, so later additions such as XPath 2.0 conditionals and regular-expression functions are unavailable, and there is no namespace resolver, so documents using prefixed namespaces need expressions that match their local names or a namespace-free test document.

Targeted Use Cases

  • Building or debugging an XPath before embedding it in Selenium, Playwright, or an XSLT transform.
  • Extracting specific records from a large SOAP response or sitemap without loading it into an editor.
  • Learning XPath: instant feedback on axes, predicates, and functions against a small sample.
  • Verifying that a scraping selector matches exactly the nodes you intend, in order.

Notes & Gotchas

  • Start broad (//title) and add predicates step by step; a count that jumps from many to one tells you which predicate did the work.
  • Prefer specific paths over double-slash searches in production - // is slow and can match deeper than you expect.
  • Quote attribute values inside predicates with quotes that do not collide with your surrounding syntax.
  • Remember the engine is XPath 1.0: no regex matches or for-loops; use position(), last(), contains(), and arithmetic instead.

Frequently Asked Questions

Which XPath version does this use?

XPath 1.0, which is what browsers implement through Document.evaluate. Core paths, axes, predicates, and the 1.0 function library work; 2.0-and-later features such as regular expression functions do not.

Does my XML leave the browser?

No. Parsing and evaluation run entirely in your page with the browser's own XML engine, so confidential documents never leave your machine.

Why do I get a parser error instead of zero matches?

The XML itself is not well-formed - a missing close tag, an unescaped ampersand, or multiple root elements. The tool shows the parser's error message; fix the document first, then the expression.

How do namespaces work here?

No namespace resolver is configured, so prefixed names cannot be resolved to URIs. Either test against a namespace-free document or match local names as they appear, keeping that limitation in mind when porting the expression.