Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Need XMLTwig help

by McA (Priest)
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 meditating upon the Monastery: (21)
As of 2015-07-06 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (80 votes), past polls