by Daniel Halan
14. September 2009 21:43
Was looking for a standard way of merging two XML Documents using XDocument objects, but found none with duplicate checking. You can use this short snippet bellow to merge two XDocuments, but then duplicate elements will also populate the merged document, so here comes a handy little method that also checks for duplicate items.
Simple Merge (Copy all)
XDocument xdoc = XDocument.Load("a.xml");
xdoc.Root.Add( XDocument.Load("b.xml").Root.Elements() );
Merge with duplicate element check (C# Class)
HalanTools.zip (0,71 KB)