in reply to XML::Twig how to find a parent's attribute
#!perl use strict; use XML::Twig; my $xml = do { local $/; <DATA> }; my $twig = new XML::Twig( twig_handlers =>{ li => \&li}, ); $twig->parse($xml); sub li { my ($t,$elt) = @_; print $elt->text; if ( $elt->parent('p[@conref != ""]') ){ print " yes\n"; } else { print " no\n"; } } __DATA__ <xml> <p conref="hello"> <ul> <li>Bob</li> <li>Mary</li> </ul> </p> <p conref=""> <ul> <li>Tom</li> <li>Susan</li> </ul> </p> </xml>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::Twig how to find a parent's attribute
by slugger415 (Monk) on Jul 26, 2014 at 01:03 UTC | |
by poj (Abbot) on Jul 26, 2014 at 05:19 UTC |