Initial revision
[TestXSLT.git] / libexpat / doc / reference.html
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html>
5 <head>
6 <!-- Copyright 1999,2000 Clark Cooper <coopercc@netheaven.com>
7      All rights reserved.
8      This is free software. You may distribute or modify according to
9      the terms of the MIT/X License -->
10   <title>Expat XML Parser</title>
11   <meta name="author" content="Clark Cooper, coopercc@netheaven.com" />
12   <meta http-equiv="Content-Style-Type" content="text/css" />
13   <link href="style.css" rel="stylesheet" type="text/css" />
14 </head>
15 <body>
16 <h1>Expat XML Parser</h1>
17
18 <p>Expat is a library, written in C, for parsing XML documents. It's
19 the underlying XML parser for the open source Mozilla project, Perl's
20 <code>XML::Parser</code>, Python's <code>xml.parsers.expat</code>, and
21 other open-source XML parsers.</p>
22
23 <p>This library is the creation of James Clark, who's also given us
24 groff (an nroff look-alike), Jade (an implemention of ISO's DSSSL
25 stylesheet language for SGML), XP (a Java XML parser package), XT (a
26 Java XSL engine).  James was also the technical lead on the XML
27 Working Group at W3C that produced the XML specification.</p>
28
29 <p>This is free software, licensed under the <a
30 href="../COPYING">MIT/X Consortium license</a>. You may download it
31 from <a href="http://www.libexpat.org/">the Expat home page</a>.
32 </p>
33
34 <p>The bulk of this document was originally commissioned as an article by
35 <a href="http://www.xml.com/">XML.com</a>. They graciously allowed
36 Clark Cooper to retain copyright and to distribute it with Expat.</p>
37
38 <hr />
39 <h2>Table of Contents</h2>
40 <ul>
41   <li><a href="#overview">Overview</a></li>
42   <li><a href="#building">Building and Installing</a></li>
43   <li><a href="#using">Using Expat</a></li>
44   <li><a href="#reference">Reference</a>
45   <ul>
46     <li><a href="#creation">Parser Creation Functions</a>
47     <ul>
48       <li><a href="#XML_ParserCreate">XML_ParserCreate</a></li>
49       <li><a href="#XML_ParserCreateNS">XML_ParserCreateNS</a></li>
50       <li><a href="#XML_ParserCreate_MM">XML_ParserCreate_MM</a></li>
51       <li><a href="#XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</a></li>
52       <li><a href="#XML_ParserFree">XML_ParserFree</a></li>
53       <li><a href="#XML_ParserReset">XML_ParserReset</a></li>
54     </ul>
55     </li>
56     <li><a href="#parsing">Parsing Functions</a>
57     <ul>
58       <li><a href="#XML_Parse">XML_Parse</a></li>
59       <li><a href="#XML_ParseBuffer">XML_ParseBuffer</a></li>
60       <li><a href="#XML_GetBuffer">XML_GetBuffer</a></li>
61     </ul>
62     </li>
63     <li><a href="#setting">Handler Setting Functions</a>
64     <ul>
65       <li><a href="#XML_SetStartElementHandler">XML_SetStartElementHandler</a></li>
66       <li><a href="#XML_SetEndElementHandler">XML_SetEndElementHandler</a></li>
67       <li><a href="#XML_SetElementHandler">XML_SetElementHandler</a></li>
68       <li><a href="#XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</a></li>
69       <li><a href="#XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</a></li>
70       <li><a href="#XML_SetCommentHandler">XML_SetCommentHandler</a></li>
71       <li><a href="#XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</a></li>
72       <li><a href="#XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</a></li>
73       <li><a href="#XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</a></li>
74       <li><a href="#XML_SetDefaultHandler">XML_SetDefaultHandler</a></li>
75       <li><a href="#XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</a></li>
76       <li><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></li>
77       <li><a href="#XML_SetExternalEntityRefHandlerArg">XML_SetExternalEntityRefHandlerArg</a></li>
78       <li><a href="#XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</a></li>
79       <li><a href="#XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</a></li>
80       <li><a href="#XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</a></li>
81       <li><a href="#XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</a></li>
82       <li><a href="#XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</a></li>
83       <li><a href="#XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</a></li>                 
84       <li><a href="#XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</a></li>
85       <li><a href="#XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</a></li>
86       <li><a href="#XML_SetDoctypeDeclHandler">XML_SetDoctypeDeclHandler</a></li>
87       <li><a href="#XML_SetElementDeclHandler">XML_SetElementDeclHandler</a></li>
88       <li><a href="#XML_SetAttlistDeclHandler">XML_SetAttlistDeclHandler</a></li>
89       <li><a href="#XML_SetEntityDeclHandler">XML_SetEntityDeclHandler</a></li>
90       <li><a href="#XML_SetUnparsedEntityDeclHandler">XML_SetUnparsedEntityDeclHandler</a></li>
91       <li><a href="#XML_SetNotationDeclHandler">XML_SetNotationDeclHandler</a></li>
92       <li><a href="#XML_SetNotStandaloneHandler">XML_SetNotStandaloneHandler</a></li>
93     </ul>
94     </li>
95     <li><a href="#position">Parse Position and Error Reporting Functions</a>
96     <ul>
97       <li><a href="#XML_GetErrorCode">XML_GetErrorCode</a></li>
98       <li><a href="#XML_ErrorString">XML_ErrorString</a></li>
99       <li><a href="#XML_GetCurrentByteIndex">XML_GetCurrentByteIndex</a></li>
100       <li><a href="#XML_GetCurrentLineNumber">XML_GetCurrentLineNumber</a></li>
101       <li><a href="#XML_GetCurrentColumnNumber">XML_GetCurrentColumnNumber</a></li>
102       <li><a href="#XML_GetCurrentByteCount">XML_GetCurrentByteCount</a></li>
103       <li><a href="#XML_GetInputContext">XML_GetInputContext</a></li>
104     </ul>
105     </li>
106     <li><a href="#miscellaneous">Miscellaneous Functions</a>
107     <ul>
108       <li><a href="#XML_SetUserData">XML_SetUserData</a></li>
109       <li><a href="#XML_GetUserData">XML_GetUserData</a></li>
110       <li><a href="#XML_UseParserAsHandlerArg">XML_UseParserAsHandlerArg</a></li>
111       <li><a href="#XML_SetBase">XML_SetBase</a></li>
112       <li><a href="#XML_GetBase">XML_GetBase</a></li>
113       <li><a href="#XML_GetSpecifiedAttributeCount">XML_GetSpecifiedAttributeCount</a></li>
114       <li><a href="#XML_GetIdAttributeIndex">XML_GetIdAttributeIndex</a></li>
115       <li><a href="#XML_SetEncoding">XML_SetEncoding</a></li>
116       <li><a href="#XML_SetParamEntityParsing">XML_SetParamEntityParsing</a></li>
117       <li><a href="#XML_UseForeignDTD">XML_UseForeignDTD</a></li>
118       <li><a href="#XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a></li>
119       <li><a href="#XML_DefaultCurrent">XML_DefaultCurrent</a></li>
120       <li><a href="#XML_ExpatVersion">XML_ExpatVersion</a></li>
121       <li><a href="#XML_ExpatVersionInfo">XML_ExpatVersionInfo</a></li>
122       <li><a href="#XML_GetFeatureList">XML_GetFeatureList</a></li>
123       <li><a href="#XML_FreeContentModel">XML_FreeContentModel</a></li>
124       <li><a href="#XML_MemMalloc">XML_MemMalloc</a></li>
125       <li><a href="#XML_MemRealloc">XML_MemRealloc</a></li>
126       <li><a href="#XML_MemFree">XML_MemFree</a></li>
127     </ul>
128     </li>
129   </ul>  
130   </li>
131 </ul>
132
133 <hr />
134 <h2><a name="overview">Overview</a></h2>
135
136 <p>Expat is a stream-oriented parser. You register callback (or
137 handler) functions with the parser and then start feeding it the
138 document.  As the parser recognizes parts of the document, it will
139 call the appropriate handler for that part (if you've registered one.) 
140 The document is fed to the parser in pieces, so you can start parsing
141 before you have all the document. This also allows you to parse really
142 huge documents that won't fit into memory.</p>
143
144 <p>Expat can be intimidating due to the many kinds of handlers and
145 options you can set. But you only need to learn four functions in
146 order to do 90% of what you'll want to do with it:</p>
147
148 <dl>
149
150 <dt><code><a href= "#XML_ParserCreate"
151              >XML_ParserCreate</a></code></dt>
152   <dd>Create a new parser object.</dd>
153
154 <dt><code><a href= "#XML_SetElementHandler"
155              >XML_SetElementHandler</a></code></dt>
156   <dd>Set handlers for start and end tags.</dd>
157
158 <dt><code><a href= "#XML_SetCharacterDataHandler"
159              >XML_SetCharacterDataHandler</a></code></dt>
160   <dd>Set handler for text.</dd>
161
162 <dt><code><a href= "#XML_Parse"
163              >XML_Parse</a></code></dt>
164   <dd>Pass a buffer full of document to the parser</dd>
165 </dl>
166
167 <p>These functions and others are described in the <a
168 href="#reference">reference</a> part of this document. The reference
169 section also describes in detail the parameters passed to the
170 different types of handlers.</p>
171
172 <p>Let's look at a very simple example program that only uses 3 of the
173 above functions (it doesn't need to set a character handler.) The
174 program <a href="../examples/outline.c">outline.c</a> prints an
175 element outline, indenting child elements to distinguish them from the
176 parent element that contains them. The start handler does all the
177 work.  It prints two indenting spaces for every level of ancestor
178 elements, then it prints the element and attribute
179 information. Finally it increments the global <code>Depth</code>
180 variable.</p>
181
182 <pre class="eg">
183 int Depth;
184
185 void
186 start(void *data, const char *el, const char **attr) {
187   int i;
188
189   for (i = 0; i &lt; Depth; i++)
190     printf("  ");
191
192   printf("%s", el);
193
194   for (i = 0; attr[i]; i += 2) {
195     printf(" %s='%s'", attr[i], attr[i + 1]);
196   }
197
198   printf("\n");
199   Depth++;
200 }  /* End of start handler */
201 </pre>
202
203 <p>The end tag simply does the bookkeeping work of decrementing
204 <code>Depth</code>.</p>
205 <pre class="eg">
206 void
207 end(void *data, const char *el) {
208   Depth--;
209 }  /* End of end handler */
210 </pre>
211
212 <p>After creating the parser, the main program just has the job of
213 shoveling the document to the parser so that it can do its work.</p>
214
215 <hr />
216 <h2><a name="building">Building and Installing Expat</a></h2>
217
218 <p>The Expat distribution comes as a compressed (with GNU gzip) tar
219 file.  You may download the latest version from <a href=
220 "http://sourceforge.net/projects/expat/" >Source Forge</a>.  After
221 unpacking this, cd into the directory. Then follow either the Win32
222 directions or Unix directions below.</p>
223
224 <h3>Building under Win32</h3>
225
226 <p>If you're using the GNU compiler under cygwin, follow the Unix
227 directions in the next section. Otherwise if you have Microsoft's
228 Developer Studio installed, then from Windows Explorer double-click on
229 "expat.dsp" in the lib directory and build and install in the usual
230 manner.</p>
231
232 <p>Alternatively, you may download the Win32 binary package that
233 contains the "expat.h" include file and a pre-built DLL.</p>
234
235 <h3>Building under Unix (or GNU)</h3>
236
237 <p>First you'll need to run the configure shell script in order to
238 configure the Makefiles and headers for your system.</p>
239
240 <p>If you're happy with all the defaults that configure picks for you,
241 and you have permission on your system to install into /usr/local, you
242 can install Expat with this sequence of commands:</p>
243
244 <pre class="eg">
245    ./configure
246    make
247    make install
248 </pre>
249
250 <p>There are some options that you can provide to this script, but the
251 only one we'll mention here is the <code>--prefix</code> option. You
252 can find out all the options available by running configure with just
253 the <code>--help</code> option.</p>
254
255 <p>By default, the configure script sets things up so that the library
256 gets installed in <code>/usr/local/lib</code> and the associated
257 header file in <code>/usr/local/include</code>.  But if you were to
258 give the option, <code>--prefix=/home/me/mystuff</code>, then the
259 library and header would get installed in
260 <code>/home/me/mystuff/lib</code> and
261 <code>/home/me/mystuff/include</code> respectively.</p>
262
263 <hr />
264 <h2><a name="using">Using Expat</a></h2>
265
266 <h3>Compiling and Linking Against Expat</h3>
267
268 <p>Unless you installed Expat in a location not expected by your
269 compiler and linker, all you have to do to use Expat in your programs
270 is to include the Expat header (<code>#include &lt;expat.h&gt;</code>)
271 in your files that make calls to it and to tell the linker that it
272 needs to link against the Expat library.  On Unix systems, this would
273 usually be done with the <code>-lexpat</code> argument.  Otherwise,
274 you'll need to tell the compiler where to look for the Expat header
275 and the linker where to find the Expat library.  You may also need to
276 take steps to tell the operating system where to find this libary at
277 run time.</p>
278
279 <p>On a Unix-based system, here's what a Makefile might look like when
280 Expat is installed in a standard location:</p>
281
282 <pre class="eg">
283 CC=cc
284 LDFLAGS=
285 LIBS= -lexpat
286 xmlapp: xmlapp.o
287         $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
288 </pre>
289
290 <p>If you installed Expat in, say, <code>/home/me/mystuff</code>, then
291 the Makefile would look like this:</p>
292
293 <pre class="eg">
294 CC=cc
295 CFLAGS= -I/home/me/mystuff/include
296 LDFLAGS=
297 LIBS= -L/home/me/mystuff/lib -lexpat
298 xmlapp: xmlapp.o
299         $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
300 </pre>
301
302 <p>You'd also have to set the environment variable
303 <code>LD_LIBRARY_PATH</code> to <code>/home/me/mystuff/lib</code> (or
304 to <code>${LD_LIBRARY_PATH}:/home/me/mystuff/lib</code> if
305 LD_LIBRARY_PATH already has some directories in it) in order to run
306 your application.</p>
307
308 <h3>Expat Basics</h3>
309
310 <p>As we saw in the example in the overview, the first step in parsing
311 an XML document with Expat is to create a parser object. There are <a
312 href="#creation">three functions</a> in the Expat API for creating a
313 parser object.  However, only two of these (<code><a href=
314 "#XML_ParserCreate" >XML_ParserCreate</a></code> and <code><a href=
315 "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>) can be used for
316 constructing a parser for a top-level document.  The object returned
317 by these functions is an opaque pointer (i.e. "expat.h" declares it as
318 void *) to data with further internal structure. In order to free the
319 memory associated with this object you must call <code><a href=
320 "#XML_ParserFree" >XML_ParserFree</a></code>. Note that if you have
321 provided any <a href="userdata">user data</a> that gets stored in the
322 parser, then your application is responsible for freeing it prior to
323 calling <code>XML_ParserFree</code>.</p>
324
325 <p>The objects returned by the parser creation functions are good for
326 parsing only one XML document or external parsed entity. If your
327 application needs to parse many XML documents, then it needs to create
328 a parser object for each one. The best way to deal with this is to
329 create a higher level object that contains all the default
330 initialization you want for your parser objects.</p>
331
332 <p>Walking through a document hierarchy with a stream oriented parser
333 will require a good stack mechanism in order to keep track of current
334 context.  For instance, to answer the simple question, "What element
335 does this text belong to?" requires a stack, since the parser may have
336 descended into other elements that are children of the current one and
337 has encountered this text on the way out.</p>
338
339 <p>The things you're likely to want to keep on a stack are the
340 currently opened element and it's attributes. You push this
341 information onto the stack in the start handler and you pop it off in
342 the end handler.</p>
343
344 <p>For some tasks, it is sufficient to just keep information on what
345 the depth of the stack is (or would be if you had one.) The outline
346 program shown above presents one example. Another such task would be
347 skipping over a complete element. When you see the start tag for the
348 element you want to skip, you set a skip flag and record the depth at
349 which the element started.  When the end tag handler encounters the
350 same depth, the skipped element has ended and the flag may be
351 cleared. If you follow the convention that the root element starts at
352 1, then you can use the same variable for skip flag and skip
353 depth.</p>
354
355 <pre class="eg">
356 void
357 init_info(Parseinfo *info) {
358   info->skip = 0;
359   info->depth = 1;
360   /* Other initializations here */
361 }  /* End of init_info */
362
363 void
364 rawstart(void *data, const char *el, const char **attr) {
365   Parseinfo *inf = (Parseinfo *) data;
366
367   if (! inf->skip) {
368     if (should_skip(inf, el, attr)) {
369       inf->skip = inf->depth;
370     }
371     else
372       start(inf, el, attr);     /* This does rest of start handling */
373   }
374
375   inf->depth++;
376 }  /* End of rawstart */
377
378 void
379 rawend(void *data, const char *el) {
380   Parseinfo *inf = (Parseinfo *) data;
381
382   inf->depth--;
383
384   if (! inf->skip)
385     end(inf, el);              /* This does rest of end handling */
386
387   if (inf->skip == inf->depth)
388     inf->skip = 0;
389 }  /* End rawend */
390 </pre>
391
392 <p>Notice in the above example the difference in how depth is
393 manipulated in the start and end handlers. The end tag handler should
394 be the mirror image of the start tag handler. This is necessary to
395 properly model containment. Since, in the start tag handler, we
396 incremented depth <em>after</em> the main body of start tag code, then
397 in the end handler, we need to manipulate it <em>before</em> the main
398 body.  If we'd decided to increment it first thing in the start
399 handler, then we'd have had to decrement it last thing in the end
400 handler.</p>
401
402 <h3 id="userdata">Communicating between handlers</h3>
403
404 <p>In order to be able to pass information between different handlers
405 without using globals, you'll need to define a data structure to hold
406 the shared variables. You can then tell Expat (with the <code><a href=
407 "#XML_SetUserData" >XML_SetUserData</a></code> function) to pass a
408 pointer to this structure to the handlers. This is typically the first
409 argument received by most handlers.</p>
410
411 <h3>XML Version</h3>
412
413 <p>Expat is an XML 1.0 parser, and as such never complains based on
414 the value of the <code>version</code> pseudo-attribute in the XML
415 declaration, if present.</p>
416
417 <p>If an application needs to check the version number (to support
418 alternate processing), it should use the <code><a href=
419 "#XML_SetXmlDeclHandler" >XML_SetXmlDeclHandler</a></code> function to
420 set a handler that uses the information in the XML declaration to
421 determine what to do.  This example shows how to check that only a
422 version number of <code>"1.0"</code> is accepted:</p>
423
424 <pre class="eg">
425 static int wrong_version;
426 static XML_Parser parser;
427
428 static void
429 xmldecl_handler(void            *userData,
430                 const XML_Char  *version,
431                 const XML_Char  *encoding,
432                 int              standalone)
433 {
434   static const XML_Char Version_1_0[] = {'1', '.', '0', 0};
435
436   int i;
437
438   for (i = 0; i &lt; (sizeof(Version_1_0) / sizeof(Version_1_0[0])); ++i) {
439     if (version[i] != Version_1_0[i]) {
440       wrong_version = 1;
441       /* also clear all other handlers: */
442       XML_SetCharacterDataHandler(parser, NULL);
443       ...
444       return;
445     }
446   }
447   ...
448 }
449 </pre>
450
451 <h3>Namespace Processing</h3>
452
453 <p>When the parser is created using the <code><a href=
454 "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>, function, Expat
455 performs namespace processing. Under namespace processing, Expat
456 consumes <code>xmlns</code> and <code>xmlns:...</code> attributes,
457 which declare namespaces for the scope of the element in which they
458 occur. This means that your start handler will not see these
459 attributes.  Your application can still be informed of these
460 declarations by setting namespace declaration handlers with <a href=
461 "#XML_SetNamespaceDeclHandler"
462 ><code>XML_SetNamespaceDeclHandler</code></a>.</p>
463
464 <p>Element type and attribute names that belong to a given namespace
465 are passed to the appropriate handler in expanded form. By default
466 this expanded form is a concatenation of the namespace URI, the
467 separator character (which is the 2nd argument to <code><a href=
468 "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>), and the local
469 name (i.e. the part after the colon). Names with undeclared prefixes
470 are passed through to the handlers unchanged, with the prefix and
471 colon still attached. Unprefixed attribute names are never expanded,
472 and unprefixed element names are only expanded when they are in the
473 scope of a default namespace.</p>
474
475 <p>However if <code><a href= "XML_SetReturnNSTriplet"
476 >XML_SetReturnNSTriplet</a></code> has been called with a non-zero
477 <code>do_nst</code> parameter, then the expanded form for names with
478 an explicit prefix is a concatenation of: URI, separator, local name,
479 separator, prefix.</p>
480
481 <p>You can set handlers for the start of a namespace declaration and
482 for the end of a scope of a declaration with the <code><a href=
483 "#XML_SetNamespaceDeclHandler" >XML_SetNamespaceDeclHandler</a></code>
484 function.  The StartNamespaceDeclHandler is called prior to the start
485 tag handler and the EndNamespaceDeclHandler is called before the
486 corresponding end tag that ends the namespace's scope.  The namespace
487 start handler gets passed the prefix and URI for the namespace.  For a
488 default namespace declaration (xmlns='...'), the prefix will be null.
489 The URI will be null for the case where the default namespace is being
490 unset.  The namespace end handler just gets the prefix for the closing
491 scope.</p>
492
493 <p>These handlers are called for each declaration. So if, for
494 instance, a start tag had three namespace declarations, then the
495 StartNamespaceDeclHandler would be called three times before the start
496 tag handler is called, once for each declaration.</p>
497
498 <h3>Character Encodings</h3>
499
500 <p>While XML is based on Unicode, and every XML processor is required
501 to recognized UTF-8 and UTF-16 (1 and 2 byte encodings of Unicode),
502 other encodings may be declared in XML documents or entities. For the
503 main document, an XML declaration may contain an encoding
504 declaration:</p>
505 <pre>
506 &lt;?xml version="1.0" encoding="ISO-8859-2"?&gt;
507 </pre>
508
509 <p>External parsed entities may begin with a text declaration, which
510 looks like an XML declaration with just an encoding declaration:</p>
511 <pre>
512 &lt;?xml encoding="Big5"?&gt;
513 </pre>
514
515 <p>With Expat, you may also specify an encoding at the time of
516 creating a parser. This is useful when the encoding information may
517 come from a source outside the document itself (like a higher level
518 protocol.)</p>
519
520 <p><a name="builtin_encodings"></a>There are four built-in encodings
521 in Expat:</p>
522 <ul>
523 <li>UTF-8</li>
524 <li>UTF-16</li>
525 <li>ISO-8859-1</li>
526 <li>US-ASCII</li>
527 </ul>
528
529 <p>Anything else discovered in an encoding declaration or in the
530 protocol encoding specified in the parser constructor, triggers a call
531 to the <code>UnknownEncodingHandler</code>. This handler gets passed
532 the encoding name and a pointer to an <code>XML_Encoding</code> data
533 structure. Your handler must fill in this structure and return
534 <code>XML_STATUS_OK</code> if it knows how to deal with the
535 encoding. Otherwise the handler should return
536 <code>XML_STATUS_ERROR</code>.  The handler also gets passed a pointer
537 to an optional application data structure that you may indicate when
538 you set the handler.</p>
539
540 <p>Expat places restrictions on character encodings that it can
541 support by filling in the <code>XML_Encoding</code> structure.
542 include file:</p>
543 <ol>
544 <li>Every ASCII character that can appear in a well-formed XML document
545 must be represented by a single byte, and that byte must correspond to
546 it's ASCII encoding (except for the characters $@\^'{}~)</li>
547 <li>Characters must be encoded in 4 bytes or less.</li>
548 <li>All characters encoded must have Unicode scalar values less than or
549 equal to 65535 (0xFFFF)<em>This does not apply to the built-in support
550 for UTF-16 and UTF-8</em></li>
551 <li>No character may be encoded by more that one distinct sequence of
552 bytes</li>
553 </ol>
554
555 <p><code>XML_Encoding</code> contains an array of integers that
556 correspond to the 1st byte of an encoding sequence. If the value in
557 the array for a byte is zero or positive, then the byte is a single
558 byte encoding that encodes the Unicode scalar value contained in the
559 array. A -1 in this array indicates a malformed byte. If the value is
560 -2, -3, or -4, then the byte is the beginning of a 2, 3, or 4 byte
561 sequence respectively. Multi-byte sequences are sent to the convert
562 function pointed at in the <code>XML_Encoding</code> structure. This
563 function should return the Unicode scalar value for the sequence or -1
564 if the sequence is malformed.</p>
565
566 <p>One pitfall that novice Expat users are likely to fall into is that
567 although Expat may accept input in various encodings, the strings that
568 it passes to the handlers are always encoded in UTF-8 or UTF-16
569 (depending on how Expat was compiled). Your application is responsible
570 for any translation of these strings into other encodings.</p>
571
572 <h3>Handling External Entity References</h3>
573
574 <p>Expat does not read or parse external entities directly. Note that
575 any external DTD is a special case of an external entity.  If you've
576 set no <code>ExternalEntityRefHandler</code>, then external entity
577 references are silently ignored. Otherwise, it calls your handler with
578 the information needed to read and parse the external entity.</p>
579
580 <p>Your handler isn't actually responsible for parsing the entity, but
581 it is responsible for creating a subsidiary parser with <code><a href=
582 "#XML_ExternalEntityParserCreate"
583 >XML_ExternalEntityParserCreate</a></code> that will do the job. This
584 returns an instance of <code>XML_Parser</code> that has handlers and
585 other data structures initialized from the parent parser. You may then
586 use <code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a
587 href= "#XML_ParseBuffer">XML_ParseBuffer</a></code> calls against this
588 parser.  Since external entities my refer to other external entities,
589 your handler should be prepared to be called recursively.</p>
590
591 <h3>Parsing DTDs</h3>
592
593 <p>In order to parse parameter entities, before starting the parse,
594 you must call <code><a href= "#XML_SetParamEntityParsing"
595 >XML_SetParamEntityParsing</a></code> with one of the following
596 arguments:</p>
597 <dl>
598 <dt><code>XML_PARAM_ENTITY_PARSING_NEVER</code></dt>
599 <dd>Don't parse parameter entities or the external subset</dd>
600 <dt><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></dt>
601 <dd>Parse parameter entites and the external subset unless
602 <code>standalone</code> was set to "yes" in the XML declaration.</dd>
603 <dt><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></dt>
604 <dd>Always parse parameter entities and the external subset</dd>
605 </dl>
606
607 <p>In order to read an external DTD, you also have to set an external
608 entity reference handler as described above.</p>
609
610 <hr />
611 <!-- ================================================================ -->
612
613 <h2><a name="reference">Expat Reference</a></h2>
614
615 <h3><a name="creation">Parser Creation</a></h3>
616
617 <pre class="fcndec" id="XML_ParserCreate">
618 XML_Parser
619 XML_ParserCreate(const XML_Char *encoding);
620 </pre>
621 <div class="fcndef">
622 Construct a new parser. If encoding is non-null, it specifies a
623 character encoding to use for the document. This overrides the document
624 encoding declaration. There are four built-in encodings:
625 <ul>
626 <li>US-ASCII</li>
627 <li>UTF-8</li>
628 <li>UTF-16</li>
629 <li>ISO-8859-1</li>
630 </ul>
631 Any other value will invoke a call to the UnknownEncodingHandler.
632 </div>
633
634 <pre class="fcndec" id="XML_ParserCreateNS">
635 XML_Parser
636 XML_ParserCreateNS(const XML_Char *encoding,
637                    XML_Char sep);
638 </pre>
639 <div class="fcndef">
640 Constructs a new parser that has namespace processing in effect. Namespace
641 expanded element names and attribute names are returned as a concatenation
642 of the namespace URI, <em>sep</em>, and the local part of the name. This
643 means that you should pick a character for <em>sep</em> that can't be
644 part of a legal URI.</div>
645
646 <pre class="fcndec" id="XML_ParserCreate_MM">
647 XML_Parser
648 XML_ParserCreate_MM(const XML_Char *encoding,
649                     const XML_Memory_Handling_Suite *ms,
650                     const XML_Char *sep);
651 </pre>
652 <pre class="signature">
653 typedef struct {
654   void *(*malloc_fcn)(size_t size);
655   void *(*realloc_fcn)(void *ptr, size_t size);
656   void (*free_fcn)(void *ptr);
657 } XML_Memory_Handling_Suite;
658 </pre>
659 <div class="fcndef">
660 <p>Construct a new parser using the suite of memory handling functions
661 specified in <code>ms</code>. If <code>ms</code> is NULL, then use the
662 standard set of memory management functions. If <code>sep</code> is
663 non NULL, then namespace processing is enabled in the created parser
664 and the character pointed at by sep is used as the separator between
665 the namespace URI and the local part of the name.</p>
666 </div>
667
668 <pre class="fcndec" id="XML_ExternalEntityParserCreate">
669 XML_Parser
670 XML_ExternalEntityParserCreate(XML_Parser p,
671                                const XML_Char *context,
672                                const XML_Char *encoding);
673 </pre>
674 <div class="fcndef">
675 Construct a new <code>XML_Parser</code> object for parsing an external
676 general entity. Context is the context argument passed in a call to a
677 ExternalEntityRefHandler. Other state information such as handlers,
678 user data, namespace processing is inherited from the parser passed as
679 the 1st argument. So you shouldn't need to call any of the behavior
680 changing functions on this parser (unless you want it to act
681 differently than the parent parser).
682 </div>
683
684 <pre class="fcndec" id="XML_ParserFree">
685 void
686 XML_ParserFree(XML_Parser p);
687 </pre>
688 <div class="fcndef">
689 Free memory used by the parser. Your application is responsible for
690 freeing any memory associated with <a href="#userdata">user data</a>.
691 </div>
692
693 <pre class="fcndec" id="XML_ParserReset">
694 XML_Bool
695 XML_ParserReset(XML_Parser p);
696 </pre>
697 <div class="fcndef">
698 Clean up the memory structures maintained by the parser so that it may
699 be used again.  After this has been called, <code>parser</code> is
700 ready to start parsing a new document.  This function may not be used
701 on a parser created using <code><a href=
702 "#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a
703 ></code>; it will return <code>XML_FALSE</code> in that case.  Returns
704 <code>XML_TRUE</code> on success.  Your application is responsible for
705 dealing with any memory associated with <a href="#userdata">user data</a>.
706 </div>
707
708 <h3><a name="parsing">Parsing</a></h3>
709
710 <p>To state the obvious: the three parsing functions <code><a href=
711 "#XML_Parse" >XML_Parse</a></code>, <code><a href= "#XML_ParseBuffer"
712 >XML_ParseBuffer</a></code> and <code><a href= "#XML_GetBuffer"
713 >>XML_GetBuffer</a></code> must not be
714 called from within a handler unless they operate on a separate parser
715 instance, that is, one that did not call the handler. For example, it
716 is OK to call the parsing functions from within an
717 <code>XML_ExternalEntityRefHandler</code>, if they apply to the parser
718 created by <code><a href= "#XML_ExternalEntityParserCreate"
719 >XML_ExternalEntityParserCreate</a></code>.</p>
720
721 <pre class="fcndec" id="XML_Parse">
722 enum XML_Status
723 XML_Parse(XML_Parser p,
724           const char *s,
725           int len,
726           int isFinal);
727 </pre>
728 <pre class="signature">
729 enum XML_Status {
730   XML_STATUS_ERROR = 0,
731   XML_STATUS_OK = 1
732 };
733 </pre>
734 <div class="fcndef">
735 Parse some more of the document. The string <code>s</code> is a buffer
736 containing part (or perhaps all) of the document. The number of bytes of s
737 that are part of the document is indicated by <code>len</code>. This means
738 that <code>s</code> doesn't have to be null terminated. It also means that
739 if <code>len</code> is larger than the number of bytes in the block of
740 memory that <code>s</code> points at, then a memory fault is likely. The
741 <code>isFinal</code> parameter informs the parser that this is the last
742 piece of the document. Frequently, the last piece is empty (i.e.
743 <code>len</code> is zero.)
744 If a parse error occurred, it returns <code>XML_STATUS_ERROR</code>.
745 Otherwise it returns <code>XML_STATUS_OK</code> value.
746 </div>
747
748 <pre class="fcndec" id="XML_ParseBuffer">
749 enum XML_Status
750 XML_ParseBuffer(XML_Parser p,
751                 int len,
752                 int isFinal);
753 </pre>
754 <div class="fcndef">
755 This is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>,
756 except in this case Expat provides the buffer.  By obtaining the
757 buffer from Expat with the <code><a href= "#XML_GetBuffer"
758 >XML_GetBuffer</a></code> function, the application can avoid double
759 copying of the input.
760 </div>
761
762 <pre class="fcndec" id="XML_GetBuffer">
763 void *
764 XML_GetBuffer(XML_Parser p,
765               int len);
766 </pre>
767 <div class="fcndef">
768 Obtain a buffer of size <code>len</code> to read a piece of the document
769 into. A NULL value is returned if Expat can't allocate enough memory for
770 this buffer. This has to be called prior to every call to
771 <code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A
772 typical use would look like this:
773
774 <pre class="eg">
775 for (;;) {
776   int bytes_read;
777   void *buff = XML_GetBuffer(p, BUFF_SIZE);
778   if (buff == NULL) {
779     /* handle error */
780   }
781
782   bytes_read = read(docfd, buff, BUFF_SIZE);
783   if (bytes_read &lt; 0) {
784     /* handle error */
785   }
786
787   if (! XML_ParseBuffer(p, bytes_read, bytes_read == 0)) {
788     /* handle parse error */
789   }
790
791   if (bytes_read == 0)
792     break;
793 }
794 </pre>
795 </div>
796
797 <h3><a name="setting">Handler Setting</a></h3>
798
799 <p>Although handlers are typically set prior to parsing and left alone, an
800 application may choose to set or change the handler for a parsing event
801 while the parse is in progress. For instance, your application may choose
802 to ignore all text not descended from a <code>para</code> element. One
803 way it could do this is to set the character handler when a para start tag
804 is seen, and unset it for the corresponding end tag.</p>
805
806 <p>A handler may be <em>unset</em> by providing a NULL pointer to the
807 appropriate handler setter. None of the handler setting functions have
808 a return value.</p>
809
810 <p>Your handlers will be receiving strings in arrays of type
811 <code>XML_Char</code>. This type is defined in expat.h as <code>char
812 *</code> and contains bytes encoding UTF-8.  Note that you'll receive
813 them in this form independent of the original encoding of the
814 document.</p>
815
816 <div class="handler">
817 <pre class="setter" id="XML_SetStartElementHandler">
818 XML_SetStartElementHandler(XML_Parser p,
819                            XML_StartElementHandler start);
820 </pre>
821 <pre class="signature">
822 typedef void
823 (*XML_StartElementHandler)(void *userData,
824                            const XML_Char *name,
825                            const XML_Char **atts);
826 </pre>
827 <p>Set handler for start (and empty) tags. Attributes are passed to the start
828 handler as a pointer to a vector of char pointers. Each attribute seen in
829 a start (or empty) tag occupies 2 consecutive places in this vector: the
830 attribute name followed by the attribute value. These pairs are terminated
831 by a null pointer.</p>
832 <p>Note that an empty tag generates a call to both start and end handlers
833 (in that order).</p>
834 </div>
835
836 <div class="handler">
837 <pre class="setter" id="XML_SetEndElementHandler">
838 XML_SetEndElementHandler(XML_Parser p,
839                          XML_EndElementHandler);
840 </pre>
841 <pre class="signature">
842 typedef void
843 (*XML_EndElementHandler)(void *userData,
844                          const XML_Char *name);
845 </pre>
846 <p>Set handler for end (and empty) tags. As noted above, an empty tag
847 generates a call to both start and end handlers.</p>
848 </div>
849
850 <div class="handler">
851 <pre class="setter" id="XML_SetElementHandler">
852 XML_SetElementHandler(XML_Parser p,
853                       XML_StartElementHandler start,
854                       XML_EndElementHandler end);
855 </pre>
856 <p>Set handlers for start and end tags with one call.</p>
857 </div>
858
859 <div class="handler">
860 <pre class="setter" id="XML_SetCharacterDataHandler">
861 XML_SetCharacterDataHandler(XML_Parser p,
862                             XML_CharacterDataHandler charhndl)
863 </pre>
864 <pre class="signature">
865 typedef void
866 (*XML_CharacterDataHandler)(void *userData,
867                             const XML_Char *s,
868                             int len);
869 </pre>
870 <p>Set a text handler. The string your handler receives
871 is <em>NOT nul-terminated</em>. You have to use the length argument
872 to deal with the end of the string. A single block of contiguous text
873 free of markup may still result in a sequence of calls to this handler.
874 In other words, if you're searching for a pattern in the text, it may
875 be split across calls to this handler.</p>
876 </div>
877
878 <div class="handler">
879 <pre class="setter" id="XML_SetProcessingInstructionHandler">
880 XML_SetProcessingInstructionHandler(XML_Parser p,
881                                     XML_ProcessingInstructionHandler proc)
882 </pre>
883 <pre class="signature">
884 typedef void
885 (*XML_ProcessingInstructionHandler)(void *userData,
886                                     const XML_Char *target,
887                                     const XML_Char *data);
888
889 </pre>
890 <p>Set a handler for processing instructions. The target is the first word
891 in the processing instruction. The data is the rest of the characters in
892 it after skipping all whitespace after the initial word.</p>
893 </div>
894
895 <div class="handler">
896 <pre class="setter" id="XML_SetCommentHandler">
897 XML_SetCommentHandler(XML_Parser p,
898                       XML_CommentHandler cmnt)
899 </pre>
900 <pre class="signature">
901 typedef void
902 (*XML_CommentHandler)(void *userData,
903                       const XML_Char *data);
904 </pre>
905 <p>Set a handler for comments. The data is all text inside the comment
906 delimiters.</p>
907 </div>
908
909 <div class="handler">
910 <pre class="setter" id="XML_SetStartCdataSectionHandler">
911 XML_SetStartCdataSectionHandler(XML_Parser p,
912                                 XML_StartCdataSectionHandler start);
913 </pre>
914 <pre class="signature">
915 typedef void
916 (*XML_StartCdataSectionHandler)(void *userData);
917 </pre>
918 <p>Set a handler that gets called at the beginning of a CDATA section.</p>
919 </div>
920
921 <div class="handler">
922 <pre class="setter" id="XML_SetEndCdataSectionHandler">
923 XML_SetEndCdataSectionHandler(XML_Parser p,
924                               XML_EndCdataSectionHandler end);
925 </pre>
926 <pre class="signature">
927 typedef void
928 (*XML_EndCdataSectionHandler)(void *userData);
929 </pre>
930 <p>Set a handler that gets called at the end of a CDATA section.</p>
931 </div>
932
933 <div class="handler">
934 <pre class="setter" id="XML_SetCdataSectionHandler">
935 XML_SetCdataSectionHandler(XML_Parser p,
936                            XML_StartCdataSectionHandler start,
937                            XML_EndCdataSectionHandler end)
938 </pre>
939 <p>Sets both CDATA section handlers with one call.</p>
940 </div>
941
942 <div class="handler">
943 <pre class="setter" id="XML_SetDefaultHandler">
944 XML_SetDefaultHandler(XML_Parser p,
945                       XML_DefaultHandler hndl)
946 </pre>
947 <pre class="signature">
948 typedef void
949 (*XML_DefaultHandler)(void *userData,
950                       const XML_Char *s,
951                       int len);
952 </pre>
953
954 <p>Sets a handler for any characters in the document which wouldn't
955 otherwise be handled. This includes both data for which no handlers
956 can be set (like some kinds of DTD declarations) and data which could
957 be reported but which currently has no handler set.  The characters
958 are passed exactly as they were present in the XML document except
959 that they will be encoded in UTF-8 or UTF-16. Line boundaries are not
960 normalized. Note that a byte order mark character is not passed to the
961 default handler. There are no guarantees about how characters are
962 divided between calls to the default handler: for example, a comment
963 might be split between multiple calls.  Setting the handler with
964 this call has the side effect of turning off expansion of references
965 to internally defined general entities. Instead these references are
966 passed to the default handler.</p>
967
968 <p>See also <code><a
969 href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
970 </div>
971
972 <div class="handler">
973 <pre class="setter" id="XML_SetDefaultHandlerExpand">
974 XML_SetDefaultHandlerExpand(XML_Parser p,
975                             XML_DefaultHandler hndl)
976 </pre>
977 <pre class="signature">
978 typedef void
979 (*XML_DefaultHandler)(void *userData,
980                       const XML_Char *s,
981                       int len);
982 </pre>
983 <p>This sets a default handler, but doesn't inhibit the expansion of
984 internal entity references.  The entity reference will not be passed
985 to the default handler.</p>
986
987 <p>See also <code><a
988 href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
989 </div>
990
991 <div class="handler">
992 <pre class="setter" id="XML_SetExternalEntityRefHandler">
993 XML_SetExternalEntityRefHandler(XML_Parser p,
994                                 XML_ExternalEntityRefHandler hndl)
995 </pre>
996 <pre class="signature">
997 typedef int
998 (*XML_ExternalEntityRefHandler)(XML_Parser p,
999                                 const XML_Char *context,
1000                                 const XML_Char *base,
1001                                 const XML_Char *systemId,
1002                                 const XML_Char *publicId);
1003 </pre>
1004 <p>Set an external entity reference handler. This handler is also
1005 called for processing an external DTD subset if parameter entity parsing
1006 is in effect. (See <a href="#XML_SetParamEntityParsing">
1007 <code>XML_SetParamEntityParsing</code></a>.)</p>
1008
1009 <p>The <code>context</code> parameter specifies the parsing context in
1010 the format expected by the <code>context</code> argument to <code><a
1011 href="#XML_ExternalEntityParserCreate"
1012 >XML_ExternalEntityParserCreate</a></code>.  <code>code</code> is
1013 valid only until the handler returns, so if the referenced entity is
1014 to be parsed later, it must be copied.  <code>context</code> is NULL
1015 only when the entity is a parameter entity, which is how one can
1016 differentiate between general and parameter entities.</p>
1017
1018 <p>The <code>base</code> parameter is the base to use for relative
1019 system identifiers.  It is set by <code><a
1020 href="#XML_SetBase">XML_SetBase</a></code> and may be NULL. The
1021 <code>publicId</code> parameter is the public id given in the entity
1022 declaration and may be NULL.  <code>systemId</code> is the system
1023 identifier specified in the entity declaration and is never NULL.</p>
1024
1025 <p>There are a couple of ways in which this handler differs from
1026 others.  First, this handler returns a status indicator (an
1027 integer). <code>XML_STATUS_OK</code> should be returned for successful
1028 handling of the external entity reference.  Returning
1029 <code>XML_STATUS_ERROR</code> indicates failure, and causes the
1030 calling parser to return an
1031 <code>XML_ERROR_EXTERNAL_ENTITY_HANDLING</code> error.</p>
1032
1033 <p>Second, instead of having the user data as its first argument, it
1034 receives the parser that encountered the entity reference. This, along
1035 with the context parameter, may be used as arguments to a call to
1036 <code><a href= "#XML_ExternalEntityParserCreate"
1037 >XML_ExternalEntityParserCreate</a></code>.  Using the returned
1038 parser, the body of the external entity can be recursively parsed.</p>
1039
1040 <p>Since this handler may be called recursively, it should not be saving
1041 information into global or static variables.</p>
1042 </div>
1043
1044 <pre class="fcndec" id="XML_SetExternalEntityRefHandlerArg">
1045 XML_SetExternalEntityRefHandlerArg(XML_Parser p,
1046                                    void *arg)
1047 </pre>
1048 <div class="fcndef">
1049 <p>Set the argument passed to the ExternalEntityRefHandler.  If
1050 <code>arg</code> is not NULL, it is the new value passed to the
1051 handler set using <code><a href="#XML_SetExternalEntityRefHandler"
1052 >XML_SetExternalEntityRefHandler</a></code>; if <code>arg</code> is
1053 NULL, the argument passed to the handler function will be the parser
1054 object itself.</p>
1055
1056 <p><strong>Note:</strong>
1057 The type of <code>arg</code> and the type of the first argument to the
1058 ExternalEntityRefHandler do not match.  This function takes a
1059 <code>void *</code> to be passed to the handler, while the handler
1060 accepts an <code>XML_Parser</code>.  This is a historical accident,
1061 but will not be corrected before Expat 2.0 (at the earliest) to avoid
1062 causing compiler warnings for code that's known to work with this
1063 API.  It is the responsibility of the application code to know the
1064 actual type of the argument passed to the handler and to manage it
1065 properly.</p>
1066 </div>
1067
1068 <div class="handler">
1069 <pre class="setter" id="XML_SetSkippedEntityHandler">
1070 XML_SetSkippedEntityHandler(XML_Parser p,
1071                             XML_SkippedEntityHandler handler)
1072 </pre>
1073 <pre class="signature">
1074 typedef void
1075 (*XML_SkippedEntityHandler)(void *userData,
1076                             const XML_Char *entityName,
1077                             int is_parameter_entity);
1078 </pre>
1079 <p>Set a skipped entity handler. This is called in two situations:</p>
1080 <ol>
1081    <li>An entity reference is encountered for which no declaration
1082        has been read <em>and</em> this is not an error.</li>
1083    <li>An internal entity reference is read, but not expanded, because
1084        <a href="#XML_SetDefaultHandler"><code>XML_SetDefaultHandler</code></a>
1085            has been called.</li>
1086 </ol>
1087 <p>The <code>is_parameter_entity</code> argument will be non-zero for
1088 a parameter entity and zero for a general entity.</p> <p>Note: skipped
1089 parameter entities in declarations and skipped general entities in
1090 attribute values cannot be reported, because the event would be out of
1091 sync with the reporting of the declarations or attribute values</p>
1092 </div>
1093
1094 <div class="handler">
1095 <pre class="setter" id="XML_SetUnknownEncodingHandler">
1096 XML_SetUnknownEncodingHandler(XML_Parser p,
1097                               XML_UnknownEncodingHandler enchandler,
1098                               void *encodingHandlerData)
1099 </pre>
1100 <pre class="signature">
1101 typedef int
1102 (*XML_UnknownEncodingHandler)(void *encodingHandlerData,
1103                               const XML_Char *name,
1104                               XML_Encoding *info);
1105
1106 typedef struct {
1107   int map[256];
1108   void *data;
1109   int (*convert)(void *data, const char *s);
1110   void (*release)(void *data);
1111 } XML_Encoding;
1112 </pre>
1113 <p>Set a handler to deal with encodings other than the <a
1114 href="#builtin_encodings">built in set</a>. This should be done before
1115 <code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href=
1116 "#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the
1117 given parser.</p> <p>If the handler knows how to deal with an encoding
1118 with the given name, it should fill in the <code>info</code> data
1119 structure and return <code>XML_STATUS_ERROR</code>. Otherwise it
1120 should return <code>XML_STATUS_OK</code>. The handler will be called
1121 at most once per parsed (external) entity. The optional application
1122 data pointer <code>encodingHandlerData</code> will be passed back to
1123 the handler.</p>
1124
1125 <p>The map array contains information for every possible possible leading
1126 byte in a byte sequence. If the corresponding value is &gt;= 0, then it's
1127 a single byte sequence and the byte encodes that Unicode value. If the
1128 value is -1, then that byte is invalid as the initial byte in a sequence.
1129 If the value is -n, where n is an integer &gt; 1, then n is the number of
1130 bytes in the sequence and the actual conversion is accomplished by a
1131 call to the function pointed at by convert. This function may return -1
1132 if the sequence itself is invalid. The convert pointer may be null if
1133 there are only single byte codes. The data parameter passed to the convert
1134 function is the data pointer from <code>XML_Encoding</code>. The
1135 string s is <em>NOT</em> nul-terminated and points at the sequence of
1136 bytes to be converted.</p>
1137
1138 <p>The function pointed at by <code>release</code> is called by the
1139 parser when it is finished with the encoding. It may be NULL.</p>
1140 </div>
1141
1142 <div class="handler">
1143 <pre class="setter" id="XML_SetStartNamespaceDeclHandler">
1144 XML_SetStartNamespaceDeclHandler(XML_Parser p,
1145                                  XML_StartNamespaceDeclHandler start);
1146 </pre>
1147 <pre class="signature">
1148 typedef void
1149 (*XML_StartNamespaceDeclHandler)(void *userData,
1150                                  const XML_Char *prefix,
1151                                  const XML_Char *uri);
1152 </pre>
1153 <p>Set a handler to be called when a namespace is declared. Namespace
1154 declarations occur inside start tags. But the namespace declaration start
1155 handler is called before the start tag handler for each namespace declared
1156 in that start tag.</p>
1157 </div>
1158
1159 <div class="handler">
1160 <pre class="setter" id="XML_SetEndNamespaceDeclHandler">
1161 XML_SetEndNamespaceDeclHandler(XML_Parser p,
1162                                XML_EndNamespaceDeclHandler end);
1163 </pre>
1164 <pre class="signature">
1165 typedef void
1166 (*XML_EndNamespaceDeclHandler)(void *userData,
1167                                const XML_Char *prefix);
1168 </pre>
1169 <p>Set a handler to be called when leaving the scope of a namespace
1170 declaration. This will be called, for each namespace declaration,
1171 after the handler for the end tag of the element in which the
1172 namespace was declared.</p>
1173 </div>
1174
1175 <div class="handler">
1176 <pre class="setter" id="XML_SetNamespaceDeclHandler">
1177 XML_SetNamespaceDeclHandler(XML_Parser p,
1178                             XML_StartNamespaceDeclHandler start,
1179                             XML_EndNamespaceDeclHandler end)
1180 </pre>
1181 <p>Sets both namespace declaration handlers with a single call.</p>
1182 </div>
1183
1184 <div class="handler">
1185 <pre class="setter" id="XML_SetXmlDeclHandler">
1186 XML_SetXmlDeclHandler(XML_Parser p,
1187                       XML_XmlDeclHandler xmldecl);
1188 </pre>
1189 <pre class="signature">
1190 typedef void
1191 (*XML_XmlDeclHandler) (void            *userData,
1192                        const XML_Char  *version,
1193                        const XML_Char  *encoding,
1194                        int             standalone);
1195 </pre>
1196 <p>Sets a handler that is called for XML declarations and also for
1197 text declarations discovered in external entities. The way to
1198 distinguish is that the <code>version</code> parameter will be NULL
1199 for text declarations. The <code>encoding</code> parameter may be NULL
1200 for an XML declaration. The <code>standalone</code> argument will
1201 contain -1, 0, or 1 indicating respectively that there was no
1202 standalone parameter in the declaration, that it was given as no, or
1203 that it was given as yes.</p>
1204 </div>
1205
1206 <div class="handler">
1207 <pre class="setter" id="XML_SetStartDoctypeDeclHandler">
1208 XML_SetStartDoctypeDeclHandler(XML_Parser p,
1209                                XML_StartDoctypeDeclHandler start);
1210 </pre>
1211 <pre class="signature">
1212 typedef void
1213 (*XML_StartDoctypeDeclHandler)(void           *userData,
1214                                const XML_Char *doctypeName,
1215                                const XML_Char *sysid,
1216                                const XML_Char *pubid,
1217                                int            has_internal_subset);
1218 </pre>
1219 <p>Set a handler that is called at the start of a DOCTYPE declaration,
1220 before any external or internal subset is parsed. Both <code>sysid</code>
1221 and <code>pubid</code> may be NULL. The <code>has_internal_subset</code>
1222 will be non-zero if the DOCTYPE declaration has an internal subset.</p>
1223 </div>
1224
1225 <div class="handler">
1226 <pre class="setter" id="XML_SetEndDoctypeDeclHandler">
1227 XML_SetEndDoctypeDeclHandler(XML_Parser p,
1228                              XML_EndDoctypeDeclHandler end);
1229 </pre>
1230 <pre class="signature">
1231 typedef void
1232 (*XML_EndDoctypeDeclHandler)(void *userData);
1233 </pre>
1234 <p>Set a handler that is called at the end of a DOCTYPE declaration,
1235 after parsing any external subset.</p>
1236 </div>
1237
1238 <div class="handler">
1239 <pre class="setter" id="XML_SetDoctypeDeclHandler">
1240 XML_SetDoctypeDeclHandler(XML_Parser p,
1241                           XML_StartDoctypeDeclHandler start,
1242                           XML_EndDoctypeDeclHandler end);
1243 </pre>
1244 <p>Set both doctype handlers with one call.</p>
1245 </div>
1246
1247 <div class="handler">
1248 <pre class="setter" id="XML_SetElementDeclHandler">
1249 XML_SetElementDeclHandler(XML_Parser p,
1250                           XML_ElementDeclHandler eldecl);
1251 </pre>
1252 <pre class="signature">
1253 typedef void
1254 (*XML_ElementDeclHandler)(void *userData,
1255                           const XML_Char *name,
1256                           XML_Content *model);
1257 </pre>
1258 <pre class="signature">
1259 enum XML_Content_Type {
1260   XML_CTYPE_EMPTY = 1,
1261   XML_CTYPE_ANY,
1262   XML_CTYPE_MIXED,
1263   XML_CTYPE_NAME,
1264   XML_CTYPE_CHOICE,
1265   XML_CTYPE_SEQ
1266 };
1267
1268 enum XML_Content_Quant {
1269   XML_CQUANT_NONE,
1270   XML_CQUANT_OPT,
1271   XML_CQUANT_REP,
1272   XML_CQUANT_PLUS
1273 };
1274
1275 typedef struct XML_cp XML_Content;
1276
1277 struct XML_cp {
1278   enum XML_Content_Type         type;
1279   enum XML_Content_Quant        quant;
1280   const XML_Char *              name;
1281   unsigned int                  numchildren;
1282   XML_Content *                 children;
1283 };
1284 </pre>
1285 <p>Sets a handler for element declarations in a DTD. The handler gets
1286 called with the name of the element in the declaration and a pointer
1287 to a structure that contains the element model. It is the
1288 application's responsibility to free this data structure using
1289 <code><a href="#XML_FreeContentModel"
1290 >XML_FreeContentModel</a></code>.</p>
1291
1292 <p>The <code>model</code> argument is the root of a tree of
1293 <code>XML_Content</code> nodes. If <code>type</code> equals
1294 <code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then
1295 <code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other
1296 fields will be zero or NULL.  If <code>type</code> is
1297 <code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be
1298 <code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and
1299 <code>numchildren</code> will contain the number of elements that are
1300 allowed to be mixed in and <code>children</code> points to an array of
1301 <code>XML_Content</code> structures that will all have type
1302 XML_CTYPE_NAME with no quantification.  Only the root node can be type
1303 <code>XML_CTYPE_EMPTY</code>, <code>XML_CTYPE_ANY</code>, or
1304 <code>XML_CTYPE_MIXED</code>.</p>
1305
1306 <p>For type <code>XML_CTYPE_NAME</code>, the <code>name</code> field
1307 points to the name and the <code>numchildren</code> and
1308 <code>children</code> fields will be zero and NULL. The
1309 <code>quant</code> field will indicate any quantifiers placed on the
1310 name.</p>
1311
1312 <p>Types <code>XML_CTYPE_CHOICE</code> and <code>XML_CTYPE_SEQ</code>
1313 indicate a choice or sequence respectively. The
1314 <code>numchildren</code> field indicates how many nodes in the choice
1315 or sequence and <code>children</code> points to the nodes.</p>
1316 </div>
1317
1318 <div class="handler">
1319 <pre class="setter" id="XML_SetAttlistDeclHandler">
1320 XML_SetAttlistDeclHandler(XML_Parser p,
1321                           XML_AttlistDeclHandler attdecl);
1322 </pre>
1323 <pre class="signature">
1324 typedef void
1325 (*XML_AttlistDeclHandler) (void           *userData,
1326                            const XML_Char *elname,
1327                            const XML_Char *attname,
1328                            const XML_Char *att_type,
1329                            const XML_Char *dflt,
1330                            int            isrequired);
1331 </pre>
1332 <p>Set a handler for attlist declarations in the DTD. This handler is
1333 called for <em>each</em> attribute. So a single attlist declaration
1334 with multiple attributes declared will generate multiple calls to this
1335 handler. The <code>elname</code> parameter returns the name of the
1336 element for which the attribute is being declared. The attribute name
1337 is in the <code>attname</code> parameter. The attribute type is in the
1338 <code>att_type</code> parameter.  It is the string representing the
1339 type in the declaration with whitespace removed.</p>
1340
1341 <p>The <code>dflt</code> parameter holds the default value. It will be
1342 NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. You can
1343 distinguish these two cases by checking the <code>isrequired</code>
1344 parameter, which will be true in the case of "#REQUIRED" attributes.
1345 Attributes which are "#FIXED" will have also have a true
1346 <code>isrequired</code>, but they will have the non-NULL fixed value
1347 in the <code>dflt</code> parameter.</p>
1348 </div>
1349
1350 <div class="handler">
1351 <pre class="setter" id="XML_SetEntityDeclHandler">
1352 XML_SetEntityDeclHandler(XML_Parser p,
1353                          XML_EntityDeclHandler handler);
1354 </pre>
1355 <pre class="signature">
1356 typedef void
1357 (*XML_EntityDeclHandler) (void           *userData,
1358                           const XML_Char *entityName,
1359                           int            is_parameter_entity,
1360                           const XML_Char *value,
1361                           int            value_length,
1362                           const XML_Char *base,
1363                           const XML_Char *systemId,
1364                           const XML_Char *publicId,
1365                           const XML_Char *notationName);
1366 </pre>
1367 <p>Sets a handler that will be called for all entity declarations.
1368 The <code>is_parameter_entity</code> argument will be non-zero in the
1369 case of parameter entities and zero otherwise.</p>
1370
1371 <p>For internal entities (<code>&lt;!ENTITY foo "bar"&gt;</code>),
1372 <code>value</code> will be non-NULL and <code>systemId</code>,
1373 <code>publicId</code>, and <code>notationName</code> will all be NULL.
1374 The value string is <em>not</em> NULL terminated; the length is
1375 provided in the <code>value_length</code> parameter. Do not use
1376 <code>value_length</code> to test for internal entities, since it is
1377 legal to have zero-length values. Instead check for whether or not
1378 <code>value</code> is NULL.</p> <p>The <code>notationName</code>
1379 argument will have a non-NULL value only for unparsed entity
1380 declarations.</p>
1381 </div>
1382
1383 <div class="handler">
1384 <pre class="setter" id="XML_SetUnparsedEntityDeclHandler">
1385 XML_SetUnparsedEntityDeclHandler(XML_Parser p,
1386                                  XML_UnparsedEntityDeclHandler h)
1387 </pre>
1388 <pre class="signature">
1389 typedef void
1390 (*XML_UnparsedEntityDeclHandler)(void *userData,
1391                                  const XML_Char *entityName,
1392                                  const XML_Char *base,
1393                                  const XML_Char *systemId,
1394                                  const XML_Char *publicId,
1395                                  const XML_Char *notationName);
1396 </pre>
1397 <p>Set a handler that receives declarations of unparsed entities. These
1398 are entity declarations that have a notation (NDATA) field:</p>
1399
1400 <div id="eg"><pre>
1401 &lt;!ENTITY logo SYSTEM "images/logo.gif" NDATA gif&gt;
1402 </pre></div>
1403 <p>This handler is obsolete and is provided for backwards
1404 compatibility.  Use instead <a href= "#XML_SetEntityDeclHandler"
1405 >XML_SetEntityDeclHandler</a>.</p>
1406 </div>
1407
1408 <div class="handler">
1409 <pre class="setter" id="XML_SetNotationDeclHandler">
1410 XML_SetNotationDeclHandler(XML_Parser p,
1411                            XML_NotationDeclHandler h)
1412 </pre>
1413 <pre class="signature">
1414 typedef void
1415 (*XML_NotationDeclHandler)(void *userData,
1416                            const XML_Char *notationName,
1417                            const XML_Char *base,
1418                            const XML_Char *systemId,
1419                            const XML_Char *publicId);
1420 </pre>
1421 <p>Set a handler that receives notation declarations.</p>
1422 </div>
1423
1424 <div class="handler">
1425 <pre class="setter" id="XML_SetNotStandaloneHandler">
1426 XML_SetNotStandaloneHandler(XML_Parser p,
1427                             XML_NotStandaloneHandler h)
1428 </pre>
1429 <pre class="signature">
1430 typedef int 
1431 (*XML_NotStandaloneHandler)(void *userData);
1432 </pre>
1433 <p>Set a handler that is called if the document is not "standalone".
1434 This happens when there is an external subset or a reference to a
1435 parameter entity, but does not have standalone set to "yes" in an XML
1436 declaration.  If this handler returns <code>XML_STATUS_ERROR</code>,
1437 then the parser will throw an <code>XML_ERROR_NOT_STANDALONE</code>
1438 error.</p>
1439 </div>
1440
1441 <h3><a name="position">Parse position and error reporting functions</a></h3>
1442
1443 <p>These are the functions you'll want to call when the parse
1444 functions return <code>XML_STATUS_ERROR</code> (a parse error has
1445 occurred), although the position reporting functions are useful outside
1446 of errors. The position reported is the byte position (in the original
1447 document or entity encoding) of the first of the sequence of
1448 characters that generated the current event (or the error that caused
1449 the parse functions to return <code>XML_STATUS_ERROR</code>.)  The
1450 exceptions are callbacks trigged by declarations in the document
1451 prologue, in which case they exact position reported is somewhere in the
1452 relevant markup, but not necessarily as meaningful as for other
1453 events.</p>
1454
1455 <p>The position reporting functions are accurate only outside of the
1456 DTD.  In other words, they usually return bogus information when
1457 called from within a DTD declaration handler.</p>
1458
1459 <pre class="fcndec" id="XML_GetErrorCode">
1460 enum XML_Error
1461 XML_GetErrorCode(XML_Parser p);
1462 </pre>
1463 <div class="fcndef">
1464 Return what type of error has occurred.
1465 </div>
1466
1467 <pre class="fcndec" id="XML_ErrorString">
1468 const XML_LChar *
1469 XML_ErrorString(enum XML_Error code);
1470 </pre>
1471 <div class="fcndef">
1472 Return a string describing the error corresponding to code.
1473 The code should be one of the enums that can be returned from
1474 <code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>.
1475 </div>
1476
1477 <pre class="fcndec" id="XML_GetCurrentByteIndex">
1478 long
1479 XML_GetCurrentByteIndex(XML_Parser p);
1480 </pre>
1481 <div class="fcndef">
1482 Return the byte offset of the position.  This always corresponds to
1483 the values returned by <code><a href= "#XML_GetCurrentLineNumber"
1484 >XML_GetCurrentLineNumber</a></code> and <code><a href=
1485 "#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>.
1486 </div>
1487
1488 <pre class="fcndec" id="XML_GetCurrentLineNumber">
1489 int
1490 XML_GetCurrentLineNumber(XML_Parser p);
1491 </pre>
1492 <div class="fcndef">
1493 Return the line number of the position.  The first line is reported as
1494 <code>1</code>.
1495 </div>
1496
1497 <pre class="fcndec" id="XML_GetCurrentColumnNumber">
1498 int
1499 XML_GetCurrentColumnNumber(XML_Parser p);
1500 </pre>
1501 <div class="fcndef">
1502 Return the offset, from the beginning of the current line, of
1503 the position.
1504 </div>
1505
1506 <pre class="fcndec" id="XML_GetCurrentByteCount">
1507 int
1508 XML_GetCurrentByteCount(XML_Parser p);
1509 </pre>
1510 <div class="fcndef">
1511 Return the number of bytes in the current event. Returns
1512 <code>0</code> if the event is inside a reference to an internal
1513 entity and for the end-tag event for empty element tags (the later can
1514 be used to distinguish empty-element tags from empty elements using
1515 separate start and end tags).
1516 </div>
1517
1518 <pre class="fcndec" id="XML_GetInputContext">
1519 const char *
1520 XML_GetInputContext(XML_Parser p,
1521                     int *offset,
1522                     int *size);
1523 </pre>
1524 <div class="fcndef">
1525
1526 <p>Returns the parser's input buffer, sets the integer pointed at by
1527 <code>offset</code> to the offset within this buffer of the current
1528 parse position, and set the integer pointed at by <code>size</code> to
1529 the size of the returned buffer.</p>
1530
1531 <p>This should only be called from within a handler during an active
1532 parse and the returned buffer should only be referred to from within
1533 the handler that made the call. This input buffer contains the
1534 untranslated bytes of the input.</p>
1535
1536 <p>Only a limited amount of context is kept, so if the event
1537 triggering a call spans over a very large amount of input, the actual
1538 parse position may be before the beginning of the buffer.</p>
1539 </div>
1540
1541 <h3><a name="miscellaneous">Miscellaneous functions</a></h3>
1542
1543 <p>The functions in this section either obtain state information from
1544 the parser or can be used to dynamicly set parser options.</p>
1545
1546 <pre class="fcndec" id="XML_SetUserData">
1547 void
1548 XML_SetUserData(XML_Parser p,
1549                 void *userData);
1550 </pre>
1551 <div class="fcndef">
1552 This sets the user data pointer that gets passed to handlers.  It
1553 overwrites any previous value for this pointer. Note that the
1554 application is responsible for freeing the memory associated with
1555 <code>userData</code> when it is finished with the parser. So if you
1556 call this when there's already a pointer there, and you haven't freed
1557 the memory associated with it, then you've probably just leaked
1558 memory.
1559 </div>
1560
1561 <pre class="fcndec" id="XML_GetUserData">
1562 void *
1563 XML_GetUserData(XML_Parser p);
1564 </pre>
1565 <div class="fcndef">
1566 This returns the user data pointer that gets passed to handlers.
1567 It is actually implemented as a macro.
1568 </div>
1569
1570 <pre class="fcndec" id="XML_UseParserAsHandlerArg">
1571 void
1572 XML_UseParserAsHandlerArg(XML_Parser p);
1573 </pre>
1574 <div class="fcndef">
1575 After this is called, handlers receive the parser in their
1576 <code>userData</code> arguments.  The user data can still be obtained
1577 using the <code><a href= "#XML_GetUserData"
1578 >XML_GetUserData</a></code> function.
1579 </div>
1580
1581 <pre class="fcndec" id="XML_SetBase">
1582 enum XML_Status
1583 XML_SetBase(XML_Parser p,
1584             const XML_Char *base);
1585 </pre>
1586 <div class="fcndef">
1587 Set the base to be used for resolving relative URIs in system
1588 identifiers.  The return value is <code>XML_STATUS_ERROR</code> if
1589 there's no memory to store base, otherwise it's
1590 <code>XML_STATUS_OK</code>.
1591 </div>
1592
1593 <pre class="fcndec" id="XML_GetBase">
1594 const XML_Char *
1595 XML_GetBase(XML_Parser p);
1596 </pre>
1597 <div class="fcndef">
1598 Return the base for resolving relative URIs.
1599 </div>
1600
1601 <pre class="fcndec" id="XML_GetSpecifiedAttributeCount">
1602 int
1603 XML_GetSpecifiedAttributeCount(XML_Parser p);
1604 </pre>
1605 <div class="fcndef">
1606 When attributes are reported to the start handler in the atts vector,
1607 attributes that were explicitly set in the element occur before any
1608 attributes that receive their value from default information in an
1609 ATTLIST declaration. This function returns the number of attributes
1610 that were explicitly set times two, thus giving the offset in the
1611 <code>atts</code> array passed to the start tag handler of the first
1612 attribute set due to defaults. It supplies information for the last
1613 call to a start handler. If called inside a start handler, then that
1614 means the current call.
1615 </div>
1616
1617 <pre class="fcndec" id="XML_GetIdAttributeIndex">
1618 int
1619 XML_GetIdAttributeIndex(XML_Parser p);
1620 </pre>
1621 <div class="fcndef">
1622 Returns the index of the ID attribute passed in the atts array in the
1623 last call to <code><a href= "#XML_StartElementHandler"
1624 >XML_StartElementHandler</a></code>, or -1 if there is no ID
1625 attribute. If called inside a start handler, then that means the
1626 current call.
1627 </div>
1628
1629 <pre class="fcndec" id="XML_SetEncoding">
1630 enum XML_Status
1631 XML_SetEncoding(XML_Parser p,
1632                 const XML_Char *encoding);
1633 </pre>
1634 <div class="fcndef">
1635 Set the encoding to be used by the parser. It is equivalent to
1636 passing a non-null encoding argument to the parser creation functions.
1637 It must not be called after <code><a href= "#XML_Parse"
1638 >XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
1639 >XML_ParseBuffer</a></code> have been called on the given parser.
1640 Returns <code>XML_STATUS_OK</code> on success or
1641 <code>XML_STATUS_ERROR</code> on error.
1642 </div>
1643
1644 <pre class="fcndec" id="XML_SetParamEntityParsing">
1645 int
1646 XML_SetParamEntityParsing(XML_Parser p,
1647                           enum XML_ParamEntityParsing code);
1648 </pre>
1649 <div class="fcndef">
1650 This enables parsing of parameter entities, including the external
1651 parameter entity that is the external DTD subset, according to
1652 <code>code</code>.
1653 The choices for <code>code</code> are:
1654 <ul>
1655 <li><code>XML_PARAM_ENTITY_PARSING_NEVER</code></li>
1656 <li><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></li>
1657 <li><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></li>
1658 </ul>
1659 </div>
1660
1661 <pre class="fcndec" id="XML_UseForeignDTD">
1662 enum XML_Error
1663 XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
1664 </pre>
1665 <div class="fcndef">
1666 <p>This function allows an application to provide an external subset
1667 for the document type declaration for documents which do not specify
1668 an external subset of their own.  For documents which specify an
1669 external subset in their DOCTYPE declaration, the application-provided
1670 subset will be ignored.  If the document does not contain a DOCTYPE
1671 declaration at all and <code>useDTD</code> is true, the
1672 application-provided subset will be parsed, but the
1673 <code>startDoctypeDeclHandler</code> and
1674 <code>endDoctypeDeclHandler</code> functions, if set, will not be
1675 called.  The setting of parameter entity parsing, controlled using
1676 <code><a href= "#XML_SetParamEntityParsing"
1677 >XML_SetParamEntityParsing</a></code>, will be honored.</p>
1678
1679 <p>The application-provided external subset is read by calling the
1680 external entity reference handler set via <code><a href=
1681 "#XML_SetExternalEntityRefHandler"
1682 >XML_SetExternalEntityRefHandler</a></code> with both
1683 <code>publicId</code> and <code>systemId</code> set to NULL.</p>
1684
1685 <p>If this function is called after parsing has begun, it returns
1686 <code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores
1687 <code>useDTD</code>.  If called when Expat has been compiled without
1688 DTD support, it returns
1689 <code>XML_ERROR_FEATURE_REQUIRES_XML_DTD</code>.  Otherwise, it
1690 returns <code>XML_ERROR_NONE</code>.</p>
1691 </div>
1692
1693 <pre class="fcndec" id="XML_SetReturnNSTriplet">
1694 void
1695 XML_SetReturnNSTriplet(XML_Parser parser,
1696                        int        do_nst);
1697 </pre>
1698 <div class="fcndef">
1699 <p>
1700 This function only has an effect when using a parser created with
1701 <code><a href= "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>,
1702 i.e. when namespace processing is in effect. The <code>do_nst</code>
1703 sets whether or not prefixes are returned with names qualified with a
1704 namespace prefix. If this function is called with <code>do_nst</code>
1705 non-zero, then afterwards namespace qualified names (that is qualified
1706 with a prefix as opposed to belonging to a default namespace) are
1707 returned as a triplet with the three parts separated by the namespace
1708 separator specified when the parser was created.  The order of
1709 returned parts is URI, local name, and prefix.</p> <p>If
1710 <code>do_nst</code> is zero, then namespaces are reported in the
1711 default manner, URI then local_name separated by the namespace
1712 separator.</p>
1713 </div>
1714
1715 <pre class="fcndec" id="XML_DefaultCurrent">
1716 void
1717 XML_DefaultCurrent(XML_Parser parser);
1718 </pre>
1719 <div class="fcndef">
1720 This can be called within a handler for a start element, end element,
1721 processing instruction or character data.  It causes the corresponding
1722 markup to be passed to the default handler set by <code><a
1723 href="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or
1724 <code><a href="#XML_SetDefaultHandlerExpand"
1725 >XML_SetDefaultHandlerExpand</a></code>.  It does nothing if there is
1726 not a default handler.
1727 </div>
1728
1729 <pre class="fcndec" id="XML_ExpatVersion">
1730 XML_LChar *
1731 XML_ExpatVersion();
1732 </pre>
1733 <div class="fcndef">
1734 Return the library version as a string (e.g. <code>"expat_1.95.1"</code>).
1735 </div>
1736
1737 <pre class="fcndec" id="XML_ExpatVersionInfo">
1738 struct XML_Expat_Version
1739 XML_ExpatVersionInfo();
1740 </pre>
1741 <pre class="signature">
1742 typedef struct {
1743   int major;
1744   int minor;
1745   int micro;
1746 } XML_Expat_Version;
1747 </pre>
1748 <div class="fcndef">
1749 Return the library version information as a structure.
1750 Some macros are also defined that support compile-time tests of the
1751 library version:
1752 <ul>
1753 <li><code>XML_MAJOR_VERSION</code></li>
1754 <li><code>XML_MINOR_VERSION</code></li>
1755 <li><code>XML_MICRO_VERSION</code></li>
1756 </ul>
1757 Testing these constants is currently the best way to determine if
1758 particular parts of the Expat API are available.
1759 </div>
1760
1761 <pre class="fcndec" id="XML_GetFeatureList">
1762 const XML_Feature *
1763 XML_GetFeatureList();
1764 </pre>
1765 <pre class="signature">
1766 enum XML_FeatureEnum {
1767   XML_FEATURE_END = 0,
1768   XML_FEATURE_UNICODE,
1769   XML_FEATURE_UNICODE_WCHAR_T,
1770   XML_FEATURE_DTD,
1771   XML_FEATURE_CONTEXT_BYTES,
1772   XML_FEATURE_MIN_SIZE,
1773   XML_FEATURE_SIZEOF_XML_CHAR,
1774   XML_FEATURE_SIZEOF_XML_LCHAR
1775 };
1776
1777 typedef struct {
1778   enum XML_FeatureEnum  feature;
1779   XML_LChar            *name;
1780   long int              value;
1781 } XML_Feature;
1782 </pre>
1783 <div class="fcndef">
1784 <p>Returns a list of "feature" records, providing details on how
1785 Expat was configured at compile time.  Most applications should not
1786 need to worry about this, but this information is otherwise not
1787 available from Expat.  This function allows code that does need to
1788 check these features to do so at runtime.</p>
1789
1790 <p>The return value is an array of <code>XML_Feature</code>,
1791 terminated by a record with a <code>feature</code> of
1792 <code>XML_FEATURE_END</code> and <code>name</code> of NULL,
1793 identifying the feature-test macros Expat was compiled with.  Since an
1794 application that requires this kind of information needs to determine
1795 the type of character the <code>name</code> points to, records for the
1796 <code>XML_FEATURE_SIZEOF_XML_CHAR</code> and
1797 <code>XML_FEATURE_SIZEOF_XML_LCHAR</code> will be located at the
1798 beginning of the list, followed by <code>XML_FEATURE_UNICODE</code>
1799 and <code>XML_FEATURE_UNICODE_WCHAR_T</code>, if they are present at
1800 all.</p>
1801
1802 <p>Some features have an associated value.  If there isn't an
1803 associated value, the <code>value</code> field is set to 0.  At this
1804 time, the following features have been defined to have values:</p>
1805
1806 <dl>
1807   <dt><code>XML_FEATURE_SIZEOF_XML_CHAR</code></dt>
1808   <dd>The number of bytes occupied by one <code>XML_Char</code>
1809   character.</dd>
1810   <dt><code>XML_FEATURE_SIZEOF_XML_LCHAR</code></dt>
1811   <dd>The number of bytes occupied by one <code>XML_LChar</code>
1812   character.</dd>
1813   <dt><code>XML_FEATURE_CONTEXT_BYTES</code></dt>
1814   <dd>The maximum number of characters of context which can be
1815   reported by <code><a href= "#XML_GetInputContext"
1816   >XML_GetInputContext</a></code>.</dd>
1817 </dl>
1818 </div>
1819
1820 <pre class="fcndec" id="XML_FreeContentModel">
1821 void
1822 XML_FreeContentModel(XML_Parser parser, XML_Content *model);
1823 </pre>
1824 <div class="fcndef">
1825 Function to deallocate the <code>model</code> argument passed to the
1826 <code>XML_ElementDeclHandler</code> callback set using <code><a
1827 href="#XML_SetElementDeclHandler" >XML_ElementDeclHandler</a></code>.
1828 This function should not be used for any other purpose.
1829 </div>
1830
1831 <p>The following functions allow external code to share the memory
1832 allocator an <code>XML_Parser</code> has been configured to use.  This
1833 is especially useful for third-party libraries that interact with a
1834 parser object created by application code, or heavily layered
1835 applications.  This can be essential when using dynamically loaded
1836 libraries which use different C standard libraries (this can happen on
1837 Windows, at least).</p>
1838
1839 <pre class="fcndec" id="XML_MemMalloc">
1840 void *
1841 XML_MemMalloc(XML_Parser parser, size_t size);
1842 </pre>
1843 <div class="fcndef">
1844 Allocate <code>size</code> bytes of memory using the allocator the
1845 <code>parser</code> object has been configured to use.  Returns a
1846 pointer to the memory or NULL on failure.  Memory allocated in this
1847 way must be freed using <code><a href="#XML_MemFree"
1848 >XML_MemFree</a></code>.
1849 </div>
1850
1851 <pre class="fcndec" id="XML_MemRealloc">
1852 void *
1853 XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
1854 </pre>
1855 <div class="fcndef">
1856 Allocate <code>size</code> bytes of memory using the allocator the
1857 <code>parser</code> object has been configured to use.
1858 <code>ptr</code> must point to a block of memory allocated by <code><a
1859 href="#XML_MemMalloc" >XML_MemMalloc</a></code> or
1860 <code>XML_MemRealloc</code>, or be NULL.  This function tries to
1861 expand the block pointed to by <code>ptr</code> if possible.  Returns
1862 a pointer to the memory or NULL on failure.  On success, the original
1863 block has either been expanded or freed.  On failure, the original
1864 block has not been freed; the caller is responsible for freeing the
1865 original block.  Memory allocated in this way must be freed using
1866 <code><a href="#XML_MemFree"
1867 >XML_MemFree</a></code>.
1868 </div>
1869
1870 <pre class="fcndec" id="XML_MemFree">
1871 void
1872 XML_MemFree(XML_Parser parser, void *ptr);
1873 </pre>
1874 <div class="fcndef">
1875 Free a block of memory pointed to by <code>ptr</code>.  The block must
1876 have been allocated by <code><a href="#XML_MemMalloc"
1877 >XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be NULL.
1878 </div>
1879
1880 <hr />
1881 <p><a href="http://validator.w3.org/check/referer"><img
1882         src="valid-xhtml10.png" alt="Valid XHTML 1.0!"
1883         height="31" width="88" class="noborder" /></a></p>
1884 </body>
1885 </html>