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

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', );


Comment on Re: Struggling with XML
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-08-02 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls