Duplicate:
Combine XML with attributes
I have two XML files that I would like to combine.
The merged file must contain each element from both files (supporting a hierarchy) when elements from the second XML can override elements from the first XML:
If two elements are identical (same XPATH, same properties), I would like to override.
There are probably a million ways to do this - this is the easiest (without XSLT training, preferably)
Example result:
File 1
<a>
<b foo="d"/>
<b bar="c"/>
<c/>
</a>
File 2
<a>
<b foo="e"/>
<b boo="c"/>
<c/>
</a>
<x>
<b bar="c"/>
</x>
Exit
<a>
<b foo="d"/>
<b bar="c"/>
<b boo="c"/>
<c/>
</a>
<x>
<b bar="c"/>
</x>
source
share