• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Compare with XPath

 
bhavya raj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic