Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Problems with default twig handler in XML::Twig

by Zoogie (Curate)
on Oct 14, 2001 at 04:02 UTC ( #118712=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Problems with default twig handler in XML::Twig
Select or Download Code
Re: Problems with default twig handler in XML::Twig
by mirod (Canon) on Oct 14, 2001 at 04:44 UTC

    Yep! You found a bug! It is fixed on the version of XML::Twig 3.00 that's on my site at www.xmltwig.com.

    As a general rule XML::Twig is not really impacted by various versions of Perl, except that after 5.6.0 it can use WeakRefs to gain proper garbage collection. It is impacted by versions of XML::Parser though, and I must say that if I can (if there are no problems with the expat version included in mod_perl) I tend to stick to version 2.27 as XML::Twig was written for it's API, and as it is cleaner Unicode-wise.

    BTW If you need a patch for XML::Twig 2.02 please let me know.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://118712]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2014-11-24 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (147 votes), past polls