in reply to Ignore elements using twig module
I'm not sure how much the following will speed up processing, but it does filter the unwanted elements:
use strict; use warnings; use XML::Twig; my $xml = <<XML; <doc> <data> <type>xxx</type> <vars>a</vars> </data> <data> <type>yyy</type> <vars>b</vars> </data> </doc> XML my $root = XML::Twig->new (twig_handlers => {data => \&handler}); $root->parse ($xml); sub handler { my $elt = $_; return if $elt->children (\&badType); print "Handling ", $elt->text (), "\n"; } sub badType { return $_->text () =~ /^yyy/; }
Prints:
Handling xxxa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ignore elements using twig module
by basalto (Beadle) on Feb 23, 2008 at 11:38 UTC | |
by basalto (Beadle) on Mar 02, 2008 at 00:32 UTC |