Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic