I have a very specific requirment of comparing 2 xml strings in java. I have 2 xml strings. Original and modified. I need to compare the original xml string with the modified and find out what has been modified.
For example:
Original xml is
<Mycontacts>
<contact>
<firstName>Robert</firstName>
<PhoneNumber>9053428756</PhoneNumber>
<lastName>Bobbling</lastName>
<mobile>4168014523</mobile>
</contact>
<contact>
<firstName>Lily</firstName>
<PhoneNumber>9053428756</PhoneNumber>
<lastName>Bobbling</lastName>
<mobile>4168014523</mobile>
</contact>
</Mycontacts>
Modified xml:
<Mycontacts>
<contact>
<firstName>Robert</firstName>
<PhoneNumber>40454321333</PhoneNumber>
<lastName>Bobbling</lastName>
<mobile>4168014523</mobile>
</contact>
</Mycontacts>
As 1 contact is modified here and 1 id deleted I want to form 2 xml's trees. 1 is modify_xml and 1 is delete xml
modify xml:
<contact>
<firstName>Robert</firstName>
<PhoneNumber>40454321333</PhoneNumber>
<lastName>Bobbling</lastName>
<mobile>4168014523</mobile>
</contact>
delete xml:
<contact>
<name>Lily</name>
</contact>
How can this be done using java API's? Is parsing each node and creating a map for each contact entry a good option?