Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Struggling with XML

by runrig (Abbot)
on Oct 05, 2012 at 16:03 UTC ( #997506=note: print w/ replies, xml ) Need Help??

in reply to Struggling with XML

Another way, w/XML::Rules:
use XML::Rules; my @rules = ( list => sub { my $dict = $_[1]{dict}; for my $d (@$dict) { print "$d->{key}: $d->{value}\n"; } return; }, dict => [ '/root' => sub { my $d = $_[1]; print "$d->{key}: $d->{value}\n" if $d->{key} eq 'status'; return; }, 'no content array', ], value => 'content', ); my $xr = XML::Rules->new( rules => \@rules ); $xr->parse($xml);
Updated to also print status. A possibly simpler way(?):
my @rules = ( "^dict" => sub { return $_[1]{key} =~ /^(?:status|subnet|gateway|netmask|data)$/; }, dict => sub { my $d = $_[1]; return if $d->{key} eq 'data'; print "$d->{key}: $d->{value}\n"; }, value => 'content', );

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2016-08-28 16:51 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (394 votes). Check out past polls.