XPATH Tester


    
XPath Expression
About XPATH Tester
XPath Tester is an online tool to test your XPath expressions/queries against an XML file. It supports most of the XPath functions (string(), number(), name(), string-length() etc.) and does not limit you to working against nodes. It fully supports XML namespaces, but the declarations MUST be explicit and MUST be on the root XML element. You can include the XML item type (Attribute, Element, Text, etc.) as part of the output and allows you to better understand which parts were matched.

How to test XPATH expression against XML?

  • To test your XPATH expression against XML add/ copy and paste the XML and XSD data into the input.
  • You can also load the XML data from the url by clicking the button or load the XML data from the computer by clicking the button.
  • Enter the appropriate XPATH query expression. Look into the below 'XPATH Query' expressions for your reference.
  • Click the 'Test' button to parse your xml and get the output based on the xpath expression

XPATH Query

ExpressionDescription
/Select the document node
/rootSelect the 'root' element
/root/celebritys/celebritySelect all 'celebrity' elements that are direct children of the 'celebritys' element.
//foo:artistSelect all 'artist' elements regardless of their positions in the document.
//foo:artist/@id Select the 'id' attributes of the 'artist' elements regardless of their positions in the document.
//celebrity[1]/text()Select the textual value of first 'celebrity' element.
//celebrity[last()]Select the last 'celebrity' element.
//celebrity[position() < 3]Select the first and second 'celebrity' elements using their position.
//celebrity[@id]Select all 'celebrity' elements that have an 'id' attribute.
//celebrity[@id='3']Select the 'celebrity' element with the 'id' attribute value of '3'.
//celebrity[@id<=3]Select all 'celebrity' nodes with the 'id' attribute value lower or equal to '3'.
/root/foo:singers/*Select all the children of the 'singers' node.
//*Select all the elements in the document.
//celebrity|//foo:artistSelect all the 'celebrity' elements AND the 'artist' elements.
name(//*[1])Select the name of the first element in the document.
number(//celebrity[1]/@id)Select the numeric value of the 'id' attribute of the first 'celebrity' element.
string(//celebrity[1]/@id)Select the string representation value of the 'id' attribute of the first 'celebrity' element.
string-length(//celebrity[1]/text())Select the length of the first 'celebrity' element's textual value.
local-name(//foo:artist[1])Select the local name of the first 'artist' element, i.e. without the namespace.
count(//foo:artist)Select the number of 'artist' elements.
sum(//foo:artist/@id) Select the sum of the 'id' attributes of the 'artist' elements.
Related Tools

XPATH Tester