Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: multiple for loop to extract required xml nodes

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


in reply to Re: multiple for loop to extract required xml nodes
in thread multiple for loop to extract required xml nodes

try this my $xpath = "//event/custom_attribute_list/custom_attribute[normalize-space(name)='SSRID']/value"; instead of SLB_SSRID

Replies are listed 'Best First'.
Re^3: multiple for loop to extract required xml nodes
by thanos1983 (Parson) on Jul 11, 2017 at 12:46 UTC

    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.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      Hello thanos1983, Sorry for inaccurate data and thanks for your time to help. The needful is done know .

        Hello snehit.ar,

        I am sorry I do not understand what you mean by "The needful is done know".

        You mean that the problem is resolved? I do not see an update on your question path, so I assume that this is what you meant?

        If not, run the sample of code that you provide us with some valid data, provide us all this information and we will be more than happy to assist you.

        Hope this helps, BR.

        Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found