in reply to XML::Twig and handles on regex/xpath
use XML::Twig; use strict; use warnings; my $data = do {local $/; <DATA>}; my $twig = new XML::Twig(twig_handlers => { '//target[@type="aim"]/*' => sub { print $_->tag, ' ', $_->text, "\n"; }, }); $twig->parse($data); __DATA__ <result> <target type="aim"> <tag1>123</tag1> <tag2>456</tag2> <tag3>234</tag3> </target> </result>
If that pulls too many nodes, you can always filter within the sub.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::Twig and handles on regex/xpath
by Eythil (Acolyte) on Apr 28, 2011 at 08:13 UTC | |
by wind (Priest) on Apr 28, 2011 at 08:20 UTC | |
by Eythil (Acolyte) on Apr 28, 2011 at 08:25 UTC |