Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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]
[stevieb]: whale oil beef hooked... Strawberry just implemented a JSON structured Perls Available. That fits right in with what I've done with berrybrew quite well me thinks.
[choroba]: Good morning!
[stevieb]: morning, choroba

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-02-23 03:30 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (338 votes). Check out past polls.