http://qs321.pair.com?node_id=916626

Jaap has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to stop parsing once you find what you are looking for in a big XML file? My code looks like this:
use XML::SAX::ExpatXS; use WDSTreeHandler; ... my $tree = read_file("/x/y/z/aap.xml"); my $handler = WDSTreeHandler->new; my $parser = XML::SAX::ExpatXS->new(Handler => $handler); $parser->parse_string($tree);
With the WDSTreeHandler looking like so:
package WDSTreeHandler; use base qw(XML::SAX::Base); ... sub start_document { my ($self, $doc) = @_; } sub start_element { my ($self, $el) = @_; ... if ($level >= 0 && $el->{'LocalName'} =~ /folder|leaf/) { ## do some stuff and try to STOP PARSING } } sub end_element { ... } sub end_document { } 1;
How do you stop parsing?