Hi!
I want to find the xpath of an xml doument along with its index value in java. I'm using DOM parser to parse the xml document.

Suppose if i consider this xml document,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE folks SYSTEM "sample.dtd">
<folks>
<person>
<name>abi</name>
<phone>999555-8888</phone>
<email>b@xyz.net</email>
</person>
<person>
<name>saran</name>
<phone>213545697</phone>
<email>bbb@abc.com</email>
</person>
<person>
<name>priya</name>
<phone>33333</phone>
<email>xxxx@xyz.com</email>
</person>
</folks>

I have found the xpath of this document as,

/folks
/folks/person
/folks/person/name
/folks/person/phone
/folks/person/email
/folks/person
/folks/person/name
/folks/person/phone
/folks/person/email
/folks/person
/folks/person/name
/folks/person/phone
/folks/person/email

I should find the xpath as
/folks[1]
/folks[1]/person[1]
/folks[1]/person[1]/name[1]
/folks[1]/person[1]/phone[1]
/folks[1]/person[1]/email[1]
/folks[1]/person[2]
/folks[1]/person[1]/name[2]
and so on....
so that i can add a node in the exact position i want.

Any help Appreciated.

Thanks in Advance.

Hi!
I have solved this issue using sax parser.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.