aspose file tools*
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
Author

XML Compare with XPath

bhavya raj
Greenhorn

Joined: May 18, 2006
Posts: 13
Hi,

Using DOM to parse XML.

Requirement is comparing the 2 xmls.

<Employee-Detail >
<Employee>
<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.

Regards
Bhavya
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi,

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?

Cheers,
Raj.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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.

Bill
florina dev
Greenhorn

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: http://aspose.com/file-tools
 
subject: XML Compare with XPath