XPath query tester
Formatters
Loading
Loading tool
The tool is loaded only when you open it.
All processing for this tool happens in your browser. Your input is not sent to a server.
About this tool
Select nodes and attributes from XML or evaluate count(), sum(), string() and boolean() locally. The tester accepts a common XPath 1.0 syntax and function subset and uses FontoXPath with XPath 3.1 evaluation semantics. It does not claim full XPath 1.0 or 3.1 conformance. Results show typed scalars or normalized nodes with diagnostic locations; XML and result text are never rendered as HTML.
Common uses
- Check an XML attribute predicate before using it in a configuration or import workflow.
- Understand why a query against a default XML namespace needs an explicit prefix.
- Inspect a bounded node selection and save complete, typed results as JSON.
How to use it
- 1.Paste XML 1.0 or choose a strict UTF-8 XML file; select a sample if needed.
- 2.Enter an XPath expression and, for namespaced elements, a JSON prefix-to-URI map such as {"b":"urn:books"}. Run the query.
- 3.Review the result type and nodes, use pagination, then download the complete JSON if it is suitable to share.
Executable query examples
Attribute predicate
XML: <books><book id="a" price="10">Alpha</book><book id="b" price="20">Beta</book></books>
XPath: //book[@price > 10]/@id
Namespaces: {}attribute id = b
The price predicate selects the second book, then its id attribute.
Default namespace
XML: <books xmlns="urn:books"><book id="a">日本語 · 中文 · 𠮷</book></books>
XPath: //b:book/@id
Namespaces: {"b":"urn:books"}attribute id = a
An explicit b prefix addresses the default XML namespace. Without the prefix, //book has zero matches.
Numeric scalar
XML: <books><book price="10"/><book price="20"/></books>
XPath: sum(//book/@price)
Namespaces: {}number = 30
The scalar is displayed as a number result and stored as the string "30" in JSON.
Unicode scalar
XML: <r>𠮷A</r>
XPath: substring(/r, 1, 1)
Namespaces: {}string = 𠮷
The supplementary character is preserved as one Unicode character rather than split into a lone surrogate.
Limits and notes
- XML is capped at 128 KiB UTF-8 and 131,072 UTF-16 units, depth 64, 5,000 DOM items including attributes, and 32 namespace declarations. Only XML 1.0 is accepted; an optional initial encoding declaration may specify UTF-8 only. DTD and entity declaration markers are rejected even inside comments or CDATA. Names use the parser BMP character range: supplementary characters in element, attribute or namespace-prefix names are unsupported, even when valid XML names; supplementary text and attribute values are supported.
- Expressions are capped at 512 UTF-16 units. Supported paths, predicates, axes except namespace, union and XPath 1.0 core functions except id() use XPath 3.1 semantics. Variables, custom/resource functions and later syntax are rejected. string(//book) fails for multiple nodes; use string((//book)[1]). Comparisons, number conversion and rounding can differ from XPath 1.0. JavaScript number precision applies.
- Namespace maps have at most 32 entries and 8,192 UTF-16 units; prefixes are ASCII and up to 64 characters, URI strings up to 512 units. xml and xmlns are reserved; xml is predefined. Repeated JSON keys keep their last value. Unprefixed names select only nodes with no namespace; URIs are identifiers, never fetched.
- The worker is terminated after 8 seconds. More than 1,000 matched nodes or a complete JSON report above 2,000,000 UTF-8 bytes rejects the whole result; serialization can reach a conservative budget sooner. Previews show up to 1,024 UTF-16 units and 100 nodes per page. Input edits, language changes and cancellation invalidate results and downloads.
- Export contains the expression, resolved namespace map and complete selected values or normalized serializations and may expose sensitive data. It omits original XML bytes, merges adjacent text/CDATA and omits the XML declaration. Diagnostic paths index all DOM siblings and are not executable XPath. Numbers are exported as strings preserving NaN, Infinity and negative zero.
Frequently asked questions
Why does //book return no nodes?
Unprefixed XPath element names match elements with no namespace. For <books xmlns="urn:books">, map b to urn:books and query //b:book. The chosen prefix need not match the original XML prefix.
Which XPath version is used?
A parse-only XPath 1.0 syntax gate and a restricted core function allowlist feed the FontoXPath 3.1 evaluator. This is an explicit mixed profile, not full XPath 1.0 compatibility or full XPath 3.1 support. Single-node conversions and comparison behavior should be checked against your destination engine.
Does a namespace URI, DTD or expression fetch data?
Namespace URIs are only identifiers. The local worker has no resource resolver; DTD and entity declarations, resource functions and extension functions are rejected. There is no input persistence or backend query execution.
Is a clipped preview also clipped in JSON?
No. Preview clipping is visible; a successful JSON export includes all accepted rows and values. If the result or export limit is exceeded, no partial result is returned.