in reply to Re^2: trying to understand xml::twig and also trying to learn how to extract attribute
in thread trying to understand xml::twig and also trying to learn how to extract attribute
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use XML::Twig; my $xmlStr = <<XML; <config> <one id="msn" type="shopping"> <traffic> <daily value="on" /> <weekly value="off" /> <monthly value="off" /> </traffic> </one> <one id="movies" type="entertainment"> <traffic> <daily value="on" /> <weekly value="off" /> <monthly value="on" /> </traffic> </one> <one id="espn" type="sports"> <traffic> <daily value="on" /> <weekly value="on" /> <monthly value="on" /> <hyper value="true" /> </traffic> </one> </config> XML my @ids; my $t = XML::Twig->new(); $t->parse($xmlStr); for my $one ( ($t->root()->children('one') ) { for my $month ( ($t->root()->children('monthly') ) { if ( $momth->att('value') eq 'on' ) { push @ids, $one->att('id'); } } } print Dumper(\@ids);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: trying to understand xml::twig and also trying to learn how to extract attribute
by GrandFather (Saint) on Nov 05, 2008 at 20:18 UTC | |
|
Re^4: trying to understand xml::twig and also trying to learn how to extract attribute
by toolic (Bishop) on Nov 05, 2008 at 21:02 UTC | |
by convenientstore (Pilgrim) on Nov 05, 2008 at 22:31 UTC | |
by convenientstore (Pilgrim) on Nov 06, 2008 at 15:03 UTC |