Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / XML::SAX::Base.3pm
1 .\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.10)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 'br\}
42 .\"
43 .\" Escape single quotes in literal strings from groff's Unicode transform.
44 .ie \n(.g .ds Aq \(aq
45 .el       .ds Aq '
46 .\"
47 .\" If the F register is turned on, we'll generate index entries on stderr for
48 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49 .\" entries marked with X<> in POD.  Of course, you'll have to process the
50 .\" output yourself in some meaningful fashion.
51 .ie \nF \{\
52 .    de IX
53 .    tm Index:\\$1\t\\n%\t"\\$2"
54 ..
55 .    nr % 0
56 .    rr F
57 .\}
58 .el \{\
59 .    de IX
60 ..
61 .\}
62 .\"
63 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
65 .    \" fudge factors for nroff and troff
66 .if n \{\
67 .    ds #H 0
68 .    ds #V .8m
69 .    ds #F .3m
70 .    ds #[ \f1
71 .    ds #] \fP
72 .\}
73 .if t \{\
74 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75 .    ds #V .6m
76 .    ds #F 0
77 .    ds #[ \&
78 .    ds #] \&
79 .\}
80 .    \" simple accents for nroff and troff
81 .if n \{\
82 .    ds ' \&
83 .    ds ` \&
84 .    ds ^ \&
85 .    ds , \&
86 .    ds ~ ~
87 .    ds /
88 .\}
89 .if t \{\
90 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96 .\}
97 .    \" troff and (daisy-wheel) nroff accents
98 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105 .ds ae a\h'-(\w'a'u*4/10)'e
106 .ds Ae A\h'-(\w'A'u*4/10)'E
107 .    \" corrections for vroff
108 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110 .    \" for low resolution devices (crt and lpr)
111 .if \n(.H>23 .if \n(.V>19 \
112 \{\
113 .    ds : e
114 .    ds 8 ss
115 .    ds o a
116 .    ds d- d\h'-1'\(ga
117 .    ds D- D\h'-1'\(hy
118 .    ds th \o'bp'
119 .    ds Th \o'LP'
120 .    ds ae ae
121 .    ds Ae AE
122 .\}
123 .rm #[ #] #H #V #F C
124 .\" ========================================================================
125 .\"
126 .IX Title "XML::SAX::Base 3"
127 .TH XML::SAX::Base 3 "2009-12-09" "perl v5.8.7" "User Contributed Perl Documentation"
128 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
129 .\" way too many mistakes in technical documents.
130 .if n .ad l
131 .nh
132 .SH "NAME"
133 XML::SAX::Base \- Base class SAX Drivers and Filters
134 .SH "SYNOPSIS"
135 .IX Header "SYNOPSIS"
136 .Vb 3
137 \&  package MyFilter;
138 \&  use XML::SAX::Base;
139 \&  @ISA = (\*(AqXML::SAX::Base\*(Aq);
140 .Ve
141 .SH "DESCRIPTION"
142 .IX Header "DESCRIPTION"
143 This module has a very simple task \- to be a base class for PerlSAX
144 drivers and filters. It's default behaviour is to pass the input directly
145 to the output unchanged. It can be useful to use this module as a base class
146 so you don't have to, for example, implement the \fIcharacters()\fR callback.
147 .PP
148 The main advantages that it provides are easy dispatching of events the right
149 way (ie it takes care for you of checking that the handler has implemented
150 that method, or has defined an \s-1AUTOLOAD\s0), and the guarantee that filters
151 will pass along events that they aren't implementing to handlers downstream
152 that might nevertheless be interested in them.
153 .SH "WRITING SAX DRIVERS AND FILTERS"
154 .IX Header "WRITING SAX DRIVERS AND FILTERS"
155 Writing \s-1SAX\s0 Filters is tremendously easy: all you need to do is
156 inherit from this module, and define the events you want to handle. A
157 more detailed explanation can be found at
158 http://www.xml.com/pub/a/2001/10/10/sax\-filters.html.
159 .PP
160 Writing Drivers is equally simple. The one thing you need to pay
161 attention to is \fB\s-1NOT\s0\fR to call events yourself (this applies to Filters
162 as well). For instance:
163 .PP
164 .Vb 2
165 \&  package MyFilter;
166 \&  use base qw(XML::SAX::Base);
167 \&
168 \&  sub start_element {
169 \&    my $self = shift;
170 \&    my $data = shift;
171 \&    # do something
172 \&    $self\->{Handler}\->start_element($data); # BAD
173 \&  }
174 .Ve
175 .PP
176 The above example works well as precisely that: an example. But it has
177 several faults: 1) it doesn't test to see whether the handler defines
178 start_element. Perhaps it doesn't want to see that event, in which
179 case you shouldn't throw it (otherwise it'll die). 2) it doesn't check
180 ContentHandler and then Handler (ie it doesn't look to see that the
181 user hasn't requested events on a specific handler, and if not on the
182 default one), 3) if it did check all that, not only would the code be
183 cumbersome (see this module's source to get an idea) but it would also
184 probably have to check for a DocumentHandler (in case this were \s-1SAX1\s0)
185 and for AUTOLOADs potentially defined in all these packages. As you can
186 tell, that would be fairly painful. Instead of going through that,
187 simply remember to use code similar to the following instead:
188 .PP
189 .Vb 2
190 \&  package MyFilter;
191 \&  use base qw(XML::SAX::Base);
192 \&
193 \&  sub start_element {
194 \&    my $self = shift;
195 \&    my $data = shift;
196 \&    # do something to filter
197 \&    $self\->SUPER::start_element($data); # GOOD (and easy) !
198 \&  }
199 .Ve
200 .PP
201 This way, once you've done your job you hand the ball back to
202 XML::SAX::Base and it takes care of all those problems for you!
203 .PP
204 Note that the above example doesn't apply to filters only, drivers
205 will benefit from the exact same feature.
206 .SH "METHODS"
207 .IX Header "METHODS"
208 A number of methods are defined within this class for the purpose of
209 inheritance. Some probably don't need to be overridden (eg parse_file)
210 but some clearly should be (eg parse). Options for these methods are
211 described in the PerlSAX2 specification available from
212 http://cvs.sourceforge.net/cgi\-bin/viewcvs.cgi/~checkout~/perl\-xml/libxml\-perl/doc/sax\-2.0.html?rev=HEAD&content\-type=text/html.
213 .IP "\(bu" 4
214 parse
215 .Sp
216 The parse method is the main entry point to parsing documents. Internally
217 the parse method will detect what type of \*(L"thing\*(R" you are parsing, and
218 call the appropriate method in your implementation class. Here is the
219 mapping table of what is in the Source options (see the Perl \s-1SAX\s0 2.0
220 specification for the meaning of these values):
221 .Sp
222 .Vb 6
223 \&  Source Contains           parse() calls
224 \&  ===============           =============
225 \&  CharacterStream (*)       _parse_characterstream($stream, $options)
226 \&  ByteStream                _parse_bytestream($stream, $options)
227 \&  String                    _parse_string($string, $options)
228 \&  SystemId                  _parse_systemid($string, $options)
229 .Ve
230 .Sp
231 However note that these methods may not be sensible if your driver class 
232 is not for parsing \s-1XML\s0. An example might be a \s-1DBI\s0 driver that generates
233 \&\s-1XML/SAX\s0 from a database table. If that is the case, you likely want to
234 write your own \fIparse()\fR method.
235 .Sp
236 Also note that the Source may contain both a PublicId entry, and an
237 Encoding entry. To get at these, examine \f(CW$options\fR\->{Source} as passed
238 to your method.
239 .Sp
240 (*) A CharacterStream is a filehandle that does not need any encoding
241 translation done on it. This is implemented as a regular filehandle
242 and only works under Perl 5.7.2 or higher using PerlIO. To get a single
243 character, or number of characters from it, use the perl core \fIread()\fR
244 function. To get a single byte from it (or number of bytes), you can 
245 use \fIsysread()\fR. The encoding of the stream should be in the Encoding
246 entry for the Source.
247 .IP "\(bu" 4
248 parse_file, parse_uri, parse_string
249 .Sp
250 These are all convenience variations on \fIparse()\fR, and in fact simply
251 set up the options before calling it. You probably don't need to
252 override these.
253 .IP "\(bu" 4
254 get_options
255 .Sp
256 This is a convenience method to get options in \s-1SAX2\s0 style, or more
257 generically either as hashes or as hashrefs (it returns a hashref).
258 You will probably want to use this method in your own implementations
259 of \fIparse()\fR and of \fInew()\fR.
260 .IP "\(bu" 4
261 get_feature, set_feature
262 .Sp
263 These simply get and set features, and throw the
264 appropriate exceptions defined in the specification if need be.
265 .Sp
266 If your subclass defines features not defined in this one,
267 then you should override these methods in such a way that they check for
268 your features first, and then call the base class's methods
269 for features not defined by your class. An example would be:
270 .Sp
271 .Vb 10
272 \&  sub get_feature {
273 \&      my $self = shift;
274 \&      my $feat = shift;
275 \&      if (exists $MY_FEATURES{$feat}) {
276 \&          # handle the feature in various ways
277 \&      }
278 \&      else {
279 \&          return $self\->SUPER::get_feature($feat);
280 \&      }
281 \&  }
282 .Ve
283 .Sp
284 Currently this part is unimplemented.
285 .IP "\(bu" 4
286 set_handler
287 .Sp
288 This method takes a handler type (Handler, ContentHandler, etc.) and a
289 handler object as arguments, and changes the current handler for that
290 handler type, while taking care of resetting the internal state that 
291 needs to be reset. This allows one to change a handler during parse
292 without running into problems (changing it on the parser object 
293 directly will most likely cause trouble).
294 .IP "\(bu" 4
295 set_document_handler, set_content_handler, set_dtd_handler, set_lexical_handler, set_decl_handler, set_error_handler, set_entity_resolver
296 .Sp
297 These are just simple wrappers around the former method, and take a
298 handler object as their argument. Internally they simply call
299 set_handler with the correct arguments.
300 .IP "\(bu" 4
301 get_handler
302 .Sp
303 The inverse of set_handler, this method takes a an optional string containing a handler type (DTDHandler, 
304 ContentHandler, etc. 'Handler' is used if no type is passed). It returns a reference to the object that implements
305 that that class, or undef if that handler type is not set for the current driver/filter.
306 .IP "\(bu" 4
307 get_document_handler, get_content_handler, get_dtd_handler, get_lexical_handler, get_decl_handler, 
308 get_error_handler, get_entity_resolver
309 .Sp
310 These are just simple wrappers around the \fIget_handler()\fR method, and take no arguments. Internally 
311 they simply call get_handler with the correct handler type name.
312 .PP
313 It would be rather useless to describe all the methods that this
314 module implements here. They are all the methods supported in \s-1SAX1\s0 and
315 \&\s-1SAX2\s0. In case your memory is a little short, here is a list. The
316 apparent duplicates are there so that both versions of \s-1SAX\s0 can be
317 supported.
318 .IP "\(bu" 4
319 start_document
320 .IP "\(bu" 4
321 end_document
322 .IP "\(bu" 4
323 start_element
324 .IP "\(bu" 4
325 start_document
326 .IP "\(bu" 4
327 end_document
328 .IP "\(bu" 4
329 start_element
330 .IP "\(bu" 4
331 end_element
332 .IP "\(bu" 4
333 characters
334 .IP "\(bu" 4
335 processing_instruction
336 .IP "\(bu" 4
337 ignorable_whitespace
338 .IP "\(bu" 4
339 set_document_locator
340 .IP "\(bu" 4
341 start_prefix_mapping
342 .IP "\(bu" 4
343 end_prefix_mapping
344 .IP "\(bu" 4
345 skipped_entity
346 .IP "\(bu" 4
347 start_cdata
348 .IP "\(bu" 4
349 end_cdata
350 .IP "\(bu" 4
351 comment
352 .IP "\(bu" 4
353 entity_reference
354 .IP "\(bu" 4
355 notation_decl
356 .IP "\(bu" 4
357 unparsed_entity_decl
358 .IP "\(bu" 4
359 element_decl
360 .IP "\(bu" 4
361 attlist_decl
362 .IP "\(bu" 4
363 doctype_decl
364 .IP "\(bu" 4
365 xml_decl
366 .IP "\(bu" 4
367 entity_decl
368 .IP "\(bu" 4
369 attribute_decl
370 .IP "\(bu" 4
371 internal_entity_decl
372 .IP "\(bu" 4
373 external_entity_decl
374 .IP "\(bu" 4
375 resolve_entity
376 .IP "\(bu" 4
377 start_dtd
378 .IP "\(bu" 4
379 end_dtd
380 .IP "\(bu" 4
381 start_entity
382 .IP "\(bu" 4
383 end_entity
384 .IP "\(bu" 4
385 warning
386 .IP "\(bu" 4
387 error
388 .IP "\(bu" 4
389 fatal_error
390 .SH "TODO"
391 .IX Header "TODO"
392 .Vb 3
393 \&  \- more tests
394 \&  \- conform to the "SAX Filters" and "Java and DOM compatibility"
395 \&    sections of the SAX2 document.
396 .Ve
397 .SH "AUTHOR"
398 .IX Header "AUTHOR"
399 Kip Hampton (khampton@totalcinema.com) did most of the work, after porting
400 it from XML::Filter::Base.
401 .PP
402 Robin Berjon (robin@knowscape.com) pitched in with patches to make it 
403 usable as a base for drivers as well as filters, along with other patches.
404 .PP
405 Matt Sergeant (matt@sergeant.org) wrote the original XML::Filter::Base,
406 and patched a few things here and there, and imported it into
407 the \s-1XML::SAX\s0 distribution.
408 .SH "SEE ALSO"
409 .IX Header "SEE ALSO"
410 \&\s-1XML::SAX\s0