Developer

XPath Tester

Details

How to use XPath Tester

What the tool does, how to run it, and what to expect from the result.

What engine you are testing against

The document is parsed with the browser XML parser and the expression is run through the browser XPath implementation. That means XPath 1.0, which is what every browser ships and what a great deal of tooling still assumes. Version 2.0 and 3.1 features are simply not available: no for expressions, no let bindings, no sequence types, no regular expression functions beyond what 1.0 provides.

In practice XPath 1.0 covers most of what people actually write. Axes, predicates, position, contains, starts-with, substring, count, and the node tests all work. What you notice missing tends to be string manipulation, since 1.0 has no ends-with and no matches, and those absences are the usual reason an expression written against a 2.0 processor fails here.

Because this is the browser implementation, an expression that works here will work in a browser script using the same evaluation call. If your XPath is destined for a Java, Python, or .NET processor, most of it will carry over, but the version those libraries implement may be newer and more permissive than what you tested against.

  • XPath 1.0 only, because that is what browsers implement
  • Axes, predicates, and the common string and node functions all work
  • No ends-with, no matches, and no XPath 2.0 or 3.1 constructs

XML mode, and what that implies for HTML

The document is parsed strictly as XML. That has a direct consequence: the input has to be well-formed. Every tag must be closed, attributes must be quoted, ampersands must be escaped, and tag names are case sensitive. If any of that is wrong, you get a parse error message instead of a result, which is more useful than a silently truncated document.

It also means this is not an HTML tester. Real-world HTML relies on the browser error-correcting parser to close unclosed tags and tolerate unquoted attributes, and none of that leniency applies here. Pasting a page source scraped from the web will usually fail to parse. Convert it to well-formed XHTML first, or test HTML selectors with a different tool.

Namespaces are the other significant gap. The evaluation runs without a namespace resolver, so an expression cannot use a prefix to select elements in a namespace. Documents with a default namespace, which includes most real SVG, RSS, and SOAP, need the local-name workaround: match on the local name in a predicate rather than naming the element directly.

Reading the results

XPath 1.0 returns one of four kinds of value and the tester handles all of them. A node set is listed as individual results with a count above them. A string expression, such as one wrapped in string-of or concat, shows the string value. A number, from count or sum or a numeric operation, shows the number. A boolean, from a comparison or the boolean function, shows true or false.

Within a node set, each result is labeled by kind and serialized appropriately. An element is shown as its full markup including children, so you can see exactly what was selected. An attribute is shown as its name and value. A text node shows its trimmed content and a comment shows its comment syntax. That labeling matters, because selecting an attribute when you meant its element is one of the easiest XPath mistakes to make and the label catches it immediately.

The node count sits above the results, and an empty node set says so explicitly rather than showing nothing. Very large result sets are truncated after several thousand nodes, which is far past the point where reading them individually stops being useful.

  • Node sets, strings, numbers, and booleans are each displayed appropriately
  • Each node is labeled by kind and serialized: full markup for elements, name and value for attributes
  • An empty node set is stated explicitly, and very large sets are truncated
Tips

Getting a better result out of XPath Tester

Specific settings and thresholds, not general advice.

  • Start from the prefilled sample. Confirming the tool behaves as expected on known XML makes debugging your own document much faster.
  • If nothing matches, suspect a default namespace first. It is the single most common reason a correct-looking expression returns nothing.
  • Use a local-name predicate to work around namespaces rather than trying to declare a prefix, which is not supported here.
  • Build the expression one step at a time. Select the parent, confirm it matches, then add the predicate, then the child.
  • Read the node kind label on each result. Selecting an attribute when you meant an element is a very easy mistake to miss.
  • For HTML rather than XML, convert to well-formed XHTML first or use a CSS selector tool, since this parser will not tolerate loose markup.
Limits

What XPath Tester does not do

The honest boundary, so you do not lose time finding it yourself.

  • XPath 1.0 only, so 2.0 and 3.1 features including regular expression functions are unavailable.
  • The document is parsed strictly as XML, so real-world HTML generally fails to parse.
  • Namespaces are not supported; there is no resolver, so prefixed selection cannot work.
  • Very large node sets are truncated, and there is no file input, so documents must be pasted in.
At a glance

Who XPath Tester is for

A quick way to understand who this helps, what it solves, and where it connects next.

Best fit

Developers writing XPath selectors for XML.

Ideal for

Using the xpath tester without installing anything or signing up.

FAQ

Common questions

Short answers for the questions people usually have before trying a utility like this.

Is this XPath tester free?

Yes. It runs entirely in your browser with no signup and no account, and neither the document nor the expression is sent anywhere.

Which XPath version does it support?

XPath 1.0, which is what browsers implement natively. Version 2.0 and 3.1 constructs such as for expressions, sequence types, and regular expression functions are not available.

Can I test XPath against HTML?

Not reliably. The document is parsed strictly as XML, so it must be well-formed. Real HTML depends on the browser error-correcting parser and will usually fail to parse here.

Why does my document not parse?

Something is not well-formed. The usual culprits are an unclosed tag, an unquoted attribute, a bare ampersand, or a mismatch in tag name case. The error message from the parser is shown.

Does it support namespaces?

No. Evaluation runs without a namespace resolver, so prefixed selection does not work. Use a local-name predicate instead, matching the element name inside a predicate rather than naming it directly.

Why does my expression match nothing?

Most often a default namespace in the document, which silently prevents plain element names from matching. After that, check tag name case, since XML is case sensitive where HTML is not.

What result types can it show?

All four from XPath 1.0: node sets, strings, numbers, and booleans. Node sets are listed individually with a count, and each node is labeled by kind.

Can I select attributes?

Yes. An attribute result is displayed as its name and value, labeled as an attribute, which makes it obvious when you selected the attribute rather than the element you meant.

Is there a limit on results?

Very large node sets are truncated after several thousand nodes. That is well past the point where individually reading results is useful, so in practice it affects only pathological expressions.

Will my expression work in Python or Java?

Usually, since XPath 1.0 is a subset of what newer processors implement. Libraries supporting 2.0 or 3.1 are more permissive, so an expression that works there may not work here, but rarely the reverse.

Recommendations

You Might Also Like

Nearby tools from the catalog that fit the same job or workflow.

Cleanor app

Do it all on your device

Cleanor puts these tools in one app: compress and convert images, video, and audio, work with PDFs, and scan text right on your device. Plus free up storage and clear inbox clutter with Email Cleaner. Start with a free trial.

  • iPhone
  • Android
  • Macsoon
  • Windowssoon