📄 XML Document
📐 XPath Expression
ℹ Tips
- Use
//tagfor descendants anywhere;/root/tagfrom the document root. [@attr='value']filters by attribute;[position()=1]by index (1-based).count(...),name(...),string(...),boolean(...)change the result type.- Default namespaces need a bound prefix in the expression — bare names will not match.
📤 Result
🔎 Matches
- {{ idx + 1 }}. {{ match }}
ℹ️ About XPath Evaluator
What this tool does
The XPath Evaluator runs an
XPath 1.0
expression against an XML document and reports the result.
Paste your XML on the left, type the XPath expression below
it, and press Evaluate. The tool reports the
result type (node-set, number,
string, or boolean) and lists every
matching node along with its serialized form.
How it works (technical details)
- Pure client-side. Parsing and evaluation both run inside your browser. No XML, no expression, and no result is sent over the network.
-
Parser. Input is parsed with
DOMParserinapplication/xmlmode. The browser does not throw on malformed input; instead it returns a document containing a<parsererror>element, which this tool detects and surfaces verbatim. -
Evaluator.
document.evaluateruns withXPathResult.ANY_TYPE, so the expression's natural result type is preserved. Node-sets are iterated viaiterateNext()(orsnapshotItemas a fallback) and each match is rendered asouterHTMLfor elements,name="value"for attributes, and text content for everything else. -
Namespaces. Every
xmlnsandxmlns:prefixdeclaration in the parsed document is collected, and a resolver is passed todocument.evaluateso prefixed expressions resolve. Note: XPath 1.0 cannot match unprefixed names in a default namespace — bind a prefix in your XPath expression for elements in a default namespace.
XPath syntax — quick reference
//book— everybookelement anywhere in the document.//book[price<10]— everybookwhosepricechild is numerically less than 10.//*[@id='foo']— every element whoseidattribute equalsfoo.count(//book)— the number ofbookelements (returns a number, not a node-set).name(//book[1])— the qualified name of the firstbookelement (returns a string).//book/@isbn— everyisbnattribute on abookelement.boolean(//book)— true if at least onebookelement exists.
Use cases
- Configuration mining. Pull values out of
pom.xml, Spring beans, Ant scripts, or SOAP envelopes without writing throwaway code. - Vendor responses. Inspect SOAP/REST-XML responses while you debug an integration.
- RSS/Atom feeds. Filter a feed down to items that match a title pattern or category.
- Sitemaps. Pull every
<loc>URL out of a sitemap.xml for audit purposes. - Learning XPath. Iterate quickly on expressions against a sample document and see the result type change as you adjust the query.
Privacy note
This evaluator runs entirely in your browser using built-in
DOMParser and document.evaluate
APIs. No XML payload, no XPath expression, and no result is
sent to a server. There is no API endpoint for this tool
because Node has no first-party equivalent for these two
primitives.
Limits and gotchas
-
XPath 1.0 only.
document.evaluateimplements XPath 1.0. Features added in XPath 2.0/3.0/3.1 (string functions likematches(), sequence types, FLWOR, schema awareness) are not available here. -
Default-namespace gotcha. An XML
document with
xmlns="http://..."as a default namespace requires a prefixed XPath expression — e.g.//ns:bookafter bindingnsin the document. The resolver picks up declared prefixes automatically; bare element names will not match. -
HTML. This tool parses as XML, not
HTML. Tag soup or unclosed tags will produce a
parsererror. For HTML evaluation, query the live DOM or pre-process to XHTML first. - External entities. Browser DOMParser does not resolve external DTD references for security reasons, so entity expansion is limited to the five predefined XML entities.
References
- W3C — XPath 1.0 Recommendation — the canonical specification.
- MDN — Document.evaluate() — browser API used here.
- MDN — DOMParser — used to turn input text into a document object.
- MDN — XPathResult — result-type values and iteration methods.
- For full-document XML reflow / indentation, see the XML Formatter.