slugger415 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, quick question I couldn't find in the documentation (or didn't understand the syntax) for XML::Twig - how do I match a parent or ancestor's attribute? For instance, I have some XML:
<p conref="hello"> <ul> <li>Bob</li> <li>Mary</li> </ul> </p>
If I'm evaluating li elements, I want to know if one of its parents has a conref attribute set. What's the syntax for that?
$elt->parent();... returns the parent, which would be ul in this case, but how do I match the ancestor that contains the attribute I'm looking for?
The doc says this about parent:
parent ($optional_condition)
Return the parent of the element, or the first ancestor matching the $optional_condition
Just not sure how to phrase the optional_condition here.
thanks, Scott
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig how to find a parent's attribute
by AppleFritter (Vicar) on Jul 25, 2014 at 18:34 UTC | |
|
Re: XML::Twig how to find a parent's attribute
by poj (Abbot) on Jul 25, 2014 at 18:55 UTC | |
by slugger415 (Monk) on Jul 26, 2014 at 01:03 UTC | |
by poj (Abbot) on Jul 26, 2014 at 05:19 UTC |