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