#!/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.

In reply to Re^4: Compare 2 XML files by snehit.ar
in thread Compare 2 XML files by snehit.ar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.