SYNOPSIS

 use XML::Handler::Subs;

 package MyHandlers;
 use vars qw{ @ISA };

 sub s_NAME { my ($self, $element) = @_ };
 sub e_NAME { my ($self, $element) = @_ };

 $self->{Names};    # an array of names
 $self->{Nodes};    # an array of $element nodes

 $handler = MyHandlers->new();
 $self->in_element($name);
 $self->within_element($name);

DESCRIPTION

\*(C`XML::Handler::Subs\*(C' is a base class for PerlSAX handlers. \*(C`XML::Handler::Subs\*(C' is subclassed to implement complete behavior and to add element-specific handling.

Each time an element starts, a method by that name prefixed with `s_' is called with the element to be processed. Each time an element ends, a method with that name prefixed with `e_' is called. Any special characters in the element name are replaced by underscores.

Subclassing XML::Handler::Subs in this way is similar to XML::Parser's Subs style.

XML::Handler::Subs maintains a stack of element names, `\*(C`$self-\*(C'{Names}', and a stack of element nodes, `\*(C`$self-\*(C'{Nodes}>' that can be used by subclasses. The current element is pushed on the stacks before calling an element-name start method and popped off the stacks after calling the element-name end method. The `\*(C`in_element()\*(C'' and `\*(C`within_element()\*(C'' calls use these stacks.

If the subclass implements `\*(C`start_document()\*(C'', `\*(C`end_document()\*(C'', `\*(C`start_element()\*(C'', and `\*(C`end_element()\*(C'', be sure to use `\*(C`SUPER::\*(C'' to call the the superclass methods also. See perlobj\|(1) for details on \s-1SUPER::\s0. `\*(C`SUPER::start_element()\*(C'' and `\*(C`SUPER::end_element()\*(C'' return 1 if an element-name method is called, they return 0 if no method was called.

XML::Handler::Subs does not implement any other PerlSAX handlers.

XML::Handler::Subs supports the following methods:

new( \s-1OPTIONS\s0 )

A basic `\*(C`new()\*(C'' method. `\*(C`new()\*(C'' takes a list of key, value pairs or a hash and creates and returns a hash with those options; the hash is blessed into the subclass.

in_element($name)

Returns true if `$name' is equal to the name of the innermost currently opened element.

within_element($name)

Returns the number of times the `$name' appears in Names.

AUTHOR

Ken MacLeod, [email protected]

RELATED TO XML::Handler::Subs…

perl\|(1), PerlSAX.pod\|(3)