File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XML Compare with XPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Compare with XPath " Watch "XML Compare with XPath " New topic

XML Compare with XPath

bhavya raj

Joined: May 18, 2006
Posts: 13

Using DOM to parse XML.

Requirement is comparing the 2 xmls.

<Employee-Detail >
<Emp_Id id="10" name="madhu"> E-001 </Emp_Id>

In Above xml if i give xpath emp_id then i should get Complete XPAth

LIke Employee-Detail/Employee/Emp_Id

How to handle this situation.

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 445


I don't see the issue using XPath if you already know the structure of the XML document beforehand. Otherwise you probably would be better of using SAX parsers (you don't intend to modify the XML, right?) Iterate through the elements/nodes in a breadth first or depth first fashion and compare each against the other. Does this answer your query?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Requirement is comparing the 2 xmls.

Please describe the requirement in more detail.

Are you trying to determine if every Emp_id in XML document A has a matching entry in XML document B or what?

An xpath expression can return a NodeList of Emp_id Nodes but you will still have to program the comparison.

florina dev

Joined: Oct 25, 2008
Posts: 1
Hi Bhavya,
Here is a suggestion. I have a tool at my desk to compare two xml files. It compares, highlights the changes and allows us to edit and save the changes on requirement. But I m not sure about how far it would help you in Xpath search. I have the tool with opensource. Better you try in enhancing the coding according to your requirement.
The tool is XML Comparer from wbcsoftwarelab.
Hope your trouble solved dear. Review and reply.
I agree. Here's the link:
subject: XML Compare with XPath
It's not a secret anymore!