I have been trying to figure out this solution online. I am finding out the most efficient way of parsing an XML file.
The following is my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<game>
<person>
<name>ABC</name>
<address>XYZ</address>
<age>35</age>
</person>
<place>
<country>US</country>
<state>California</state>
<city>Fremont</city>
</place>
<thing>
<name>Book</name>
<use>Read and write</use>
</thing>
</game>
I have to parse this XML file using xPath in Java. I would like to have /*[i]
as the xPath expression where i
is an integer and 0<i<4
. Also I would like to display the whole "chunk" of XML. That is
if i=1, then the expression has to return <country>US</country><state>California</state><city>Fremont</city>
. Please help me out with this.Please do NOT use DOM (Ex. Node class) for this in any of the steps of your solution. Also please try to use Apache Commons framework as it uses SAX Parser internally.
Thanks.