1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
package HTTP::OAI::SAX::Text;
@ISA = qw( XML::SAX::Base );
use strict;
sub start_element
{
( my $self, my $hash, @_ ) = @_;
$self->{Data} = "";
push @{$self->{Attributes}}, $hash->{Attributes};
$self->SUPER::start_element( $hash, @_ );
}
sub characters { $_[0]->{Data} .= $_[1]->{Data} }
sub end_element
{
( my $self, my $hash, @_ ) = @_;
$hash->{Text} = $self->{Data};
$hash->{Attributes} = pop @{$self->{Attributes} || []};
# strip surrounding whitespace in leaf nodes
$hash->{Text} =~ s/^\s+//;
$hash->{Text} =~ s/\s+$//;
$self->SUPER::characters( {Data => $self->{Data}}, @_ );
$self->{Data} = "";
$self->SUPER::end_element( $hash, @_ );
}
1;
=head1 NAME
HTTP::OAI::SAX::Text - Adds Text and Attributes to end_element.
=head1 DESCRIPTION
This module adds Text and Attributes to the end_element call. This is only useful for leaf nodes (elements that don't contain any child elements).
|