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 Comparing 2 XML Files 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 "Comparing 2 XML Files" Watch "Comparing 2 XML Files" New topic

Comparing 2 XML Files

Dave Hewy
Ranch Hand

Joined: Aug 21, 2003
Posts: 93
I have a requirement to compare 2 XML files, say A and B, and to mark-up B to flag the differences. I think at this stage the structure will be the same, but am not certain.

So if an element has changed in B, then B would have an extra attribute added, something like changed="Y".

I need to do this programatically, has anyone had a similar experience that can point me at some info ?


William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Are these files small enough that both will fit in memory as DOMs?
I'm assuming that you want to ignore differences in formatting that a pure text comparison would find. For example - you want the two ways of writing an empty element to be considered identical.
<element></element> same as <element/>

A google search for "xml document equality" gets loads of hits since this problem has been bothering XML people for a long while.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Another good set of search keywords is "xml diff".
I agree. Here's the link:
subject: Comparing 2 XML Files
It's not a secret anymore!