Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: XML::Rules parsing inside out?

by runrig (Abbot)
on Dec 07, 2017 at 22:38 UTC ( #1205127=note: print w/replies, xml ) Need Help??


in reply to Re: XML::Rules parsing inside out?
in thread XML::Rules parsing inside out?

Here's an (untested) example:
use XML::Rules; use Data::Dumper; my %tag_value; my $tag_name; my $xr = XML::Rules->new( rules => [ value => sub { $tag_value{$tag_name} = $_[1]->{_content} +], start_rules => [ 'summary,detail1,detail2' => sub { $tag_name = $_[0 +] } ], ); $xr->parse($xml) # I left the xml out print Dumper \%tag_value;
Note that this could be done much differently by passing the 'value' content up through the 'item' tag to the item's parent tag, returning the entire data structure. I'll leave that as an exercise...(Hint: use the 'content' rule for value and 'pass no content' for item tags, and 'no content by <attr>' for the other tags).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2019-04-23 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (118 votes). Check out past polls.

    Notices?