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 compare two XML files using DOM parser 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 "compare two XML files using DOM parser " Watch "compare two XML files using DOM parser " New topic

compare two XML files using DOM parser

Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
I need to compare two XML files in which second XML file has some slight modifications and I need to compare that particular node. Can any one help me by providing tutorials or any API( if its available).
As I am new in XML parsing.
for example-
First XML file
Second XML file--

like that some more nodes are there as I have to check names and then check enable_status and visisbility
How can I do that. Please help me
Thanks in advance.

SCJP1.5(81%), SCDJWS(94%), next mission SCEA (but need to wait or that)
Craig Bayley
Ranch Hand

Joined: Sep 27, 2007
Posts: 46
Hava a look at xmlunit....You can use that to perform a diff.
Alternatively, marshall the xml into java objects and do direct comparison that way.
Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
As I am new to XML parsing could you please provide any link or tutorial for marshalling into java objects.
Thanks in advance.
Ugender Rekulampally
Ranch Hand

Joined: Nov 14, 2005
Posts: 135
follow this link for marshalling (generating XML document using JAVA objects)
and you search/google for unmarshalling (XML document to Java objects) which you want to look into.

I couldn't find a proper link for unmarshalling so get familiarize with marshalling first and unmarshalling will be real easy (just opposite to marshalling).

post any questions you have while you are working on unmarshalling.

praveen oruganti
Ranch Hand

Joined: Feb 05, 2007
Posts: 74
use Castor Framework.

Just convert the first Xml into object and second xml into object and then compare.

Then marshal it.

Regards,<br />Praveen Oruganti<br />Software Programmer
I agree. Here's the link:
subject: compare two XML files using DOM parser
It's not a secret anymore!