# $Id: Stream.pm,v 1.1 2003/07/27 16:07:49 matt Exp $
package XML
::Parser
::Style
::Stream
;
# This style invented by Tim Bray <tbray@textuality.com>
my $sub = $expat->{Pkg
} ."::StartDocument";
$_ .= ' ' . shift() . '="' . shift() . '"';
my $sub = $expat->{Pkg
} . "::StartTag";
# Set right context for Text handler
push(@
{$expat->{Context
}}, $type);
pop(@
{$expat->{Context
}});
my $sub = $expat->{Pkg
} . "::EndTag";
$_ = "<?$target $text?>";
my $sub = $expat->{Pkg
} . "::PI";
&$sub($expat, $target, $text);
my $sub = $expat->{Pkg
} . "::EndDocument";
my $sub = $expat->{Pkg
} . "::Text";
XML::Parser::Style::Stream - Stream style for XML::Parser
my $p = XML::Parser->new(Style => 'Stream', Pkg => 'MySubs');
$p->parsefile('foo.xml');
# do something with start tags
# do something with end tags
# do something with text nodes
This style uses the Pkg option to find subs in a given package to call for each event.
If none of the subs that this
style looks for is there, then the effect of parsing with this style is
to print a canonical copy of the document without comments or declarations.
All the subs receive as their 1st parameter the Expat instance for the
document they're parsing.
It looks for the following routines:
Called at the start of the parse .
Called for every start tag with a second parameter of the element type. The $_
variable will contain a copy of the tag and the %_ variable will contain
attribute values supplied for that element.
Called for every end tag with a second parameter of the element type. The $_
variable will contain a copy of the end tag.
Called just before start or end tags with accumulated non-markup text in
Called for processing instructions. The $_ variable will contain a copy of
the PI and the target and data are sent as 2nd and 3rd parameters
Called at conclusion of the parse.