Created
January 31, 2012 18:31
-
-
Save teradyne/1712060 to your computer and use it in GitHub Desktop.
Merge multiple XML files into single file given a node.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Merge Multiple XML files into a single XML file with a specific node. | |
//For quickest result use linqpad. | |
//Language: C# Statement(s) | |
var downloadfolder = @"G:\temp\"; // your download folder where there are multiple files | |
string[] files = Directory.GetFiles(downloadfolder); | |
var masterfile = new XDocument(); | |
XElement newDocument = new XElement("root"); | |
masterfile.Add(newDocument); | |
foreach (var file in files) | |
{ | |
Console.WriteLine("--------------------------------------------------"); | |
Console.WriteLine(file); | |
Console.WriteLine("--------------------------------------------------"); | |
XDocument xdoc = XDocument.Load(file); | |
masterfile.Root.Add(xdoc.Descendants("company")); //your root note | |
} | |
masterfile.Dump(); | |
masterfile.Save( @"G:\temp\merged_.xml"); |
Hi friend,
I tried this but i am getting an error (Error: 'XDocument' does not contain a definition for 'Dump' and no extension method 'Dump' accepting a first argument of type 'XDocument'could be found ) on masterfile.Dump();
Can anyone help regarding this error ???
This was created using LINQPad.
This .Dump() is an extension method provided there.
It can be discarded elsewhere.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi friend,
I tried this but i am getting an error (Error: 'XDocument' does not contain a definition for 'Dump' and no extension method 'Dump' accepting a first argument of type 'XDocument'could be found ) on masterfile.Dump();
Can anyone help regarding this error ???