Merge two XDocuments

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)

 


Tags: ,

.NET | LINQ

Powered by BlogEngine.NET 1.6.1.2
Theme by Daniel Halan

About the author

Daniel Halan Daniel Halan systems architect at Logica in Sweden.

Working primary with Microsoft Dynamics CRM.

Complete Profile

The content of this site are my own personal opinions and do not represent my employer's view in anyway.

Follow me on Twitter