in reply to Re^2: multiple for loop to extract required xml nodes
in thread multiple for loop to extract required xml nodes
Hello again snehit.ar,
Try to replicate the problem solution based on the code that you give us.
Check the and update accordingly the code before replying! We can not help you with faulty data.
#!/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)='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; __END__ $ perl test.pl $VAR1 = { '957' => 'cccc', '2667' => 'aaaa', '1250' => 'dddd', '1103' => 'bbbb' }; $VAR1 = [];
Hope this helps, BR.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: multiple for loop to extract required xml nodes
by snehit.ar (Beadle) on Jul 11, 2017 at 13:36 UTC | |
by thanos1983 (Parson) on Jul 11, 2017 at 15:03 UTC | |
by snehit.ar (Beadle) on Jul 12, 2017 at 05:18 UTC |