Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205127]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-11-30 18:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found