• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to compare two xml files?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I need to compare two xml files and validate whether all elements are same.I am using DOM api to parse the xml files.I have retrieved the values but i am getting stuck in comparison.
Kindly help out.

Regards,
Ananthakumar
 
Ranch Hand
Posts: 69
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using some good xml parser like sax or DOM xml parsers
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's true, without a parser you won't be able to do anything with any XML document. But it isn't very helpful, as the parser does absolutely nothing to help you to compare two XML documents.

Ananthakumar: you haven't said what you want to get out of this comparison. Do you just want to know if the two documents differ? Or what?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to determine if two XML documents are identical in the infoset sense is a classic XML problem.

Some problems:
1. an empty element is the same as a start element followed immediately by an end element.
2. the order of attributes is not significant

A bit of googling found this attempt to create a Diff for XML documents.

I have not tried that toolkit, please let us know how it works if you try it.

Bill
 
Anantha kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
Thank you for your response about this topic.Actually whats my problem is i can get the data elements from one xml and store it into hashmap and can get all the elemens from another one xml and store it into another hashmap.But the problem is one xml is well formatted one and another one is not well formated.i dont know how to proceed hereafter.Please help me out in this.

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anantha kumar wrote:
Actually whats my problem is i can get the data elements from one xml and store it into hashmap and can get all the elemens from another one xml and store it into another hashmap.



Hmm, I'm not sure how that really works. What's the purpose of storing them in a HashMap? Is it stored just like some random Strings?

But the problem is one xml is well formatted one and another one is not well formated.i dont know how to proceed hereafter



How did you figure out that one xml is well formatted and the other is not?

 
Anantha kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jaikiran,

For performance use only am using hashmap.My one xml file contains <details>213310873*|#1067*|#11588*|#2009-08-28T07:12:54.000000<details> tag.

another well formed one contains:
<details>
<no>213310873</n>
<no1>1067>
...
</details>

So i have to compare those values 213310873 from two files and chec whether its equal or not.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not going to be able to use XML tools if you don't have an XML document. So either:

1. repair the ill-formatted document
-or-
2. write your own code to extract the elements/text you want to compare by normal Java String methods.

Your description of the problem seems to have changed - do you really want to test for equality of two documents or are you just checking for identity of one small data item?

Bill

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try XMLUnit
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or search for "xml diff"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic