in reply to Re: XPathing Up level
in thread XPathing Up level
try this code for your search
Thanks and Regards,my $xml_str = '<List> <Events WID="1"> <Event Confirmed="Y"> <Country>USA</Country> </Event> <Event Confirmed="Y"> <Country>UK</Country> </Event> <Event Confirmed="Y"> <Country>CANADA</Country> </Event> </Events> <Events WID="2"> <Event Confirmed="Y"> <Country>MEXICO</Country> </Event> <Event Confirmed="Y"> <Country>INDIA</Country> </Event> <Event Confirmed="Y"> <Country>CHINA</Country> </Event> </Events> </List>'; parse_xml($xml_str); sub parse_xml { use XML::LibXML; no warnings; my $Country = (); my @List = (); my $parser = XML::LibXML->new(); my $doc = $parser->parse_string($_[0]); foreach my $ca_isins ($doc->findnodes('/List/Events')) { my ($id) = $ca_isins->findnodes('@WID'); $widValue=$id->to_literal; my (@titleCountry) = $ca_isins->findnodes('./Event//Country'); + foreach (@titleCountry){ push (@List, ($_->to_literal, '|', $widValue, "\n")); } } print "@List"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: XPathing Up level
by mr_p (Scribe) on Dec 04, 2010 at 05:52 UTC | |
by ikegami (Patriarch) on Dec 04, 2010 at 08:22 UTC | |
|
Re^3: XPathing Up level
by Anonymous Monk on Dec 03, 2010 at 07:24 UTC |