CoderTools

XPath Tester

Test and evaluate XPath expressions online with instant results

Match Results

No matches found
Enter XML/HTML and XPath expression to see results

Result Details

Enter an XPath expression and XML/HTML to see detailed match information

Quick Templates

XPath Testing Tool Documentation

Understanding XPath

XPath (XML Path Language) is a query language for selecting nodes from XML and HTML documents. It uses path expressions to navigate through elements and attributes in a document tree structure, similar to how file system paths work.

Absolute Path

/html/body/div

Starts from the root node. Use when you know the exact document structure.

Relative Path

//div[@class='content']

Selects nodes anywhere in the document. More flexible and commonly used.

XPath Syntax Reference

Selection Expressions

Expression Description
/ Selects from the root node (absolute path)
// Selects nodes anywhere below current context (relative path)
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes
* Matches any element node

Predicates (Filters)

Expression Description
[1] Selects the first element
[last()] Selects the last element
[@attr] Selects elements with the specified attribute
[@attr='val'] Selects elements where attribute equals value
[position()<3] Selects elements at position less than 3

Common Functions

text()

Selects the text content of a node

contains()

Checks if string contains substring

starts-with()

Checks if string starts with prefix

normalize-space()

Removes leading/trailing whitespace

count()

Counts the number of nodes

not()

Returns true if condition is false

Practical XPath Examples

Select External Links

//a[@href and contains(@class, 'external')]

Finds all anchor elements that have an href attribute and contain 'external' in their class.

Select Table Data (Skip Header)

//table//tr[position() > 1]/td[1]

Selects the first cell of each table row, excluding the header row.

Extract Visible Text Content

//*[not(self::script) and not(self::style)]//text()

Gets all text nodes except those inside script and style elements.

XPath Axes

Axes define relationships between the current node and other nodes in the document tree. They allow navigation in any direction.

ancestor::

Selects all ancestors (parent, grandparent, etc.)

descendant::

Selects all descendants (children, grandchildren, etc.)

following-sibling::

Selects all siblings after the current node

preceding-sibling::

Selects all siblings before the current node

child::

Selects all children of the current node

parent::

Selects the parent of the current node

Quick Menu

No recent tools