Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2021-03-02 23:01 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (65 votes). Check out past polls.