For example I have the following XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
I want to query book and return the following text:
<title lang="eng">Harry Potter</title>
<price>29.99</price>
Is it possible in XPath? If yes, how do I go about doing that?
Thank you.
An XPath expression can select the nodes you want, but the serialization is up to the programming language (such as XSLT, C#, PHP, Java) that hosts XPath and its API (such as DOM objects and methods).
This XPath expression:
selects exactly the wanted nodes:
The XPath expression above, in plain English, means:
Select all elements that are children of the first (in document order)
bookelement that is a child of the top element (regardless what is its name) of the XML document.