You can execute multiple expressions on an XML file with the use of XPath "|" separator. It allows you more flexibility by allowing you to execute multiple expressions at a time.
In this example we have created an XML file "persons.xml" as in our previous section, which is necessary to execute XPath query on to it. This "persons.xml" contains information related to name, age, gender of different persons.
Here is the full source code for persons.xml file as follows :
Now we have declared a class XPathSeparator and in this class we are parsing the XML file with JAXP. First of all we need to load the document into DOM Document object. We have put that persons.xml file in that current working directory.
Above lines of code parses "persons.xml" file and creates a Document object. Next we have created XPath object with the use of XPathFactory.
When we will execute the following expression then it
will execute both expressions "//person/name/text()" as well as
Here is the full example code for XPathSeparator.java as follows:
To run this example :
Ask Questions? Discuss: Use of "|" separator for selecting more than one path
Post your Comment
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.