XPath Element

XPath Element expression location path for finding XPath node in XML document. You can define either on relative or absolute.

Relative location path is sequence of child element separated by "/" (forward slash).

element_name/element_name

Absolute location path is beginning to a "/" (forward slash) with root element and after sequence of child element separated by "/" (forward slash).

/root_element/element_name/element_name

XPath Element Expression For Finding XPath Node

XPath Element Expression For Finding XPath Node

Following are some XPath element expressions for locating XPath nodes.

Expression Description
empinfo Direct child element
Select empinfo element all children nodes.
empinfo/employee Child of child element
Select employee node of the empinfo element.
empinfo/employee/name Sequence of child of child element
Select name element of employee element of empinfo element.
/ Root node
/empinfo All child elements of root element
Select all child elements of empinfo element.
/empinfo/employee Child of root element
Select all child element of empinfo root element.
/empinfo/employee/name Sequence of child of root element
Select name element of employee element of empinfo element.
*/employee Select all grand parent element
Select all employee grand parent elements.
// Descendant element
empinfo//employee Descendant of element
Select all employee element of empinfo element.
/empinfo//employee Descendant of root element
Select all employee element in XML document within context node empinfo root element.
//employee/name Child of descendant element
Select all name element in XML document within context node employee element.

empinfo: Select empinfo element all children nodes.

Expression relation: Direct child element

XPath selection: 2 to 18 lines

empinfo

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

empinfo/employee: Select employee node of the empinfo element.

Expression relation: Child of child element

XPath selection: 3 to 7, 8 to 12, 13 to 17 lines

empinfo/employee

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

empinfo/employee/name: Select name element of employee element of empinfo element.

Expression relation: Sequence of child of child element

XPath selection: 4, 9 and 14 lines

empinfo/employee/name

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

/empinfo: Select all child elements of empinfo element.

Expression relation: All child elements of root element

XPath selection: 2 to 18 lines

/empinfo

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

/empinfo/employee: Select all child element of empinfo root element.

Expression relation: Child of root element

XPath selection: 3 to 7, 8 to 12, 13 to 17 lines

/empinfo/employee

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

/empinfo/employee/name: Select name element of employee element of empinfo element.

Expression relation: Sequence of child of root element

XPath selection: 4, 9 and 14 lines

/empinfo/employee/name

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

*/employee: Select all employee grand parent elements.

Expression relation: Select all grand parent element

XPath selection: 3 to 7, 8 to 12, 13 to 17 lines.

*/employee

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

empinfo//employee: Select all employee element of empinfo element.

Expression relation: Descendant of element

XPath selection: 3 to 7, 8 to 12, 13 to 17 lines.

empinfo//employee

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

/empinfo//employee: Select all employee element in XML document within context node empinfo root element.

Expression relation: Descendant of root element

XPath selection: 3 to 7, 8 to 12, 13 to 17 lines

/empinfo//employee

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>

//employee/name: Select all name element in XML document within context node employee element.

Expression relation: Child of descendant element

XPath selection: 4, 9 and 14 lines

//employee/name

<?xml version="1.0" standalone="yes"?>
<empinfo>
  <employee id="1">
    <name>Opal Kole</name>
    <designation discipline="web" experience="3 year">Senior Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="2">
    <name from="CA">Max Miller</name>
    <designation discipline="DBA" experience="2 year">DBA Engineer</designation>
    <email>[email protected]</email>
  </employee>
  <employee id="3">
    <name>Beccaa Moss</name>
    <designation discipline="appdev">Application Developer</designation>
    <email>[email protected]</email>
  </employee>
</empinfo>