Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by bfdi533 (Friar)
on Dec 07, 2017 at 23:07 UTC ( #1205129=note: print w/replies, xml ) Need Help??


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

Good explanation and I did some more digging and found that $_[2] is an array of the prior tags in the "stack".

So, if I do the following I can determine which item I am in and handle appropriately:

'item' => sub { my $in_item = $_[2][$#{$_[2]}]; if ($in_item eq "summary") { $hash{summary} = $_[1]->{value}; } if ($in_item eq "detail1") { $hash{detail1} = $_[1]->{value}; } if ($in_item eq "detail2") { $hash{detail2} = $_[1]->{value}; } }

This gets me what I want perfectly! Obviously my actual XMl is much more complicated than this contrived example (and I actually have an array of items in detail2 (sometimes) so this works quite well to determine what 'value' belongs to.

Thank you for the time to answer and steer me in my research to get where I need to go.

Replies are listed 'Best First'.
Re^3: XML::Rules parsing inside out?
by Anonymous Monk on Dec 08, 2017 at 01:26 UTC

    Good explanation and I did some more digging ... This gets me what I want perfectly! Obviously my actual XMl is much more complicated than this contrived example

    Why XML::Rules?

    To me this is clearly XML::Twig or xpath territory

      I've found XML::Rules pretty easy to use, so I'm not clear on why you think this is clearly XML::Twig domain.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-03-02 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (66 votes). Check out past polls.

    Notices?