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

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dears I would like to merge few xml file in a simple way.
xml file 1 <head> <t> 1 </t> <t> 15 </t> <t> 17 </t> </head> xml file 2 <head> <t> 26 </t> <t> 19 </t> <t> 0 </t> </head> merged file: <head> <t> 1 </t> <t> 15 </t> <t> 17 </t> <t> 26 </t> <t> 19 </t> <t> 0 </t> </head>
which method is the fastest and easier? which xml module would be suggested?

Replies are listed 'Best First'.
Re: merging XML file
by moritz (Cardinal) on Apr 04, 2009 at 14:23 UTC
    Please see Concatenating XML files, I found the answers quite helpful.

    It won't get you there to 100%, but it'll show you how similar things are done with various XML modules.

Re: merging XML file
by linuxer (Curate) on Apr 04, 2009 at 16:07 UTC

    My CPAN search for xml merge revealed a module XML::Merge. Maybe that can be helpful in your case?

Re: merging XML file
by Bloodnok (Vicar) on Apr 04, 2009 at 15:50 UTC
    moritzs suggestion apart (I haven't yet been to have a look), it looks (from slightly sparse evidence) like you want a simple merge of 2 (or maybe more) XML files, so why not ...
    1. Read each file into its own hash (using XMLin() from XML::Simple,
    2. Merge all the input hashes
    3. Finally, write the resultant hash using XMLout() (again from XML::Simple).
    Assuming, of course, that the combined size of the input XML files isn't huge (and thus likely to cause the process to run out of memory).

    A user level that continues to overstate my experience :-))