• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Compare two xml documents in Java DOM

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that to walk through a document using Java/Jaxp DOM you can use recursion, but I am trying to find a way for the following. There are two xml documents 1 and 2. The code needs to loop through the elements of document 2 and check if an element of document 2 exists in document 1. If it does not exist, then the code should add the element at that heirarchy. The problem is, with nesting and all, its complicated. Would greatly appreciate if someone could show if there is a easier way to do this. No assumptions about an existing structure for the xml can be made

Sample XMLs are shown below

Document 1
<employeelist>
<employee>
<id>2134</id>
<name>javaguy</name>
</employee>
<employee>
<id>2134</id>
</employee>
</employeelist>

Document 2
<employeelist>
<employee>
<id>2134</id>
<name>javaguy</name>
</employee>
<employee>
<id>2135</id>
<name>oracleguy</name>
</employee>
</employeelist>


The code should read both docs and update doc 1 with the name for employee with id 2135 as oracleguy. I can create document elements and all that stuff, so any code snippets to do this should just be great
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic