XPath Tester

Test XPath expressions against XML or HTML and inspect every matching node, value and path.

Input type
XML / HTML input
Results
Enter XML or HTML and an XPath expression to test.

Your XML, HTML and XPath are tested in your browser. Nothing is uploaded to BroBroGo.

FAQ

Can I test XPath on HTML as well as XML?

Yes. XML mode keeps XML namespace rules. HTML mode is forgiving and lets simple paths like //a match normal tags.

How do XML namespaces work?

Namespace prefixes declared in your XML can be used in the XPath, such as //x:item. For default namespaces, //item also follows the document declaration.

Why can a query time out?

Very large documents or broad expressions can be expensive to evaluate. The tool stops a run after 2 seconds so the page stays responsive; narrow the path or try a smaller sample.

Testing XPath Expressions Against XML and HTML

The XPath Tester is a browser-based utility designed to evaluate XPath expressions against your provided XML or HTML content. When you input your document and an expression, the tool identifies and displays every matching node. For each match, you can inspect its specific type, name, path, and a preview of its value. If you need to extract specific data, you can copy the value of any individual result directly to your clipboard.

The tool operates entirely within your web browser. Your XML, HTML, and XPath are tested in your browser, and nothing is uploaded to BroBroGo. This ensures your data remains local to your machine during testing.

Input Specifications and Constraints

To use the tool, you must provide two primary inputs and select the appropriate evaluation mode:

  • XML / HTML input: This is the text content of your document. The input document has a maximum length of 500,000 characters.
  • XPath expression: The query you want to test against your document. The expression has a maximum length of 4,000 characters.
  • Input type: A toggle that lets you choose between "XML mode" or "HTML mode".

The interface also displays real-time statistics about your input and output, including "Chars" (the total character count of your input document) and "Results" (the number of matching results displayed).

Understanding XML Mode and HTML Mode

The tool processes your queries differently depending on the selected "Input type":

  • XML mode: When this mode is active, strict XML namespace rules are followed. This is essential for well-formed XML documents that rely on precise namespace declarations.
  • HTML mode: This mode is highly forgiving. It allows you to use simple paths, such as //a, to match normal tags without requiring strict XML compliance.

It is important to note that this tool evaluates static input and does not represent the real-time structure, rendered DOM, or network requests of live online pages.

Handling Namespaces in XML

When working in "XML mode", namespaces are handled according to the declarations present in your document:

  • Declared Prefixes: Namespace prefixes declared in your XML can be used directly within your XPath expression, such as //x:item.
  • Default Namespaces: For default namespaces defined in the XML, a query like //item will follow the document's default namespace declaration to locate the correct nodes.

Error Messages and Evaluation Limits

To maintain a responsive interface, the tool enforces several safety limits and validation checks. If an input violates these rules, specific error messages are displayed:

  • Timeouts: The tool stops evaluating an XPath expression after 2 seconds to keep the page responsive. If an expression takes too long to run, the interface displays: "This XPath took too long to run. Narrow the expression or use a smaller sample.".
  • Document Size: If the input document exceeds the 500,000-character limit, the tool displays: "This document is too large to test here. Try a smaller sample.".
  • Expression Size: If the XPath expression exceeds 4,000 characters, the tool displays: "This XPath expression is too long to test here.".
  • Parsing Failures: If the input document is malformed and cannot be read, the tool displays: "Could not parse this document.".
  • Invalid Syntax: If the XPath expression contains syntax errors, the tool displays: "This XPath expression is not valid.".
  • Evaluation Failures: If the expression is syntactically valid but cannot be executed against the document, the tool displays: "Could not evaluate this XPath.".
  • No Matches: If the query executes successfully but finds no matching nodes, the tool displays: "No results.".
  • Result Truncation: To prevent browser slowdowns, the tool displays a maximum of 200 matching nodes. When more than 200 results are found, it displays the message "Showing the first {max}." and limits the output to the first 200 results.

Frequently Asked Questions

Can I test XPath on HTML as well as XML?

Yes. XML mode keeps XML namespace rules. HTML mode is forgiving and lets simple paths like //a match normal tags.

How do XML namespaces work?

Namespace prefixes declared in your XML can be used in the XPath, such as //x:item. For default namespaces, //item also follows the document declaration.

Why can a query time out?

Very large documents or broad expressions can be expensive to evaluate. The tool stops a run after 2 seconds so the page stays responsive; narrow the path or try a smaller sample.