How to append multiple XML files

Active3 hr before
Viewed126 times

6 Answers


edit: I've found that in Excel you can import multiple xml files. You have to go to the Develop tab (show it if it's hidden). Then in the XML group, choose Import and select multiple XML files. That should work., Podcast 394: what if you could invest in your favorite developer? ,This code produces a common XML element and collects in it the contents of any .xml files it finds according to the file set. See: , What is "anti-geysering" and why would you turn it off 70 seconds before launch?

In your case, however, you may not want to introduce this new layer to the XML. If all you're doing is viewing the XML in a single area (eg: in a web browser) then this works.

@echo on
rem ==clean up==
erase %0.xml
rem ==add the root node==
echo ^<root^> > %0.txt
   rem ==add all the xml files==
   type *.xml >> %0.txt
   rem ==close the root node==
   echo ^<^ /root^> >> %0.txt
      rem ==rename to xml==
      ren %0.txt %0.xml
load more v

Q How can I merge the contents of multiple XML files into one?,Feel free to download the sample code from the link at the top of this article and experiment on your own.,When you do, by default wsdl.exe generates a proxy class with the endpoint's URL hardcoded into the constructor, as shown here:,The client application code in Figure 8 illustrates how to use these methods to implement the UDDI invocation pattern.

Figure 2 WriteNode Method

// new document stream XmlWriter tw = new XmlTextWriter(Console.Out); tw.WriteStartDocument(); tw.WriteStartElement("Container"); // write product.xml to new document stream XmlTextReader reader = new XmlTextReader("product.xml"); tw.WriteNode(reader, true); // write material.xml to new document stream reader = new XmlTextReader("material.xml"); tw.WriteNode(reader, true); tw.WriteEndElement(); tw.WriteEndDocument();
load more v

I tried that solution, but it merges the data, I mean it inserts the <assets> of all the five or six XML files into the single XML file, but the <items> in the combined XMl files are only 100, i.e that is the number of items per file, and a total of 594 items are present in all the XML files,thanks to decker the problem's solved though through a little different approach, but his idea clicked, now I face another problem when I try to read that XML file using the following code it gives and XMLException error,    i see, you have opened file using "File.Open". that is fine. But you have not close it. After completion of processing you should close it  programatically.,I have a problem here, and it worsens as I have to use .NET 2 or below, I have to combine the data from multiple XML files into one, and all the files will have the same structure, and the first nodes along with all its child nodes from all the files needs to be trimmed and discarded, except the first file. the structure is given below, actually I need to combine all the items along with their childs into one XML file, any help would be appreciated, once again I cannot use LINQ as its only available in 3.5 or above.

In my mind,I think you can try to fetch all the nodes under itemList do conbinations。Try this——

namespace MyTest {
   class Program {
      public static void Merge(string fileName, XmlDocument originalSource, XmlElement ele) {
         XmlDocument cdoc = new XmlDocument();
         var result = cdoc.DocumentElement.GetElementsByTagName("item")[0].InnerXml;
         XmlElement newe = originalSource.CreateElement("item");
         newe.InnerXml = result;
      static void Main(string[] args) {
         //Read the first file
         XmlDocument doc = new XmlDocument();
         //Fetch the itemList tag
         var result = doc.DocumentElement.GetElementsByTagName("item")[0] as XmlElement;
         //Call this to merge
         Merge("abc2.xml", doc, result);

Partners Events News Case StudiesAbout UsCustomersQuotesCareersLegal,ShopPricing and licesing for businesses, Academic and individuals Sales FAQ Register Code Sales Support Resellers

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="" xmlns:xs="" xmlns:fn="">
   <xsl:output method="xml" />
   <xsl:template match="/">
         <xsl:apply-templates mode="rootcopy" />

   <xsl:template match="node()" mode="rootcopy">
         <xsl:variable name="folderURI" select="resolve-uri('.',base-uri())" />
         <xsl:for-each select="collection(concat($folderURI, '?select=*.xml;recurse=yes'))/*/node()">
            <xsl:apply-templates mode="copy" select="." />

   <!-- Deep copy template -->
   <xsl:template match="node()|@*" mode="copy">
         <xsl:apply-templates mode="copy" select="@*" />
         <xsl:apply-templates mode="copy" />

   <!-- Handle default matching -->
   <xsl:template match="*" />
load more v

XmlCombiner allows to combine multiple XML files into one.,For instance having two XML documents:, Combines several XML documents into one , Combines several XML documents into one

load more v

The files need to all have the same outer tags.,I have several xml files. They all have the same structure, but were splitted due to file size. So, let's say I have A.xml, B.xml, C.xml and D.xml and want to combine/merge them to combined.xml, using a command line tool.,The outer tags must not have attributes.,To combine files, run:


   <product id="1234"></product>


   <product id="5678"></product>
load more v

Other "files-append" queries related to "How to append multiple XML files"