How to select several path of XPath in XML
In this article I will explain how to select the several path in XPath.
Introduction
In this article I will explain how to select the several path in Xml.With the help of | operator in XPath we can select multiple paths/or several paths. Lets take an example to understand this concept.
Example
<?xml version="1.0" encoding="utf-8" ?>
<Employee>
<Trainee>
<Name>Harry</Name>
<id>1234</id>
<Salary>10k</Salary>
<address street="12">Delhi</address>
</Trainee>
<Trainee>
<Name>Georage</Name>
<id>1432</id>
<Salary>20k</Salary>
<address street="10">Delhi</address>
</Trainee>
</Employee>
|
The following lines listed some path expressions and the result of the expressions
//Trainee/address | //Trainee/
salary
: Selects all the address AND salary elements of all Trainee elements.
//address | //salary : Selects all the address AND salary elements in the document.
/Employee/Trainee/address | //salary : Selects all the address elements of the Trainee element of the Employee element AND all the salary elements in the document.
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here