XPath Tester
XPath Tester
Run XPath 1.0 expressions against an XML document via the browser's native document.evaluate. Returns matched element nodes (serialised), attribute / text nodes, and string / number / boolean expression results.
You do not have to know the document to start. Paste it and every element path in it is listed below the panes with a node count, together with the attributes that occur at each — click one and it becomes the expression. The italic chips after them are starter shapes (count them, second one, contains text) built from this document's own deepest repeated element, so they run rather than just illustrate.
Namespaces are handled. The row above the paths lists every prefix the document declares and binds each one for evaluation, so //dc:creator works. A default namespace — xmlns="http://www.w3.org/2005/Atom" — cannot be named in XPath 1.0 at all, so it is given a prefix (ns:) and the path chips are written with it. If you would rather not think about any of that, tick ignore namespaces.
XPath 1.0 only
The browser ships XPath 1.0. That covers //tag, /root/child[2], @attr, text(), count(), contains(), starts-with(), and predicates with position / attribute filters. XPath 2.0 / 3.1 features (regex, sequences, let) are not supported.
Why //entry finds nothing in an Atom feed
Because in XPath 1.0 a bare name test means “that name, in no namespace”, and every element in an Atom feed is in http://www.w3.org/2005/Atom. There is no such thing as a default namespace in an XPath expression — the prefix has to be spelled out even when the document does not spell it. That single rule is behind most “my XPath is correct and returns nothing” evenings.
Two ways through it, both here:
- Name it. The tool reads the declarations out of your document and binds them, generating
ns:for a default namespace.//ns:entry/ns:titleworks, and the path chips are already written that way. - Ignore it. Ticking ignore namespaces rewrites each unprefixed element name as
*[local-name()='name'], which matches whatever namespace it is in. The rewritten expression is shown in the status line, so you can copy the real thing into your code. String literals, function names, axis names and theand/or/div/modoperators are left alone.
Attributes are the exception worth knowing: an unprefixed attribute is genuinely in no namespace, so @href keeps working in a namespaced document without either treatment.
Privacy
100% client-side. No upload. See the privacy policy.