Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Compare 2 XML files

by Corion (Patriarch)
on Jul 10, 2017 at 10:42 UTC ( [id://1194675]=note: print w/replies, xml ) Need Help??


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

The first thing would be to actually extract your $ssrids from the XML and print them.

Then, extract the system IDs from the other XML and print those.

After you have convinced yourself that you can extract the correct values, apply the hint of how to find matching elements between two lists.

Maybe you need to take a step back and consider whether/how you can actually extract the data you need.

Replies are listed 'Best First'.
Re^4: Compare 2 XML files
by snehit.ar (Beadle) on Jul 10, 2017 at 11:22 UTC
    #!/usr/bin/env perl use strict; use warnings; use XML::XPath; use Data::Dumper; use List::Compare; my @records; my @eventrecords; my $eventxml = 'events.xml'; my $evenxp = XML::XPath->new(filename => $eventxml); my $evennodeset = $evenxp->findnodes('//event'); foreach my $evennode ($evennodeset->get_nodelist) { my $evenssrid = $evenxp->find("./custom_attribute_list/custom_ +attribute[normalize-space(name)='SLB_SSRID']/value", $evennode); s/^\s+|\s+$//g for $evenssrid; push @eventrecords, {eventid => $evenssrid}; } print Dumper \@eventrecords; my $xml = 'ApplicationList.xml'; my $xp = XML::XPath->new(filename => $xml); #my $nodeset = $xp->findnodes('//application_list'); for ($xp->findnodes('/application_list/application/@id') ) { my $appid = $_->string_value; $appid =~ s/^\s+|\s+$//g; push @records, {appid => $appid}; } print Dumper \@records; #if ( scalar List::Compare->new(\@records, \@eventrecords)->get_in +tersection ) { # print "The arrays are the same"; #print Dumper @eventrecords; #}

    C:\SLB\Dashboard\Perl>perl testperl $VAR1 = [ { 'eventid' => '957' }, { 'eventid' => '2667' }, ]; $VAR1 = [ { 'appid' => '957' }, { 'appid' => '975' } ];

    HOW TO GET ONLY ID PRESENT IN BOTH THE LIST AND NOT ALL THE RECORDS.

      Now is the moment when you refer to perlfaq4 to get the "intersection of two arrays", as I already told you.

      Maybe we are talking past each other here. This is not a code writing service. You are expected to write the code yourself. I will help you by pointing you to the resources you need to write your code for your work, but you will have to do the work yourself.

        I have gone through the perlfaq4 ,but I am really struggling to get the correct logic to compare two array reference and only display matching records... Its also says use of Hash, so do i need to change Hash ...as im already having array of hash.. please correct me ..
        #!/usr/bin/env perl use strict; use warnings; use XML::XPath; use Data::Dumper; my @records; my @eventrecords; my $eventxml = 'events.xml'; my $evenxp = XML::XPath->new(filename => $eventxml); my $evennodeset = $evenxp->findnodes('//event'); my $xml = 'ApplicationList.xml'; my $xp = XML::XPath->new(filename => $xml); my $nodeset = $xp->findnodes('//application_list'); foreach my $evennode ($evennodeset->get_nodelist) { my $evenssrid = $evenxp->find("./custom_attribute_list/custom_ +attribute[normalize-space(name)='SSRID']/value", $evennode); s/^\s+|\s+$//g for $evenssrid; push @eventrecords, {eventid => $evenssrid}; } print Dumper \@eventrecords; foreach ($xp->findnodes('/application_list/application/@id') ) { my $appid = $_->string_value; $appid =~ s/^\s+|\s+$//g; push @records, {appid => $appid }; } print Dumper \@records;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 14:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found