XPath Tester

This tool allows you to test XPath queries on XML data. Enter your XML, write an XPath query, and see the results.

Loading...
XPath Examples

Click on an example to load the sample XML and the query.

  • Select the document node/

  • Select the 'root' element/root

  • Select all 'actor' elements that are direct children of the 'actors' element/root/actors/actor

  • Select all 'singer' elements regardless of their positions in the document//foo:singer

  • Select the 'id' attributes of the 'singer' elements//foo:singer/@id

  • Select the textual value of first 'actor' element//actor[1]/text()

  • Select the last 'actor' element//actor[last()]

  • Select the first and second 'actor' elements using their position//actor[position() < 3]

  • Select all 'actor' elements that have an 'id' attribute//actor[@id]

  • Select the 'actor' element with the 'id' attribute value of '3'//actor[@id='3']

  • Select all 'actor' nodes with the 'id' attribute value lower or equal to '3'//actor[@id<=3]

  • Select all the children of the 'singers' node/root/foo:singers/*

  • Select all the elements in the document//*

  • Select all the 'actor' elements AND the 'singer' elements//actor|//foo:singer

  • Select the name of the first element in the documentname(//*[1])

  • Select the numeric value of the 'id' attribute of the first 'actor' elementnumber(//actor[1]/@id)

  • Select the string representation value of the 'id' attribute of the first 'actor' elementstring(//actor[1]/@id)

  • Select the length of the first 'actor' element's textual valuestring-length(//actor[1]/text())

  • Select the local name of the first 'singer' elementlocal-name(//foo:singer[1])

  • Select the number of 'singer' elementscount(//foo:singer)

  • Select the sum of the 'id' attributes of the 'singer' elementssum(//foo:singer/@id)