root/main/trunk/release-kits/shared/linux/XML-Parser/64-bit/perl-5.14/XML/Parser/Style/Stream.pm @ 29197

Revision 29197, 3.4 KB (checked in by ak19, 5 years ago)

Further XML::Parser binary files (for 64-bit linux, perl 5.14)

Line 
1# $Id: Stream.pm,v 1.1 2003-07-27 16:07:49 matt Exp $
2
3package XML::Parser::Style::Stream;
4use strict;
5
6# This style invented by Tim Bray <tbray@textuality.com>
7
8sub Init {
9  no strict 'refs';
10  my $expat = shift;
11  $expat->{Text} = '';
12  my $sub = $expat->{Pkg} ."::StartDocument";
13  &$sub($expat)
14    if defined(&$sub);
15}
16
17sub Start {
18  no strict 'refs';
19  my $expat = shift;
20  my $type = shift;
21 
22  doText($expat);
23  $_ = "<$type";
24 
25  %_ = @_;
26  while (@_) {
27    $_ .= ' ' . shift() . '="' . shift() . '"';
28  }
29  $_ .= '>';
30 
31  my $sub = $expat->{Pkg} . "::StartTag";
32  if (defined(&$sub)) {
33    &$sub($expat, $type);
34  } else {
35    print;
36  }
37}
38
39sub End {
40  no strict 'refs';
41  my $expat = shift;
42  my $type = shift;
43 
44  # Set right context for Text handler
45  push(@{$expat->{Context}}, $type);
46  doText($expat);
47  pop(@{$expat->{Context}});
48 
49  $_ = "</$type>";
50 
51  my $sub = $expat->{Pkg} . "::EndTag";
52  if (defined(&$sub)) {
53    &$sub($expat, $type);
54  } else {
55    print;
56  }
57}
58
59sub Char {
60  my $expat = shift;
61  $expat->{Text} .= shift;
62}
63
64sub Proc {
65  no strict 'refs';
66  my $expat = shift;
67  my $target = shift;
68  my $text = shift;
69 
70  doText($expat);
71
72  $_ = "<?$target $text?>";
73 
74  my $sub = $expat->{Pkg} . "::PI";
75  if (defined(&$sub)) {
76    &$sub($expat, $target, $text);
77  } else {
78    print;
79  }
80}
81
82sub Final {
83  no strict 'refs';
84  my $expat = shift;
85  my $sub = $expat->{Pkg} . "::EndDocument";
86  &$sub($expat)
87    if defined(&$sub);
88}
89
90sub doText {
91  no strict 'refs';
92  my $expat = shift;
93  $_ = $expat->{Text};
94 
95  if (length($_)) {
96    my $sub = $expat->{Pkg} . "::Text";
97    if (defined(&$sub)) {
98      &$sub($expat);
99    } else {
100      print;
101    }
102   
103    $expat->{Text} = '';
104  }
105}
106
1071;
108__END__
109
110=head1 NAME
111
112XML::Parser::Style::Stream - Stream style for XML::Parser
113
114=head1 SYNOPSIS
115
116  use XML::Parser;
117  my $p = XML::Parser->new(Style => 'Stream', Pkg => 'MySubs');
118  $p->parsefile('foo.xml');
119 
120  {
121    package MySubs;
122   
123    sub StartTag {
124      my ($e, $name) = @_;
125      # do something with start tags
126    }
127   
128    sub EndTag {
129      my ($e, $name) = @_;
130      # do something with end tags
131    }
132   
133    sub Characters {
134      my ($e, $data) = @_;
135      # do something with text nodes
136    }
137  }
138
139=head1 DESCRIPTION
140
141This style uses the Pkg option to find subs in a given package to call for each event.
142If none of the subs that this
143style looks for is there, then the effect of parsing with this style is
144to print a canonical copy of the document without comments or declarations.
145All the subs receive as their 1st parameter the Expat instance for the
146document they're parsing.
147
148It looks for the following routines:
149
150=over 4
151
152=item * StartDocument
153
154Called at the start of the parse .
155
156=item * StartTag
157
158Called for every start tag with a second parameter of the element type. The $_
159variable will contain a copy of the tag and the %_ variable will contain
160attribute values supplied for that element.
161
162=item * EndTag
163
164Called for every end tag with a second parameter of the element type. The $_
165variable will contain a copy of the end tag.
166
167=item * Text
168
169Called just before start or end tags with accumulated non-markup text in
170the $_ variable.
171
172=item * PI
173
174Called for processing instructions. The $_ variable will contain a copy of
175the PI and the target and data are sent as 2nd and 3rd parameters
176respectively.
177
178=item * EndDocument
179
180Called at conclusion of the parse.
181
182=back
183
184=cut
Note: See TracBrowser for help on using the browser.