All of the solutions I have come across regarding merging XML documents do not accomplish what I desire. Let me explain:
XML Document 1:
<?xml version="1.0" encoding="utf-8" ?>
<a>
<b title="Original Section">
<b title="Original Child Section"></b>
<b title="Original Child Section 2"></b>
</b>
</a>
XML Document 2:
<?xml version="1.0" encoding="utf-8" ?>
<a>
<b title="New Section">
<b title="New Child Section"></b>
</b>
<b title="Original Section">
<b title="Original Child Section">
<b title="New Child For Old Section"></b>
</b>
</b>
</a>
Into a final doc like this:
<?xml version="1.0" encoding="utf-8" ?>
<a>
<b title="Original Section">
<b title="Original Child Section">
<b title="New Child For Old Section"></b>
</b>
<b title="Original Child Section 2"></b>
</b>
<b title="New Section">
<b title="New Child Section"></b>
</b>
</a>
The documents are similar in content, but can have an arbitrary number of child nodes. I also would like to eliminate duplicates. I consider duplicates being elements with the same attributes (based on attribute name and value). Has anyone seen a working example of this implementation? I can envision how I would write it using some loops and a bit of recursion, but to me, that just doesn't seem like the best way to accomplish what I want :)
Cheers and thanks in advance!
* EDIT *
Since the consensus is that loops and recursion are a must, what would be the most elegant and efficient way to accomplish this? I suppose another fundamental question to this problem is what is the best way to compare the nodes as you iterate?