Well, there's no simple way to merge xml documents. Why? You have to be completely sure that desired content will be OK (in aspect of structure and values).
Let me explain it on below example:
string xcontent1 = @"<root>
<Item id='1'>
<Subitems>
<Subitem sid='1'>A</Subitem>
<Subitem sid='2'>B</Subitem>
</Subitems>
</Item>
<Item id='2'>
<Subitems>
<Subitem sid='1'>A</Subitem>
<Subitem sid='2'>B</Subitem>
<Subitem sid='3'>C</Subitem>
</Subitems>
</Item>
</root>";
string xcontent2 = @"<root>
<Item id='1'>
<Subitems>
<Subitem sid='1'>A</Subitem>
<Subitem sid='2'>E</Subitem>
<Subitem sid='3'>F</Subitem>
</Subitems>
</Item>
<Item id='3'>
<Subitems>
<Subitem sid='1'>A</Subitem>
<Subitem sid='2'>B</Subitem>
<Subitem sid='3'>C</Subitem>
</Subitems>
</Item>
</root>";
XDocument xdoc1 = XDocument.Parse(xcontent1);
XDocument xdoc2 = XDocument.Parse(xcontent2);
XDocument xdst = new XDocument();
xdst.Add(xdoc1.Root);
xdst.Root.Add(xdoc2.Root.Elements());
Result of merged document:
<root>
<Item id="1">
<Subitems>
<Subitem sid="1">A</Subitem>
<Subitem sid="2">B</Subitem>
</Subitems>
</Item>
<Item id="2">
<Subitems>
<Subitem sid="1">A</Subitem>
<Subitem sid="2">B</Subitem>
<Subitem sid="3">C</Subitem>
</Subitems>
</Item>
<Item id="1">
<Subitems>
<Subitem sid="1">A</Subitem>
<Subitem sid="2">E</Subitem>
<Subitem sid="3">F</Subitem>
</Subitems>
</Item>
<Item id="3">
<Subitems>
<Subitem sid="1">A</Subitem>
<Subitem sid="2">B</Subitem>
<Subitem sid="3">C</Subitem>
</Subitems>
</Item>
</root>
As you can see, merged xml document contains 2
Item
nodes with the same
id
(1), but with different content (
Subitems
). There's one rule, which you have to respect:
Programmers have to be wiser than users. ;)
Conclusion: You have to provide method which will go through the nodes collection (and their subnodes) to be able to compare each node with currently imported node.