1 .\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.10)
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
9 .de Vb \" Begin verbatim text
14 .de Ve \" End verbatim text
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<>.
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
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
43 .\" Escape single quotes in literal strings from groff's Unicode transform.
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.
53 . tm Index:\\$1\t\\n%\t"\\$2"
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
74 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 . \" simple accents for nroff and troff
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'
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 \
124 .\" ========================================================================
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.
133 XML::SAX::Base \- Base class SAX Drivers and Filters
135 .IX Header "SYNOPSIS"
138 \& use XML::SAX::Base;
139 \& @ISA = (\*(AqXML::SAX::Base\*(Aq);
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.
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.
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:
166 \& use base qw(XML::SAX::Base);
168 \& sub start_element {
172 \& $self\->{Handler}\->start_element($data); # BAD
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:
191 \& use base qw(XML::SAX::Base);
193 \& sub start_element {
196 \& # do something to filter
197 \& $self\->SUPER::start_element($data); # GOOD (and easy) !
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!
204 Note that the above example doesn't apply to filters only, drivers
205 will benefit from the exact same feature.
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.
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):
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)
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.
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
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.
248 parse_file, parse_uri, parse_string
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
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.
261 get_feature, set_feature
263 These simply get and set features, and throw the
264 appropriate exceptions defined in the specification if need be.
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:
275 \& if (exists $MY_FEATURES{$feat}) {
276 \& # handle the feature in various ways
279 \& return $self\->SUPER::get_feature($feat);
284 Currently this part is unimplemented.
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).
295 set_document_handler, set_content_handler, set_dtd_handler, set_lexical_handler, set_decl_handler, set_error_handler, set_entity_resolver
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.
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.
307 get_document_handler, get_content_handler, get_dtd_handler, get_lexical_handler, get_decl_handler,
308 get_error_handler, get_entity_resolver
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.
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
335 processing_instruction
394 \& \- conform to the "SAX Filters" and "Java and DOM compatibility"
395 \& sections of the SAX2 document.
399 Kip Hampton (khampton@totalcinema.com) did most of the work, after porting
400 it from XML::Filter::Base.
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.
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.
409 .IX Header "SEE ALSO"