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

Re^8: Compare 2 XML files

by snehit.ar (Beadle)
on Jul 11, 2017 at 05:29 UTC ( [id://1194771]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Compare 2 XML files
in thread Compare 2 XML files

Brilliant @Poj - Thank you for helping ...

Replies are listed 'Best First'.
Re^9: Compare 2 XML files
by snehit.ar (Beadle) on Jul 11, 2017 at 05:53 UTC
    Hello Poj, i have modify the code as below :
    my $xml = 'ApplicationList.xml'; my $xp = XML::XPath->new(filename => $xml); my $appxpath = $xp->findnodes("//application_list/application/"); my %appid = (); my %appname = (); foreach my $appnodeset ($appxpath->get_nodelist) { my $id = $xp->find('./@id',$appnodeset); my $name = $xp->find('./@name',$appnodeset); #$name = $_->string_value; s/^\s+|\s+$//g for $id,$name; $appid{$id} = {$name->string_value}; } print Dumper \%appid;
    But i am getting output as
    $VAR1 = { '1103' => { 'cccc' => undef }, '2667' => { 'bbbb' => undef }, '957' => { 'aaaa' => undef }, '1503' => { 'dddd' => undef } };
    But i want out put as
    $VAR1 = { '1103' => 'cccc', '2667' => 'bbbb', '957' => 'aaaa', '1503' => 'dddd' };

      $appid{$id} = $name->string_value; So what do you think putting braces around then contents did?
      What do braces mean?
      What happens when there isnt an even number of values inside braces?

      You need to understand the answers to those questions or you will just keep getting into trouble.

        Your question really make sense ,but i wont able to complete understand it..Sorry for that.. if i use $appid{$id} = $name->string_value getting this error Odd number of elements in anonymous hash at comparexml.pl line 21. I dont know much in perl ,just got some work todo... How i can resolve it please help ?

      Get string values before regex

      #!/usr/bin/env perl use strict; use warnings; use XML::XPath; use Data::Dumper; my $xml = 'ApplicationList.xml'; my $xp = XML::XPath->new(filename => $xml); my $appxpath = $xp->findnodes("//application_list/application"); # no + end / my %appid = (); foreach my $appnodeset ($appxpath->get_nodelist) { my $id = $xp->find('./@id',$appnodeset)->string_value; my $name = $xp->find('./@name',$appnodeset)->string_value; s/^\s+|\s+$//g for $id,$name; $appid{$id} = $name; } print Dumper \%appid;
        You are really a monk saver for me ...!!! Please do help me with 1more small query ... as per the code u shared yesterday i am getting eventid and name in diff arrays.. But Now i want out put as :

        required output

        $VAR1 = [ { 'eventid' => '957', 'name' => 'aaaa' }, { 'eventid' => '2667', 'name' => 'bbbb' }, { 'eventid' => '2667' 'name' => 'bbbb' }, { 'eventid' => '1503' 'name' => 'cccc' }, { 'eventid' => '1103' 'name' => 'dddd' }, { 'eventid' => '1503' 'name' => 'cccc' } ];
        How can i do with multiple loop :
        #!/usr/bin/env perl use strict; use warnings; use XML::XPath; use Data::Dumper; my $xml = 'ApplicationList.xml'; my $xp = XML::XPath->new(filename => $xml); my $appxpath = $xp->findnodes("//application_list/application/"); my %appid = (); foreach my $appnodeset ($appxpath->get_nodelist) { my $id = $xp->find('./@id',$appnodeset)->string_value; my $name = $xp->find('./@name',$appnodeset)->string_value; s/^\s+|\s+$//g for $id,$name; $appid{$id} = $name; } print Dumper \%appid; my $eventxml = 'events.xml'; my $evenxp = XML::XPath->new(filename => $eventxml); my $xpath = "//event/custom_attribute_list/custom_attribute[normalize- +space(name)='SLB_SSRID']/value"; my @eventrecords = (); foreach my $node ($evenxp->findnodes($xpath)) { my $ssrid = $node->string_value; $ssrid =~ s/^\s+|\s+$//g ; if ( exists $appid{$ssrid} ){ push @eventrecords, { eventid => $ssrid }; } } print Dumper \@eventrecords;
        Thanks for helping .

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found