Question:
Can I merge XML Files Togeather with a Utility?
Milo Bloom
2008-07-30 19:31:24 UTC
A vendor of mine sends me updates of inventory via XML
(39 Files) Which I open each one at a time in Excel.

I was wondering if there was a program (Hopefully free)
or can I use a program that merges text files ( Also hopefully a free one) The only thing that concerns me is if the Schema comes up for every file, how opening it would handle that.

Just opening up each file every time is a pain in the butt.
Six answers:
Yahgoogle
2008-08-03 22:48:20 UTC
If you just want join the together, you can try Replace Pioneer, you can even add a filename before each file if you like.



Following is a detailed example on Replace Pioneer support page:



"How to merge many files into one file, and add filename before each file?"

http://www.mind-pioneer.com/services/conv_view.php?id=240



Replace Pioneer free trial download: http://www.mind-pioneer.com
?
2016-12-11 13:18:36 UTC
Concatenate Xml Files
2008-07-30 19:44:23 UTC
Saxon allows you to use the collection() function to access all the files in

a directory, for example



collection("file:///c:/some/dir?select=*.xml")



returns all the .xml files in the given folder.



So you can merge them like this:











or



There are a variety of ways to accomplish this with the Microsoft® .NET Framework, each of which uses a different type of XML API. To do this with the DOM API, you need to use the ImportNode function for copying XmlNode objects between documents. Since ImportNode only transfers control of the object between documents, you still need to call AppendChild (or InsertBefore, and so forth) in order to inject the node into the tree.

A There are a variety of ways to accomplish this with the Microsoft® .NET Framework, each of which uses a different type of XML API. To do this with the DOM API, you need to use the ImportNode function for copying XmlNode objects between documents. Since ImportNode only transfers control of the object between documents, you still need to call AppendChild (or InsertBefore, and so forth) in order to inject the node into the tree.

Figure 1 shows a complete C# example that merges two XML documents (product.xml and material.xml) into one. The new document has a root Container element which will hold the contents of the other two files. Use the XmlReader and XmlWriter APIs. To do this you'd use a single XmlWriter to generate the new XML document, along with several XmlReaders to merge other documents into the new one. XmlWriter provides a WriteNode method that reads through the supplied XmlReader object and writes all of its nodes in one shot (see Figure 2 ).

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();



Figure 1 Merging XML Docs



// the other documents will be merged into this one

// under the Container element

XmlDocument doc = new XmlDocument();

XmlNode cont = doc.CreateElement("Container");

doc.AppendChild(cont);



// first document to merge

XmlDocument stuff = new XmlDocument();

stuff.Load("product.xml");

XmlNode imported =

doc.ImportNode(stuff.DocumentElement, true);

doc.DocumentElement.AppendChild(imported);



// second document to merge

stuff.Load("material.xml");

imported = doc.ImportNode(stuff.DocumentElement, true);

doc.DocumentElement.AppendChild(imported);



// print merged documents

Console.WriteLine(doc.InnerXml);



And finally, you could also use XSLT to accomplish this via the document function. This is probably the easiest solution of all:




xmlns:xsl="http://www.w3.org/1999/XSL/Transform">













NaCH3COO
2008-07-30 19:33:50 UTC
Check this out:



http://msdn.microsoft.com/en-us/magazine/cc164169.aspx
?
2016-08-01 08:58:18 UTC
This may be feasible
2016-08-28 23:14:40 UTC
that is an interesting question


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...