Comparing two xmls based on keys....

N

Nick

Hi,

I need to compare two xml files. Which contain multiple xml datas
based on a key.

So for eg. I have two xmls A.xml and B.xml.

A.xml :
<?xml version="1.0" encoding="UTF-8"?>
<Test >
<Item>1</Item>
<Name>Orange</Name>
</Test>
<Test >
<Item>2</Item>
<Name>Apple</Name>
</Test>

Whereas B.xml :

<?xml version="1.0" encoding="UTF-8"?>
<Test >
<Item>2/Item>
<Name>Apple</Name>
</Test>
<Test >
<Item>1</Item>
<Name>Orange</Name>
</Test>

If you compare tags row by row then the xmls won't match but if you
keep the Item as the key then both the xmls are equal.
Item : 1 / Name : Orange
Item : 2 / Name : Apple

How can you do such comparison in Java

Cheers
Nick
 
J

Joseph J. Kesselman

Nick said:
How can you do such comparison in Java

Sounds like a class assignment. Shouldn't be hard. I'd suggest using a
SAX parser to load the data from the first document into an
application-specific data structure, then to load the data from the
second document and check it off against the first. Don't forget to
handle the cases of more items present, fewer items present, and
duplicate items. Have fun,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,843
Latest member
WizcraftEntertainmentAgen

Latest Threads

Top