XPath query

Evaluate XPath 1.0 expressions against XML or XHTML. Return text values, attributes, counts, booleans, or serialized matching nodes.

Matches

About this tool

XPath query evaluates an XPath 1.0 expression against an XML or XHTML document and returns the matching values. Use it to extract element text, attribute values, filtered node sets, counts, booleans, and function results.

Examples

Scope and limitations

This is an XPath 1.0 evaluator for well-formed XML/XHTML. It is not a forgiving HTML parser; tidy malformed HTML before querying it. Namespace-heavy documents may need namespace-aware expressions that the current simple page UI does not configure separately.

Privacy

The browser version runs locally in WebAssembly, so your XML document and XPath expression stay on your device.

FAQ

Can I query a real-world HTML page with this?

Only if it's well-formed. The evaluator parses strict XML/XHTML — it is not a forgiving HTML parser, so typical scraped HTML (unclosed <li>, bare <br>, unquoted attributes) fails to parse. Run the page through an HTML tidier, or use the html-to-markdown tool if you just want the content.

What's the difference between the "value" and "xml" output modes?

value (the default) prints each matched node's string value — the concatenated text content, which for an attribute is just its value. xml serializes the whole matching node as outer XML, including its tag and attributes, with text properly re-escaped; an empty element comes out self-closing.

Which XPath version and functions are supported?

XPath 1.0 — node-set paths with predicates, plus the 1.0 function library (count(), name(), string(), comparisons returning booleans, and so on). Scalar expressions return a single number, string, or boolean; XPath 2.0+ features such as matches() or sequences aren't available.

Why does my query return nothing on a namespaced document?

In XPath 1.0, an unprefixed name only matches elements in no namespace — so //svg won't match <svg xmlns="http://www.w3.org/2000/svg">. The page UI doesn't currently let you register namespace prefixes; a common workaround is matching by local name, e.g. //*[local-name()='svg'].

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool xpath-query "//book/title or count(//item)" 'xml=<catalog><book id="b1"><title>Rust</title></book></catalog>'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/xpath-query/?expression=%2F%2Fbook%2Ftitle%20or%20count%28%2F%2Fitem%29&xml=%3Ccatalog%3E%3Cbook%20id%3D%22b1%22%3E%3Ctitle%3ERust%3C%2Ftitle%3E%3C%2Fbook%3E%3C%2Fcatalog%3E&output=value

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.