Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Need XMLTwig help

by McA (Curate)
on Aug 22, 2013 at 20:07 UTC ( #1050559=note: print w/ replies, xml ) Need Help??


in reply to Need XMLTwig help

Probably something like that:

#!/usr/bin/env perl use 5.010; use strict; use warnings; use Data::Dumper; use local::lib 'lib'; use XML::Twig; my $string = <<EOF; <Person name="Brian"> <Phones> <Phone name="cell" number="5551112233" /> <Phone name="cell" number="5557778899" /> <Phone name="home" number="5554441122" /> </Phones> </Person> EOF my $twig = XML::Twig->new; $twig->parse($string); my @nodes = $twig->findnodes('/Person/Phones/Phone'); my @cellphones_nrs = map { $_->att('number') } grep { defined $_->att('name') && $_->att('name') eq 'cell' && defined $_->att('number') } @nodes; say "Cellphone: $cellphones_nrs[-1]" if @cellphones_nrs;

Best regards
McA


Comment on Re: Need XMLTwig help
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-01 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls