http://www.perlmonks.org?node_id=1056688


in reply to xml join

This seems like it's not a perl question (esp. since you didn't post any code).

But, by way of a non-perl answer, I have found that it can be very useful to concatenate a bunch of xml files that use a common schema/dtd, e.g. to get a global summary of contents.

All I need is some arbitrary tag to serve as the outer-most container for the concatenated set. Sometimes the files have this at the beginning:

<?xml version="1.0"?>
(and sometimes that includes an 'encoding' attribute as well); those need to be filtered out. So the process boils down to a simple, 3-step sequence of shell commands (assuming there's one directory containing all the xml files of interest, and a separate path to use for output):
echo '<arbitrary_tag>' > outpath/combined.xml cat inpath/*.xml | fgrep -v '<?xml' >> outpath/combined.xml echo '</arbitrary_tag>' >> output/combined.xml
That also assumes that the order of file names you get from a default sort will put the files in the desired sequence (if that matters at all). If you want them in a sequence that differs from a default sort on the file names, you'll need to create a separate text file that lists the xml file names in the desired order, then pipe that list to "xargs cat" (instead of doing "cat inpath/*.xml").

That also assumes you're on a system where the unix/linux/osx/cygwin "cat", "echo", "fgrep" and "xargs" commands are available.