Comparing two xmls based on keys....

Discussion in 'XML' started by Nick, Jun 17, 2008.

  1. Nick

    Nick Guest

    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
    Nick, Jun 17, 2008
    #1
    1. Advertising

  2. Nick wrote:
    > 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,
    Joseph J. Kesselman, Jun 17, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maalej

    2 xmls

    maalej, Apr 23, 2005, in forum: XML
    Replies:
    1
    Views:
    504
    Dimitre Novatchev
    Apr 23, 2005
  2. maalej

    edit xmls like

    maalej, Aug 16, 2005, in forum: XML
    Replies:
    3
    Views:
    466
    Peter Flynn
    Aug 18, 2005
  3. Stefan
    Replies:
    2
    Views:
    1,012
  4. Replies:
    1
    Views:
    401
    Andy Dingley
    Dec 21, 2006
  5. Jason
    Replies:
    8
    Views:
    128
    Dr.Ruud
    Jul 27, 2006
Loading...

Share This Page