snehit.ar has asked for the wisdom of the Perl Monks concerning the following question:
---application.xml
-----Events.xml<application_list> <application id="2667" external-id="EAR-AA-2667" name="aaaa"></applica +tion> <application id="1103" external-id="EAR-AA-1103" name="bbbb"></applica +tion> <application id="957" external-id="EAR-AA-957" name="cccc"></applicati +on> <application id="1250" external-id="EAR-AA-1250" name="dddd"></applica +tion> </application_list>
<event_list> <event> <name> Incident</name> <value> INC0004532345324</value> <name> SSRID</name> <value> 957</value> </event> </event_list>
---Perl code
Thanks in advance !#!/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_int +ersection ) { print "The arrays are the same"; #print Dumper @eventrecords; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare 2 XML files
by choroba (Cardinal) on Jul 10, 2017 at 11:49 UTC | |
|
Re: Compare 2 XML files
by Corion (Patriarch) on Jul 10, 2017 at 07:28 UTC | |
by snehit.ar (Beadle) on Jul 10, 2017 at 10:02 UTC | |
by snehit.ar (Beadle) on Jul 10, 2017 at 10:05 UTC | |
by Corion (Patriarch) on Jul 10, 2017 at 10:42 UTC | |
by snehit.ar (Beadle) on Jul 10, 2017 at 11:22 UTC | |
by Corion (Patriarch) on Jul 10, 2017 at 11:55 UTC | |
| |
|
Re: Compare 2 XML files
by karlgoethebier (Abbot) on Jul 10, 2017 at 07:40 UTC |