Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

(jcwren) Re: Merging XML

by jcwren (Prior)
on Nov 27, 2001 at 22:15 UTC ( #127853=note: print w/ replies, xml ) Need Help??


in reply to Merging XML

Without having written any code to verify this, this seems like a most excellent use of Hash::Merge and XML::Simple.

In theory, it should be something as easy as this:

use XML::Simple; use Hash::Merge; my %config1 = %{XMLin ('file1')}; my %config2 = %{XMLin ('file2')}; my %newhash; Hash::Merge::set_behavior ('RIGHT_PRECEDENT'); *newhash = merge (\%config1, \%config2); XMLout (\%newhash, outputfile => "newfile", xmldecl => 1, rootname => +'config');

While this code is theoretical, I use a variant of it for a similiar purpose, and it works flawlessly. I don't know if what you want to do can be done reliably, without using some XML module or another.

--Chris

e-mail jcwren


Comment on (jcwren) Re: Merging XML
Download Code
Replies are listed 'Best First'.
Re: (jcwren) Re: Merging XML
by artist (Parson) on Nov 27, 2001 at 22:30 UTC
    Hi,
    Making use of XML::Simple requires XML::Parser which I would like to avoid due to problems installing expat.
    Artist
Re: (jcwren) Re: Merging XML
by artist (Parson) on Nov 28, 2001 at 02:33 UTC
    Hi Chris, This works fine,
    It works great, except it duplicates instead of overwriting the things.
    ex.. If I am trying to merge same 2 files, it makes bigger file which is double the size of single file approximately
    Artist.

      I think you probably need to post the two source XML files to your scratchpad or as a follow-up to the original article. Hash::Merge has a couple of options, and a different one may need to be selected. It does merge correctly, assuming that your input XML structure is as you say it is. But without a real data set, it's impossible to tell for sure.

      --Chris

      e-mail jcwren

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://127853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-07-08 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls