Combining multiple xml documents into one large one with a batch file

Combining multiple xml documents into one large one with a batch file

A very easy approach will be to do a simple copy:

n

n

copy *.xml new.xml

n

n

The new.xml file created will have all the xml files merged together. You can create a BAT file with the same command

Heres a quick batch command that combines all the xml files in the current directory into a single file CombineXML.bat. It wraps all the XML files with a new root node (<root>).

n

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

n

[email protected] onnrem ==clean up==nerase %0.xmlnrem ==add the root node==necho ^<root^> > %0.txtnrem ==add all the xml files==ntype *.xml >> %0.txtnrem ==close the root node==necho ^<^/root^> >> %0.txtnrem ==rename to xml==nren %0.txt %0.xmln

Combining multiple xml documents into one large one with a batch file

The problem is that XML has a single starting tag like: <?xml version=1.0 encoding=UTF-8?> that would be repeated on the merged document. Also, if theres a root tag that contains all the others, merging you would include the root tag multiple times.

n

I think that it would be very hard (if possible) to do that in a batch shell, even using a powerful shell and commands like those in Linux/Unix (find, grep, etc).

n

I would use a simple program (say, VBA) to do that.

n

edit: Ive found that in Excel you can import multiple xml files. You have to go to the Develop tab (show it if its hidden). Then in the XML group, choose Import and select multiple XML files. That should work.

Leave a Reply

Your email address will not be published.