Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: xml join

by graff (Chancellor)
on Oct 02, 2013 at 22:35 UTC ( #1056688=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056688]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-05-25 03:54 GMT
Find Nodes?
    Voting Booth?