Logo

Free Online XPath Tester

Analyze XML documents using this free online XPath Tester. Provide an XML document by entering it into the text area or importing a file, add your XPath expression, and evaluate it to see which parts of the document satisfy the query. You can also display XML item types during testing.

XPath relies on properly structured XML to produce accurate matches. If your document isn’t valid, review it first with our XML Validator before evaluating the expression.

XPath Tester
Include XML Item Type in output
XPath Result

XPath Tester Examples

<?xml version="1.0" encoding="UTF-8"?>
<university xmlns:ac="http://www.academics.org">
    <departments>
        <department code="CS">
            <name>Computer Science</name>
            <head>Dr. Alice Johnson</head>
            <students>
                <student id="S101" level="Undergraduate">
                    <fullname>James Carter</fullname>
                    <gpa>3.8</gpa>
                </student>
                <student id="S102" level="Postgraduate">
                    <fullname>Olivia Brown</fullname>
                    <gpa>3.9</gpa>
                </student>
            </students>
        </department>

        <department code="ENG">
            <name>Engineering</name>
            <head>Dr. Michael Reed</head>
            <students>
                <student id="S103" level="Undergraduate">
                    <fullname>Daniel Smith</fullname>
                    <gpa>3.5</gpa>
                </student>
            </students>
        </department>
    </departments>

    <ac:courses>
        <ac:course code="C201">
            <ac:title>Data Structures</ac:title>
        </ac:course>
        <ac:course code="C202">
            <ac:title>Thermodynamics</ac:title>
        </ac:course>
    </ac:courses>
</university>

Example 1

Select the document node

/

Example 2

Select the root university element

/university

Example 3

Select all department elements

//department

Example 4

Select all department names

//department/name

Example 5

Select all students in the Computer Science department

//department[@code='CS']/students/student

Example 6

Select the id attributes of all students

//student/@id

Example 7

Select the full name of the first student

//student[1]/fullname/text()

Example 8

Select the last student in the document

//student[last()]

Example 9

Select all postgraduate students

//student[@level='Postgraduate']

Example 10

Select all students with GPA greater than 3.6

//student[gpa > 3.6]

Example 11

Select all children of the ac:courses element

/university/ac:courses/*

Example 12

Select all elements in the document

//*

Example 13

Select both department and course elements

//department | //ac:course

Example 14

Select the local name of the first course element

local-name(//ac:course[1])

Example 15

Count the total number of students

count(//student)

Related Tools