Skip to content

XPath Tester

Evaluate XPath 1.0 against detached XML and inspect node, string, number, or Boolean results without inserting matched markup.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Paste a well-formed XML fixture, including explicit namespace prefix declarations where needed.
  2. 2.Enter an XPath 1.0 expression and evaluate it in the browser's detached XML document.
  3. 3.Inspect the result type and exact serialized matches, then test the expression in the destination runtime.

About XPath Tester

XPath Tester evaluates an XPath 1.0 expression against an XML document using the browser's native DOM interfaces. Paste well-formed XML, enter an expression, run it, and inspect a node-set, string, number, or Boolean result. Everything happens in a detached in-memory document in the current tab; XML and results are not uploaded.

The XML source is parsed with DOMParser using application/xml. A parsererror result is treated as failure, so mismatched tags and other malformed XML do not proceed to XPath evaluation. The parsed document is separate from the page. Matched elements are serialized for visible output, attributes use an explicit at-sign representation, and text and comment nodes receive visible labels. None of that output is inserted into the live page as markup.

Evaluation uses Document.evaluate with ANY_TYPE so the browser reports the expression's natural XPath result. Node-set results are collected and displayed one per numbered line. Functions such as string, count, and boolean produce their scalar result type rather than being forced into a node list. Empty strings and zero-node sets remain valid results and are distinguished from parser or expression errors.

Namespace prefixes in the XPath expression are resolved from declarations visible on the XML document element. The reserved xml prefix maps to its standard namespace. For example, if the root declares xmlns:b="urn:books", an expression using b:book can select those namespaced elements. Unprefixed names select elements in no namespace under XPath 1.0 rules; a default XML namespace does not make an unprefixed XPath name match it. Give that namespace an explicit prefix in the XML and expression when necessary.

This tool follows the browser's XPath 1.0 implementation, not XPath 2.0, 3.1, XQuery, XSLT, CSS selectors, JSONPath, or an XML Schema validator. Functions, sequences, regular-expression features, typed values, maps, arrays, and operators introduced by later XPath editions are not available. Browser error wording can differ, so the interface adds a stable XPath error prefix while preserving the underlying message for diagnosis.

XPath can select elements, attributes, text, comments, and processing-related nodes, but a match does not prove that the XML satisfies business rules. DOMParser does not validate against an XSD or DTD in this workflow. The tool does not fetch a remote document, follow links, execute scripts, insert selected markup, mutate the source, or save history. Treat sensitive XML with the same local-screen and clipboard precautions as any developer tool.

Work is limited to 500,000 XML characters, 2,000 expression characters, 500 matched nodes, and 1,000,000 displayed result characters. If a node-set exceeds the match limit, the tool fails and asks for a narrower expression instead of presenting an incomplete prefix as the whole result. Expressions beginning with a broad descendant search can be expensive on large documents; prefer a specific absolute path or narrower context when practical.

Eight external fixtures cover element node-sets, string, count, Boolean, attribute, comment, namespace, and empty selection behavior. Pure tests lock visible serialization for four node kinds, while real-browser acceptance tests exercise DOMParser and Document.evaluate together. For reliable use, keep a representative XML fixture, declare prefixes explicitly, test positive and zero-match cases, and verify the same expression in the target runtime because server libraries may implement a different XPath edition or namespace policy.

Methodology & sources

Parses application/xml into a detached DOM, rejects parsererror documents, resolves XPath prefixes from the document root plus the reserved xml namespace, evaluates with the browser's natural ANY_TYPE result, serializes supported node kinds as visible text, and fails rather than truncating over-limit matches or output.

Frequently asked questions

Why does an unprefixed XPath miss elements in a default namespace?
Under XPath 1.0 an unprefixed name selects no-namespace elements. Bind the namespace to a prefix and use that prefix in the expression.
Does this support XPath 2.0 or 3.1?
No. It uses the browser DOM XPath interface, which implements XPath 1.0 behavior. Later-edition sequences, maps, arrays, and functions are outside scope.
Can matched XML execute in this page?
No. The XML stays in a detached document and serialized matches are rendered as text. They are never inserted into the live DOM as markup.

Developer Tools guides

View all