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

I'm having trouble calling the superclass in myHandler. If I comment out my start_element() Things work as I would expect, (i.e. the elements are pushed into the stack) but when I implement my start_element() I don't seem to be calling the superclass method (i.e. $self->{Names} is empty)

From the XML::Handler::Subs docs:
If the subclass implements `start_document()', `end_document()', `start_element()', and `end_element()', be sure to use `SUPER::' to call the the superclass methods also.

#!/usr/bin/perl use warnings; use strict; use XML::Parser::PerlSAX; use XML::Handler::Subs; my $parser = XML::Parser::PerlSAX->new(Handler => myHandler->new() ); $parser->parse(Source => {String => '<foo><bar>f*** it</bar></foo>'}); package myHandler; use base('XML::Handler::Subs'); sub new { my $type = shift; my $self = {@_}; return bless($self,$type); } sub start_element { my ($self,$properties) = @_; $self->SUPER::start_element(); print "started ",$properties->{Name},"\n"; } sub characters { my ($self, $properties) = @_; my $data = $properties->{Data}; print "$data\n"; print "These are the Names; ",@{$self->{Names}},"\n"; }

Replies are listed 'Best First'.
•Re: Using SUPER:: with XML::Handler::Subs?
by merlyn (Sage) on Nov 16, 2004 at 23:31 UTC
      Yep, thats what I was missing. Thanks.