satzbu has asked for the wisdom of the Perl Monks concerning the following question:
this two xml files are my inputs i want the output as1. <xml> <chapter>sathish <subchap1>sathish is good boy or not <p>sathish is a good bou</p> </subchap1> </chapter> </xml> 2.<xml> <chapter>head <subchap1>body <p>para</p> </subchap1> </chapter> </xml>
this code converts the two xml files to hash value and compare the two hash keys are same if there are same keys replace the first hash keys with second hash values what is the error and please suggest me how can i do this<xml> <head>sathish <body>sathish is good boy or not <para>sathish is a good bou</para> <//body> </head> </xml> </code. i mean the second xml file contents are replaced to the first xml file + tags please help any one how can i do this i use the code as <code> #!/usr/bin/perl -w use warnings; use strict; use XML::Simple; use Data::Dumper; my %hash; my %hash1; my $file= $ARGV[0]; my $simple = XML::Simple->new(); my $hash = $simple->XMLin($file); my $file1= $ARGV[1]; my $hash1 = $simple->XMLin($file1); print Dumper ($hash); print Dumper ($hash1); my $areEqual=1; if(keys %hash == keys %hash1) { foreach my $key(keys %hash) { if(!exists $hash1{$key}) { $areEqual=0; last; } } } if($areEqual) { print "ARE "; } else { print "ARE NOT "; } for (keys %hash) { $hash{$_} = $hash1{$_} if exists $hash1{$_}; } print Dumper ($hash); print Dumper($hash1); $simple->XMLout($hash, KeepRoot => 1, OutputFile => 'pets.xml', XMLDecl => "<?xml version='1.0'?>", ); $simple->XMLout($hash1, KeepRoot => 1, OutputFile => 'pets1.xml', XMLDecl => "<?xml version='1.0'?>", );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: xml tag mapping?
by toolic (Bishop) on Mar 24, 2010 at 16:49 UTC | |
|
Re: xml tag mapping?
by ikegami (Patriarch) on Mar 24, 2010 at 17:27 UTC | |
|
Re: xml tag mapping?
by grantm (Parson) on Mar 25, 2010 at 20:13 UTC |