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

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

I'm currently using XML::Twig to handle processing of XML documents, and have run into a snag regarding setting a default twig handler. We want to use the "_default_" twig handler to print a warning about unrecognized elements for development (and validation) purposes, but XML::Twig doesn't seem to be calling the "_default_" twig handler at all.

I've created a minimal test program and test XML document that illustrates the problems we're having:

#!/usr/bin/perl -w # twigtest.pl use strict; use XML::Twig; my $t = new XML::Twig( TwigHandlers => { 'download' => \&tag_download, '_default_' => \&tag__default, } ); if (!($t->safe_parsefile('test.xml'))) { warn("Error: Test XML had processing errors: $@\n"); } # Handles the <download> tag. sub tag_download { my ($t,$elt) = @_; print("Found a <download>!\n"); $t->purge(); } # Handles any unrecognized tag. sub tag__default { my ($t,$elt) = @_; print("Unrecognized tag: <".$elt->gi().">!\n"); $t->purge(); }
Here's the test XML document (named "test.xml"):
<?xml version="1.0" ?> <download> <oops/> </download>
The output from running "./twigtest.pl" is:
Found a <download>!
which seems to indicate that tag__default isn't being called by XML::Twig.

The version of Perl we're using is 5.005_03, haven't yet had a chance to try it on 5.6.1. XML::Twig version is 2.02. Am I doing something wrong? Has anybody else experienced this problem?

- Zoogie