Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

batch-file

I have a directory of 86 xml files with the same columns and formatting that I need to combine into one large xml file. I am very inexperienced with batch files, and my first attempt was to simply append one file text onto the next using...

FOR %%i IN (directory\*.001) DO type %%i >> directory\combo_file.001

Unfortunately, this creates a Parse error when i try to open it in excel. I would imagine that this is because many fields and tags are repeated. Does anyone know how I might be able to achieve this? I only need to open this file in excel, so I would be open to converting files to CSV, if that was an option.

Any help is much appreciated, thanks!

like image 743
tob88 Avatar asked Feb 21 '12 12:02

tob88


Video Answer


2 Answers

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

copy *.xml new.xml

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

like image 187
Bhaskar Avatar answered Oct 02 '22 20:10

Bhaskar


Here's 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>").

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.

--CombineXML.bat--
@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
like image 41
mxmoss Avatar answered Oct 02 '22 21:10

mxmoss