Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Need XMLTwig help

by McA (Priest)
on Aug 22, 2013 at 21:00 UTC ( #1050561=note: print w/replies, xml ) Need Help??


in reply to Re: Need XMLTwig help
in thread Need XMLTwig help

Being not the XPath expert, poj's post (++) animated to reduce my solution to the following:

#!/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[@name="cell"]'); my @cellphones_nrs = map { $_->att('number') } @nodes; say "Cellphone: $cellphones_nrs[-1]" if @cellphones_nrs;

McA

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1050561]
help
Chatterbox?
[Discipulus]: have you been fired?!?
[LanX]: remote rules, I've been offered jobs in the US with the promise to stay outside
[MidLifeXis]: Nope. Just looking around, as there are multiple culture and business changes in the area I am in.
[MidLifeXis]: not yet, anyway. Who knows. Just do my best and whatever happens happens.
[LanX]: should be even easier for you
[Discipulus]: oh well we cant afford two monks fired in a day!
[LanX]: any news from tye ' s search?
[MidLifeXis]: Ugh - who else?
[Discipulus]: so the right term is 'gired'
[Discipulus]: look at ot by karl

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2017-03-23 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (286 votes). Check out past polls.