How to combine multiple XML files in a series of ZIP files

To Kin Hang
1 min readNov 7, 2021

Using CMD

TLDR

echo ^<dummynode^> > result.xml
unzip -p *.zip path/to/result.xml >> result.xml
echo ^</dummynode^> >> result.xml

Background

Recently my company adopted an e-form system. However, each of the individual submissions came back in a zipped XLM file. Even worst, all XML got an identical name.

The end-users wish processing the return themselves with Excel in a batch instead of import them one by one, so they asked our help.

File structure of the ZIP files

form-return-<datetimehash>.zip
|- return.xml

Analysis

Obviously, the simplest handling would be unzip and pipe the zipped XML files in a single XML file.

unzip -p *.zip path/to/result.xml > result.xml

However, the result.xml at this stage has multiple top elements, which Excel (and most of XML parsers) considers that as an invalid XML file.

To cope with that, simple wrapping the result in a dummy node. That comes the commands at the top.

Conclusion

Saving the script as a bat file will become a one-click solution for users. It should also work in *inx with minor tweaks.

--

--