Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by bfdi533 (Friar)
on Dec 07, 2017 at 23:07 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205129]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found