This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to compare two xml files?

 
Anantha kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
mahesh shinde
Ranch Hand
Posts: 69
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using some good xml parser like sax or DOM xml parsers
 
Paul Clapham
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • 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
  • 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.

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • 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

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try XMLUnit
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or search for "xml diff"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic