Maybe I'm not understanding you correctly.
Here's my Books1.xml that I used:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Books>
<Book Id="Book1">
<TITLE>Title of Book 1</TITLE>
<AUTHOR>Author of Book 1</AUTHOR>
<YEAR>2010</YEAR>
</Book>
<Book Id="Book2">
<TITLE>Title of Book 2</TITLE>
<AUTHOR>Author of Book 2</AUTHOR>
<YEAR>2011</YEAR>
</Book>
</Books>
</Root>
And Books2.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Books>
<Book Id="Book3">
<TITLE>Title of Book 3</TITLE>
<AUTHOR>Author of Book 3</AUTHOR>
<YEAR>2006</YEAR>
</Book>
<Book Id="Book4">
<TITLE>Title of Book 4</TITLE>
<AUTHOR>Author of Book 4</AUTHOR>
<YEAR>2000</YEAR>
</Book>
</Books>
</Root>
Here's the code I used to test with:
Code:
var xml1 = XDocument.Load("C:\\Temp\\Books1.xml");
var xml2 = XDocument.Load("C:\\Temp\\Books2.xml");
xml1.Descendants("Books").FirstOrDefault().Add(xml2.Descendants("Books").FirstOrDefault().Nodes());
xml1.Save("C:\\Temp\\CombinedBooks.xml");
And here's the resultant CombinedBooks.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Books>
<Book Id="Book1">
<TITLE>Title of Book 1</TITLE>
<AUTHOR>Author of Book 1</AUTHOR>
<YEAR>2010</YEAR>
</Book>
<Book Id="Book2">
<TITLE>Title of Book 2</TITLE>
<AUTHOR>Author of Book 2</AUTHOR>
<YEAR>2011</YEAR>
</Book>
<Book Id="Book3">
<TITLE>Title of Book 3</TITLE>
<AUTHOR>Author of Book 3</AUTHOR>
<YEAR>2006</YEAR>
</Book>
<Book Id="Book4">
<TITLE>Title of Book 4</TITLE>
<AUTHOR>Author of Book 4</AUTHOR>
<YEAR>2000</YEAR>
</Book>
</Books>
</Root>
You say you've got n number of files to go through. Just keep adding the nodes to xml1.Descendants("Books").FirstOrDefault() and then save the merged files when you're done.
Code:
var xml1 = XDocument.Load(@"C:\Temp\Books1.xml");
var xml2 = XDocument.Load(@"C:\Temp\Books2.xml");
xml1.Descendants("Books").FirstOrDefault().Add(xml2.Descendants("Books").FirstOrDefault().Nodes());
var xml3 = XDocument.Load(@"C:\Temp\Books3.xml");
xml1.Descendants("Books").FirstOrDefault().Add(xml3.Descendants("Books").FirstOrDefault().Nodes());
xml1.Save("C:\\Temp\\CombinedBooks.xml");
If you're looking for something different then I'll need a little more information on what you'd like the end result to look like before I can help.