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


In reply to Problems with default twig handler in XML::Twig by Zoogie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.