my dog learned polymorphism
The moose likes XML and Related Technologies and the fly likes XML file comparison 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 file comparison" Watch "XML file comparison" New topic

XML file comparison

ARS Kumar
Ranch Hand

Joined: May 22, 2000
Posts: 108
Hi all
Is there any tool ( in Java API ) which I can use in my application to compare two XML files ?
ARS Kumar.

ARS Kumar, Sun Certified Programmer for Java 2 Platform
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Since XML files are text-based, you can use any freely available file comparison tools to compare XML files. Or even better, you can write one yourself.
Many implementations of DOM( Sun, IBM, Oracle etc ) also have helper methods that return the String representation of the XML document. If you just want to compare two XML files to findout if they are same( and not worry about how they differ if they differ, ) then you can simply use equals() method on the returned string objects. Voila!!
Hope that helps
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
ARS Kumar
Ranch Hand

Joined: May 22, 2000
Posts: 108
Hi Ajith
What you said is what I end up doing. I don't see any single method that returns a String in xercers parser. So I wrote a small method to just read in the XML file and created a String out of it. Then I did the the string comparison like you mentioned with a small change. In this specific case I need to eliminate one tag before comparing. is the tool which I found close to what I was looking for. Because while comparing the two XML files actually I need to know which are tags that changed. I am in the process of evaluating the same. The free version is only available as command line.
Thanks a lot for your help

ARS Kumar
Sun Certified Java 2 Programmer.
I agree. Here's the link:
subject: XML file comparison
It's not a secret anymore!