I need to read xml data and put it on the browser. I thought frist i will get xpath of all the elements and get its value calling xpath from my another java program.
Is there any better way to do it ? please suggest me?! In the following code the last element's number is
getting incremented where i want that to start from [0].
Can anyone please help me?
My code as follows:
book.xml
<?xml version = "1.0" encoding= "ISO-8859-1" standalone ="no"?>
<book>
<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>
<person>
<first>Bill</first>
<last>Gates</last>
<age>46</age>
</person>
<person>
<first>Steve</first>
<last>Jobs</last>
<age>40</age>
</person>
</book>
[/cdoe]
My java code as follows:
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
/**
* SAX handler that creates and prints XPath expressions for each element encountered.
*
* for above book.xml, my program will report
*
* //book[0]
//book[0]/person[0]
//book[0]/person[0]/first[0]---> This segment is working fine.
//book[0]/person[0]/last[0]
//book[0]/person[0]/last[0]/name[0]
//book[0]/person[0]/age[0]
//book[0]/person[1]
//book[0]/person[1]/first[1]->(this is wrong: should be //book[0]/person[1]/first[0])
//book[0]/person[1]/last[0]
//book[0]/person[1]/age[0]
//book[0]/person[2]
//book[0]/person[2]/first[2]-> (this is wrong: should be //book[0]/person[2]/first[0])
//book[0]/person[2]/last[0]
//book[0]/person[2]/age[0]