xref: /freebsd/contrib/expat/doc/reference.html (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
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  <table cellspacing="0" cellpadding="0" width="100%">
17    <tr>
18      <td class="corner"><img src="expat.png" alt="(Expat logo)" /></td>
19      <td class="banner"><h1>The Expat XML Parser</h1></td>
20    </tr>
21    <tr>
22      <td class="releaseno">Release 2.0.1</td>
23      <td></td>
24    </tr>
25  </table>
26<div class="content">
27
28<p>Expat is a library, written in C, for parsing XML documents. It's
29the underlying XML parser for the open source Mozilla project, Perl's
30<code>XML::Parser</code>, Python's <code>xml.parsers.expat</code>, and
31other open-source XML parsers.</p>
32
33<p>This library is the creation of James Clark, who's also given us
34groff (an nroff look-alike), Jade (an implementation of ISO's DSSSL
35stylesheet language for SGML), XP (a Java XML parser package), XT (a
36Java XSL engine).  James was also the technical lead on the XML
37Working Group at W3C that produced the XML specification.</p>
38
39<p>This is free software, licensed under the <a
40href="../COPYING">MIT/X Consortium license</a>. You may download it
41from <a href="http://www.libexpat.org/">the Expat home page</a>.
42</p>
43
44<p>The bulk of this document was originally commissioned as an article
45by <a href="http://www.xml.com/">XML.com</a>. They graciously allowed
46Clark Cooper to retain copyright and to distribute it with Expat.
47This version has been substantially extended to include documentation
48on features which have been added since the original article was
49published, and additional information on using the original
50interface.</p>
51
52<hr />
53<h2>Table of Contents</h2>
54<ul>
55  <li><a href="#overview">Overview</a></li>
56  <li><a href="#building">Building and Installing</a></li>
57  <li><a href="#using">Using Expat</a></li>
58  <li><a href="#reference">Reference</a>
59  <ul>
60    <li><a href="#creation">Parser Creation Functions</a>
61    <ul>
62      <li><a href="#XML_ParserCreate">XML_ParserCreate</a></li>
63      <li><a href="#XML_ParserCreateNS">XML_ParserCreateNS</a></li>
64      <li><a href="#XML_ParserCreate_MM">XML_ParserCreate_MM</a></li>
65      <li><a href="#XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</a></li>
66      <li><a href="#XML_ParserFree">XML_ParserFree</a></li>
67      <li><a href="#XML_ParserReset">XML_ParserReset</a></li>
68    </ul>
69    </li>
70    <li><a href="#parsing">Parsing Functions</a>
71    <ul>
72      <li><a href="#XML_Parse">XML_Parse</a></li>
73      <li><a href="#XML_ParseBuffer">XML_ParseBuffer</a></li>
74      <li><a href="#XML_GetBuffer">XML_GetBuffer</a></li>
75      <li><a href="#XML_StopParser">XML_StopParser</a></li>
76      <li><a href="#XML_ResumeParser">XML_ResumeParser</a></li>
77      <li><a href="#XML_GetParsingStatus">XML_GetParsingStatus</a></li>
78    </ul>
79    </li>
80    <li><a href="#setting">Handler Setting Functions</a>
81    <ul>
82      <li><a href="#XML_SetStartElementHandler">XML_SetStartElementHandler</a></li>
83      <li><a href="#XML_SetEndElementHandler">XML_SetEndElementHandler</a></li>
84      <li><a href="#XML_SetElementHandler">XML_SetElementHandler</a></li>
85      <li><a href="#XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</a></li>
86      <li><a href="#XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</a></li>
87      <li><a href="#XML_SetCommentHandler">XML_SetCommentHandler</a></li>
88      <li><a href="#XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</a></li>
89      <li><a href="#XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</a></li>
90      <li><a href="#XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</a></li>
91      <li><a href="#XML_SetDefaultHandler">XML_SetDefaultHandler</a></li>
92      <li><a href="#XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</a></li>
93      <li><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></li>
94      <li><a href="#XML_SetExternalEntityRefHandlerArg">XML_SetExternalEntityRefHandlerArg</a></li>
95      <li><a href="#XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</a></li>
96      <li><a href="#XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</a></li>
97      <li><a href="#XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</a></li>
98      <li><a href="#XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</a></li>
99      <li><a href="#XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</a></li>
100      <li><a href="#XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</a></li>
101      <li><a href="#XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</a></li>
102      <li><a href="#XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</a></li>
103      <li><a href="#XML_SetDoctypeDeclHandler">XML_SetDoctypeDeclHandler</a></li>
104      <li><a href="#XML_SetElementDeclHandler">XML_SetElementDeclHandler</a></li>
105      <li><a href="#XML_SetAttlistDeclHandler">XML_SetAttlistDeclHandler</a></li>
106      <li><a href="#XML_SetEntityDeclHandler">XML_SetEntityDeclHandler</a></li>
107      <li><a href="#XML_SetUnparsedEntityDeclHandler">XML_SetUnparsedEntityDeclHandler</a></li>
108      <li><a href="#XML_SetNotationDeclHandler">XML_SetNotationDeclHandler</a></li>
109      <li><a href="#XML_SetNotStandaloneHandler">XML_SetNotStandaloneHandler</a></li>
110    </ul>
111    </li>
112    <li><a href="#position">Parse Position and Error Reporting Functions</a>
113    <ul>
114      <li><a href="#XML_GetErrorCode">XML_GetErrorCode</a></li>
115      <li><a href="#XML_ErrorString">XML_ErrorString</a></li>
116      <li><a href="#XML_GetCurrentByteIndex">XML_GetCurrentByteIndex</a></li>
117      <li><a href="#XML_GetCurrentLineNumber">XML_GetCurrentLineNumber</a></li>
118      <li><a href="#XML_GetCurrentColumnNumber">XML_GetCurrentColumnNumber</a></li>
119      <li><a href="#XML_GetCurrentByteCount">XML_GetCurrentByteCount</a></li>
120      <li><a href="#XML_GetInputContext">XML_GetInputContext</a></li>
121    </ul>
122    </li>
123    <li><a href="#miscellaneous">Miscellaneous Functions</a>
124    <ul>
125      <li><a href="#XML_SetUserData">XML_SetUserData</a></li>
126      <li><a href="#XML_GetUserData">XML_GetUserData</a></li>
127      <li><a href="#XML_UseParserAsHandlerArg">XML_UseParserAsHandlerArg</a></li>
128      <li><a href="#XML_SetBase">XML_SetBase</a></li>
129      <li><a href="#XML_GetBase">XML_GetBase</a></li>
130      <li><a href="#XML_GetSpecifiedAttributeCount">XML_GetSpecifiedAttributeCount</a></li>
131      <li><a href="#XML_GetIdAttributeIndex">XML_GetIdAttributeIndex</a></li>
132      <li><a href="#XML_GetAttributeInfo">XML_GetAttributeInfo</a></li>
133      <li><a href="#XML_SetEncoding">XML_SetEncoding</a></li>
134      <li><a href="#XML_SetParamEntityParsing">XML_SetParamEntityParsing</a></li>
135      <li><a href="#XML_SetHashSalt">XML_SetHashSalt</a></li>
136      <li><a href="#XML_UseForeignDTD">XML_UseForeignDTD</a></li>
137      <li><a href="#XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a></li>
138      <li><a href="#XML_DefaultCurrent">XML_DefaultCurrent</a></li>
139      <li><a href="#XML_ExpatVersion">XML_ExpatVersion</a></li>
140      <li><a href="#XML_ExpatVersionInfo">XML_ExpatVersionInfo</a></li>
141      <li><a href="#XML_GetFeatureList">XML_GetFeatureList</a></li>
142      <li><a href="#XML_FreeContentModel">XML_FreeContentModel</a></li>
143      <li><a href="#XML_MemMalloc">XML_MemMalloc</a></li>
144      <li><a href="#XML_MemRealloc">XML_MemRealloc</a></li>
145      <li><a href="#XML_MemFree">XML_MemFree</a></li>
146    </ul>
147    </li>
148  </ul>
149  </li>
150</ul>
151
152<hr />
153<h2><a name="overview">Overview</a></h2>
154
155<p>Expat is a stream-oriented parser. You register callback (or
156handler) functions with the parser and then start feeding it the
157document.  As the parser recognizes parts of the document, it will
158call the appropriate handler for that part (if you've registered one.)
159The document is fed to the parser in pieces, so you can start parsing
160before you have all the document. This also allows you to parse really
161huge documents that won't fit into memory.</p>
162
163<p>Expat can be intimidating due to the many kinds of handlers and
164options you can set. But you only need to learn four functions in
165order to do 90% of what you'll want to do with it:</p>
166
167<dl>
168
169<dt><code><a href= "#XML_ParserCreate"
170             >XML_ParserCreate</a></code></dt>
171  <dd>Create a new parser object.</dd>
172
173<dt><code><a href= "#XML_SetElementHandler"
174             >XML_SetElementHandler</a></code></dt>
175  <dd>Set handlers for start and end tags.</dd>
176
177<dt><code><a href= "#XML_SetCharacterDataHandler"
178             >XML_SetCharacterDataHandler</a></code></dt>
179  <dd>Set handler for text.</dd>
180
181<dt><code><a href= "#XML_Parse"
182             >XML_Parse</a></code></dt>
183  <dd>Pass a buffer full of document to the parser</dd>
184</dl>
185
186<p>These functions and others are described in the <a
187href="#reference">reference</a> part of this document. The reference
188section also describes in detail the parameters passed to the
189different types of handlers.</p>
190
191<p>Let's look at a very simple example program that only uses 3 of the
192above functions (it doesn't need to set a character handler.) The
193program <a href="../examples/outline.c">outline.c</a> prints an
194element outline, indenting child elements to distinguish them from the
195parent element that contains them. The start handler does all the
196work.  It prints two indenting spaces for every level of ancestor
197elements, then it prints the element and attribute
198information. Finally it increments the global <code>Depth</code>
199variable.</p>
200
201<pre class="eg">
202int Depth;
203
204void XMLCALL
205start(void *data, const char *el, const char **attr) {
206  int i;
207
208  for (i = 0; i &lt; Depth; i++)
209    printf("  ");
210
211  printf("%s", el);
212
213  for (i = 0; attr[i]; i += 2) {
214    printf(" %s='%s'", attr[i], attr[i + 1]);
215  }
216
217  printf("\n");
218  Depth++;
219}  /* End of start handler */
220</pre>
221
222<p>The end tag simply does the bookkeeping work of decrementing
223<code>Depth</code>.</p>
224<pre class="eg">
225void XMLCALL
226end(void *data, const char *el) {
227  Depth--;
228}  /* End of end handler */
229</pre>
230
231<p>Note the <code>XMLCALL</code> annotation used for the callbacks.
232This is used to ensure that the Expat and the callbacks are using the
233same calling convention in case the compiler options used for Expat
234itself and the client code are different.  Expat tries not to care
235what the default calling convention is, though it may require that it
236be compiled with a default convention of "cdecl" on some platforms.
237For code which uses Expat, however, the calling convention is
238specified by the <code>XMLCALL</code> annotation on most platforms;
239callbacks should be defined using this annotation.</p>
240
241<p>The <code>XMLCALL</code> annotation was added in Expat 1.95.7, but
242existing working Expat applications don't need to add it (since they
243are already using the "cdecl" calling convention, or they wouldn't be
244working).  The annotation is only needed if the default calling
245convention may be something other than "cdecl".  To use the annotation
246safely with older versions of Expat, you can conditionally define it
247<em>after</em> including Expat's header file:</p>
248
249<pre class="eg">
250#include &lt;expat.h&gt;
251
252#ifndef XMLCALL
253#if defined(_MSC_EXTENSIONS) &amp;&amp; !defined(__BEOS__) &amp;&amp; !defined(__CYGWIN__)
254#define XMLCALL __cdecl
255#elif defined(__GNUC__)
256#define XMLCALL __attribute__((cdecl))
257#else
258#define XMLCALL
259#endif
260#endif
261</pre>
262
263<p>After creating the parser, the main program just has the job of
264shoveling the document to the parser so that it can do its work.</p>
265
266<hr />
267<h2><a name="building">Building and Installing Expat</a></h2>
268
269<p>The Expat distribution comes as a compressed (with GNU gzip) tar
270file.  You may download the latest version from <a href=
271"http://sourceforge.net/projects/expat/" >Source Forge</a>.  After
272unpacking this, cd into the directory. Then follow either the Win32
273directions or Unix directions below.</p>
274
275<h3>Building under Win32</h3>
276
277<p>If you're using the GNU compiler under cygwin, follow the Unix
278directions in the next section. Otherwise if you have Microsoft's
279Developer Studio installed,
280you can use CMake to generate a <code>.sln</code> file, e.g.
281<code>
282cmake -G"Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=RelWithDebInfo .
283</code>, and build Expat using <code>msbuild /m expat.sln</code> after.</p>
284
285<p>Alternatively, you may download the Win32 binary package that
286contains the "expat.h" include file and a pre-built DLL.</p>
287
288<h3>Building under Unix (or GNU)</h3>
289
290<p>First you'll need to run the configure shell script in order to
291configure the Makefiles and headers for your system.</p>
292
293<p>If you're happy with all the defaults that configure picks for you,
294and you have permission on your system to install into /usr/local, you
295can install Expat with this sequence of commands:</p>
296
297<pre class="eg">
298./configure
299make
300make install
301</pre>
302
303<p>There are some options that you can provide to this script, but the
304only one we'll mention here is the <code>--prefix</code> option. You
305can find out all the options available by running configure with just
306the <code>--help</code> option.</p>
307
308<p>By default, the configure script sets things up so that the library
309gets installed in <code>/usr/local/lib</code> and the associated
310header file in <code>/usr/local/include</code>.  But if you were to
311give the option, <code>--prefix=/home/me/mystuff</code>, then the
312library and header would get installed in
313<code>/home/me/mystuff/lib</code> and
314<code>/home/me/mystuff/include</code> respectively.</p>
315
316<h3>Configuring Expat Using the Pre-Processor</h3>
317
318<p>Expat's feature set can be configured using a small number of
319pre-processor definitions.  The definition of this symbols does not
320affect the set of entry points for Expat, only the behavior of the API
321and the definition of character types in the case of
322<code>XML_UNICODE_WCHAR_T</code>.  The symbols are:</p>
323
324<dl class="cpp-symbols">
325<dt>XML_DTD</dt>
326<dd>Include support for using and reporting DTD-based content.  If
327this is defined, default attribute values from an external DTD subset
328are reported and attribute value normalization occurs based on the
329type of attributes defined in the external subset.  Without
330this, Expat has a smaller memory footprint and can be faster, but will
331not load external entities or process conditional sections.  This does
332not affect the set of functions available in the API.</dd>
333
334<dt>XML_NS</dt>
335<dd>When defined, support for the <cite><a href=
336"http://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite>
337specification is included.</dd>
338
339<dt>XML_UNICODE</dt>
340<dd>When defined, character data reported to the application is
341encoded in UTF-16 using wide characters of the type
342<code>XML_Char</code>.  This is implied if
343<code>XML_UNICODE_WCHAR_T</code> is defined.</dd>
344
345<dt>XML_UNICODE_WCHAR_T</dt>
346<dd>If defined, causes the <code>XML_Char</code> character type to be
347defined using the <code>wchar_t</code> type; otherwise, <code>unsigned
348short</code> is used.  Defining this implies
349<code>XML_UNICODE</code>.</dd>
350
351<dt>XML_LARGE_SIZE</dt>
352<dd>If defined, causes the <code>XML_Size</code> and <code>XML_Index</code>
353integer types to be at least 64 bits in size. This is intended to support
354processing of very large input streams, where the return values of
355<code><a href="#XML_GetCurrentByteIndex" >XML_GetCurrentByteIndex</a></code>,
356<code><a href="#XML_GetCurrentLineNumber" >XML_GetCurrentLineNumber</a></code> and
357<code><a href="#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>
358could overflow. It may not be supported by all compilers, and is turned
359off by default.</dd>
360
361<dt>XML_CONTEXT_BYTES</dt>
362<dd>The number of input bytes of markup context which the parser will
363ensure are available for reporting via <code><a href=
364"#XML_GetInputContext" >XML_GetInputContext</a></code>.  This is
365normally set to 1024, and must be set to a positive integer.  If this
366is not defined, the input context will not be available and <code><a
367href= "#XML_GetInputContext" >XML_GetInputContext</a></code> will
368always report NULL.  Without this, Expat has a smaller memory
369footprint and can be faster.</dd>
370
371<dt>XML_STATIC</dt>
372<dd>On Windows, this should be set if Expat is going to be linked
373statically with the code that calls it; this is required to get all
374the right MSVC magic annotations correct.  This is ignored on other
375platforms.</dd>
376
377<dt>XML_ATTR_INFO</dt>
378<dd>If defined, makes the additional function <code><a href=
379"#XML_GetAttributeInfo" >XML_GetAttributeInfo</a></code> available
380for reporting attribute byte offsets.</dd>
381</dl>
382
383<hr />
384<h2><a name="using">Using Expat</a></h2>
385
386<h3>Compiling and Linking Against Expat</h3>
387
388<p>Unless you installed Expat in a location not expected by your
389compiler and linker, all you have to do to use Expat in your programs
390is to include the Expat header (<code>#include &lt;expat.h&gt;</code>)
391in your files that make calls to it and to tell the linker that it
392needs to link against the Expat library.  On Unix systems, this would
393usually be done with the <code>-lexpat</code> argument.  Otherwise,
394you'll need to tell the compiler where to look for the Expat header
395and the linker where to find the Expat library.  You may also need to
396take steps to tell the operating system where to find this library at
397run time.</p>
398
399<p>On a Unix-based system, here's what a Makefile might look like when
400Expat is installed in a standard location:</p>
401
402<pre class="eg">
403CC=cc
404LDFLAGS=
405LIBS= -lexpat
406xmlapp: xmlapp.o
407        $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
408</pre>
409
410<p>If you installed Expat in, say, <code>/home/me/mystuff</code>, then
411the Makefile would look like this:</p>
412
413<pre class="eg">
414CC=cc
415CFLAGS= -I/home/me/mystuff/include
416LDFLAGS=
417LIBS= -L/home/me/mystuff/lib -lexpat
418xmlapp: xmlapp.o
419        $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
420</pre>
421
422<p>You'd also have to set the environment variable
423<code>LD_LIBRARY_PATH</code> to <code>/home/me/mystuff/lib</code> (or
424to <code>${LD_LIBRARY_PATH}:/home/me/mystuff/lib</code> if
425LD_LIBRARY_PATH already has some directories in it) in order to run
426your application.</p>
427
428<h3>Expat Basics</h3>
429
430<p>As we saw in the example in the overview, the first step in parsing
431an XML document with Expat is to create a parser object. There are <a
432href="#creation">three functions</a> in the Expat API for creating a
433parser object.  However, only two of these (<code><a href=
434"#XML_ParserCreate" >XML_ParserCreate</a></code> and <code><a href=
435"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>) can be used for
436constructing a parser for a top-level document.  The object returned
437by these functions is an opaque pointer (i.e. "expat.h" declares it as
438void *) to data with further internal structure. In order to free the
439memory associated with this object you must call <code><a href=
440"#XML_ParserFree" >XML_ParserFree</a></code>. Note that if you have
441provided any <a href="#userdata">user data</a> that gets stored in the
442parser, then your application is responsible for freeing it prior to
443calling <code>XML_ParserFree</code>.</p>
444
445<p>The objects returned by the parser creation functions are good for
446parsing only one XML document or external parsed entity. If your
447application needs to parse many XML documents, then it needs to create
448a parser object for each one. The best way to deal with this is to
449create a higher level object that contains all the default
450initialization you want for your parser objects.</p>
451
452<p>Walking through a document hierarchy with a stream oriented parser
453will require a good stack mechanism in order to keep track of current
454context.  For instance, to answer the simple question, "What element
455does this text belong to?" requires a stack, since the parser may have
456descended into other elements that are children of the current one and
457has encountered this text on the way out.</p>
458
459<p>The things you're likely to want to keep on a stack are the
460currently opened element and it's attributes. You push this
461information onto the stack in the start handler and you pop it off in
462the end handler.</p>
463
464<p>For some tasks, it is sufficient to just keep information on what
465the depth of the stack is (or would be if you had one.) The outline
466program shown above presents one example. Another such task would be
467skipping over a complete element. When you see the start tag for the
468element you want to skip, you set a skip flag and record the depth at
469which the element started.  When the end tag handler encounters the
470same depth, the skipped element has ended and the flag may be
471cleared. If you follow the convention that the root element starts at
4721, then you can use the same variable for skip flag and skip
473depth.</p>
474
475<pre class="eg">
476void
477init_info(Parseinfo *info) {
478  info->skip = 0;
479  info->depth = 1;
480  /* Other initializations here */
481}  /* End of init_info */
482
483void XMLCALL
484rawstart(void *data, const char *el, const char **attr) {
485  Parseinfo *inf = (Parseinfo *) data;
486
487  if (! inf->skip) {
488    if (should_skip(inf, el, attr)) {
489      inf->skip = inf->depth;
490    }
491    else
492      start(inf, el, attr);     /* This does rest of start handling */
493  }
494
495  inf->depth++;
496}  /* End of rawstart */
497
498void XMLCALL
499rawend(void *data, const char *el) {
500  Parseinfo *inf = (Parseinfo *) data;
501
502  inf->depth--;
503
504  if (! inf->skip)
505    end(inf, el);              /* This does rest of end handling */
506
507  if (inf->skip == inf->depth)
508    inf->skip = 0;
509}  /* End rawend */
510</pre>
511
512<p>Notice in the above example the difference in how depth is
513manipulated in the start and end handlers. The end tag handler should
514be the mirror image of the start tag handler. This is necessary to
515properly model containment. Since, in the start tag handler, we
516incremented depth <em>after</em> the main body of start tag code, then
517in the end handler, we need to manipulate it <em>before</em> the main
518body.  If we'd decided to increment it first thing in the start
519handler, then we'd have had to decrement it last thing in the end
520handler.</p>
521
522<h3 id="userdata">Communicating between handlers</h3>
523
524<p>In order to be able to pass information between different handlers
525without using globals, you'll need to define a data structure to hold
526the shared variables. You can then tell Expat (with the <code><a href=
527"#XML_SetUserData" >XML_SetUserData</a></code> function) to pass a
528pointer to this structure to the handlers.  This is the first
529argument received by most handlers.  In the <a href="#reference"
530>reference section</a>, an argument to a callback function is named
531<code>userData</code> and have type <code>void *</code> if the user
532data is passed; it will have the type <code>XML_Parser</code> if the
533parser itself is passed.  When the parser is passed, the user data may
534be retrieved using <code><a href="#XML_GetUserData"
535>XML_GetUserData</a></code>.</p>
536
537<p>One common case where multiple calls to a single handler may need
538to communicate using an application data structure is the case when
539content passed to the character data handler (set by <code><a href=
540"#XML_SetCharacterDataHandler"
541>XML_SetCharacterDataHandler</a></code>) needs to be accumulated.  A
542common first-time mistake with any of the event-oriented interfaces to
543an XML parser is to expect all the text contained in an element to be
544reported by a single call to the character data handler.  Expat, like
545many other XML parsers, reports such data as a sequence of calls;
546there's no way to know when the end of the sequence is reached until a
547different callback is made.  A buffer referenced by the user data
548structure proves both an effective and convenient place to accumulate
549character data.</p>
550
551<!-- XXX example needed here -->
552
553
554<h3>XML Version</h3>
555
556<p>Expat is an XML 1.0 parser, and as such never complains based on
557the value of the <code>version</code> pseudo-attribute in the XML
558declaration, if present.</p>
559
560<p>If an application needs to check the version number (to support
561alternate processing), it should use the <code><a href=
562"#XML_SetXmlDeclHandler" >XML_SetXmlDeclHandler</a></code> function to
563set a handler that uses the information in the XML declaration to
564determine what to do.  This example shows how to check that only a
565version number of <code>"1.0"</code> is accepted:</p>
566
567<pre class="eg">
568static int wrong_version;
569static XML_Parser parser;
570
571static void XMLCALL
572xmldecl_handler(void            *userData,
573                const XML_Char  *version,
574                const XML_Char  *encoding,
575                int              standalone)
576{
577  static const XML_Char Version_1_0[] = {'1', '.', '0', 0};
578
579  int i;
580
581  for (i = 0; i &lt; (sizeof(Version_1_0) / sizeof(Version_1_0[0])); ++i) {
582    if (version[i] != Version_1_0[i]) {
583      wrong_version = 1;
584      /* also clear all other handlers: */
585      XML_SetCharacterDataHandler(parser, NULL);
586      ...
587      return;
588    }
589  }
590  ...
591}
592</pre>
593
594<h3>Namespace Processing</h3>
595
596<p>When the parser is created using the <code><a href=
597"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>, function, Expat
598performs namespace processing. Under namespace processing, Expat
599consumes <code>xmlns</code> and <code>xmlns:...</code> attributes,
600which declare namespaces for the scope of the element in which they
601occur. This means that your start handler will not see these
602attributes.  Your application can still be informed of these
603declarations by setting namespace declaration handlers with <a href=
604"#XML_SetNamespaceDeclHandler"
605><code>XML_SetNamespaceDeclHandler</code></a>.</p>
606
607<p>Element type and attribute names that belong to a given namespace
608are passed to the appropriate handler in expanded form. By default
609this expanded form is a concatenation of the namespace URI, the
610separator character (which is the 2nd argument to <code><a href=
611"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>), and the local
612name (i.e. the part after the colon). Names with undeclared prefixes
613are not well-formed when namespace processing is enabled, and will
614trigger an error. Unprefixed attribute names are never expanded,
615and unprefixed element names are only expanded when they are in the
616scope of a default namespace.</p>
617
618<p>However if <code><a href= "#XML_SetReturnNSTriplet"
619>XML_SetReturnNSTriplet</a></code> has been called with a non-zero
620<code>do_nst</code> parameter, then the expanded form for names with
621an explicit prefix is a concatenation of: URI, separator, local name,
622separator, prefix.</p>
623
624<p>You can set handlers for the start of a namespace declaration and
625for the end of a scope of a declaration with the <code><a href=
626"#XML_SetNamespaceDeclHandler" >XML_SetNamespaceDeclHandler</a></code>
627function.  The StartNamespaceDeclHandler is called prior to the start
628tag handler and the EndNamespaceDeclHandler is called after the
629corresponding end tag that ends the namespace's scope.  The namespace
630start handler gets passed the prefix and URI for the namespace.  For a
631default namespace declaration (xmlns='...'), the prefix will be null.
632The URI will be null for the case where the default namespace is being
633unset.  The namespace end handler just gets the prefix for the closing
634scope.</p>
635
636<p>These handlers are called for each declaration. So if, for
637instance, a start tag had three namespace declarations, then the
638StartNamespaceDeclHandler would be called three times before the start
639tag handler is called, once for each declaration.</p>
640
641<h3>Character Encodings</h3>
642
643<p>While XML is based on Unicode, and every XML processor is required
644to recognized UTF-8 and UTF-16 (1 and 2 byte encodings of Unicode),
645other encodings may be declared in XML documents or entities. For the
646main document, an XML declaration may contain an encoding
647declaration:</p>
648<pre>
649&lt;?xml version="1.0" encoding="ISO-8859-2"?&gt;
650</pre>
651
652<p>External parsed entities may begin with a text declaration, which
653looks like an XML declaration with just an encoding declaration:</p>
654<pre>
655&lt;?xml encoding="Big5"?&gt;
656</pre>
657
658<p>With Expat, you may also specify an encoding at the time of
659creating a parser. This is useful when the encoding information may
660come from a source outside the document itself (like a higher level
661protocol.)</p>
662
663<p><a name="builtin_encodings"></a>There are four built-in encodings
664in Expat:</p>
665<ul>
666<li>UTF-8</li>
667<li>UTF-16</li>
668<li>ISO-8859-1</li>
669<li>US-ASCII</li>
670</ul>
671
672<p>Anything else discovered in an encoding declaration or in the
673protocol encoding specified in the parser constructor, triggers a call
674to the <code>UnknownEncodingHandler</code>. This handler gets passed
675the encoding name and a pointer to an <code>XML_Encoding</code> data
676structure. Your handler must fill in this structure and return
677<code>XML_STATUS_OK</code> if it knows how to deal with the
678encoding. Otherwise the handler should return
679<code>XML_STATUS_ERROR</code>.  The handler also gets passed a pointer
680to an optional application data structure that you may indicate when
681you set the handler.</p>
682
683<p>Expat places restrictions on character encodings that it can
684support by filling in the <code>XML_Encoding</code> structure.
685include file:</p>
686<ol>
687<li>Every ASCII character that can appear in a well-formed XML document
688must be represented by a single byte, and that byte must correspond to
689it's ASCII encoding (except for the characters $@\^'{}~)</li>
690<li>Characters must be encoded in 4 bytes or less.</li>
691<li>All characters encoded must have Unicode scalar values less than or
692equal to 65535 (0xFFFF)<em>This does not apply to the built-in support
693for UTF-16 and UTF-8</em></li>
694<li>No character may be encoded by more that one distinct sequence of
695bytes</li>
696</ol>
697
698<p><code>XML_Encoding</code> contains an array of integers that
699correspond to the 1st byte of an encoding sequence. If the value in
700the array for a byte is zero or positive, then the byte is a single
701byte encoding that encodes the Unicode scalar value contained in the
702array. A -1 in this array indicates a malformed byte. If the value is
703-2, -3, or -4, then the byte is the beginning of a 2, 3, or 4 byte
704sequence respectively. Multi-byte sequences are sent to the convert
705function pointed at in the <code>XML_Encoding</code> structure. This
706function should return the Unicode scalar value for the sequence or -1
707if the sequence is malformed.</p>
708
709<p>One pitfall that novice Expat users are likely to fall into is that
710although Expat may accept input in various encodings, the strings that
711it passes to the handlers are always encoded in UTF-8 or UTF-16
712(depending on how Expat was compiled). Your application is responsible
713for any translation of these strings into other encodings.</p>
714
715<h3>Handling External Entity References</h3>
716
717<p>Expat does not read or parse external entities directly. Note that
718any external DTD is a special case of an external entity.  If you've
719set no <code>ExternalEntityRefHandler</code>, then external entity
720references are silently ignored. Otherwise, it calls your handler with
721the information needed to read and parse the external entity.</p>
722
723<p>Your handler isn't actually responsible for parsing the entity, but
724it is responsible for creating a subsidiary parser with <code><a href=
725"#XML_ExternalEntityParserCreate"
726>XML_ExternalEntityParserCreate</a></code> that will do the job. This
727returns an instance of <code>XML_Parser</code> that has handlers and
728other data structures initialized from the parent parser. You may then
729use <code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a
730href= "#XML_ParseBuffer">XML_ParseBuffer</a></code> calls against this
731parser.  Since external entities my refer to other external entities,
732your handler should be prepared to be called recursively.</p>
733
734<h3>Parsing DTDs</h3>
735
736<p>In order to parse parameter entities, before starting the parse,
737you must call <code><a href= "#XML_SetParamEntityParsing"
738>XML_SetParamEntityParsing</a></code> with one of the following
739arguments:</p>
740<dl>
741<dt><code>XML_PARAM_ENTITY_PARSING_NEVER</code></dt>
742<dd>Don't parse parameter entities or the external subset</dd>
743<dt><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></dt>
744<dd>Parse parameter entities and the external subset unless
745<code>standalone</code> was set to "yes" in the XML declaration.</dd>
746<dt><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></dt>
747<dd>Always parse parameter entities and the external subset</dd>
748</dl>
749
750<p>In order to read an external DTD, you also have to set an external
751entity reference handler as described above.</p>
752
753<h3 id="stop-resume">Temporarily Stopping Parsing</h3>
754
755<p>Expat 1.95.8 introduces a new feature: its now possible to stop
756parsing temporarily from within a handler function, even if more data
757has already been passed into the parser.  Applications for this
758include</p>
759
760<ul>
761  <li>Supporting the <a href= "http://www.w3.org/TR/xinclude/"
762  >XInclude</a> specification.</li>
763
764  <li>Delaying further processing until additional information is
765  available from some other source.</li>
766
767  <li>Adjusting processor load as task priorities shift within an
768  application.</li>
769
770  <li>Stopping parsing completely (simply free or reset the parser
771  instead of resuming in the outer parsing loop).  This can be useful
772  if an application-domain error is found in the XML being parsed or if
773  the result of the parse is determined not to be useful after
774  all.</li>
775</ul>
776
777<p>To take advantage of this feature, the main parsing loop of an
778application needs to support this specifically.  It cannot be
779supported with a parsing loop compatible with Expat 1.95.7 or
780earlier (though existing loops will continue to work without
781supporting the stop/resume feature).</p>
782
783<p>An application that uses this feature for a single parser will have
784the rough structure (in pseudo-code):</p>
785
786<pre class="pseudocode">
787fd = open_input()
788p = create_parser()
789
790if parse_xml(p, fd) {
791  /* suspended */
792
793  int suspended = 1;
794
795  while (suspended) {
796    do_something_else()
797    if ready_to_resume() {
798      suspended = continue_parsing(p, fd);
799    }
800  }
801}
802</pre>
803
804<p>An application that may resume any of several parsers based on
805input (either from the XML being parsed or some other source) will
806certainly have more interesting control structures.</p>
807
808<p>This C function could be used for the <code>parse_xml</code>
809function mentioned in the pseudo-code above:</p>
810
811<pre class="eg">
812#define BUFF_SIZE 10240
813
814/* Parse a document from the open file descriptor 'fd' until the parse
815   is complete (the document has been completely parsed, or there's
816   been an error), or the parse is stopped.  Return non-zero when
817   the parse is merely suspended.
818*/
819int
820parse_xml(XML_Parser p, int fd)
821{
822  for (;;) {
823    int last_chunk;
824    int bytes_read;
825    enum XML_Status status;
826
827    void *buff = XML_GetBuffer(p, BUFF_SIZE);
828    if (buff == NULL) {
829      /* handle error... */
830      return 0;
831    }
832    bytes_read = read(fd, buff, BUFF_SIZE);
833    if (bytes_read &lt; 0) {
834      /* handle error... */
835      return 0;
836    }
837    status = XML_ParseBuffer(p, bytes_read, bytes_read == 0);
838    switch (status) {
839      case XML_STATUS_ERROR:
840        /* handle error... */
841        return 0;
842      case XML_STATUS_SUSPENDED:
843        return 1;
844    }
845    if (bytes_read == 0)
846      return 0;
847  }
848}
849</pre>
850
851<p>The corresponding <code>continue_parsing</code> function is
852somewhat simpler, since it only need deal with the return code from
853<code><a href= "#XML_ResumeParser">XML_ResumeParser</a></code>; it can
854delegate the input handling to the <code>parse_xml</code>
855function:</p>
856
857<pre class="eg">
858/* Continue parsing a document which had been suspended.  The 'p' and
859   'fd' arguments are the same as passed to parse_xml().  Return
860   non-zero when the parse is suspended.
861*/
862int
863continue_parsing(XML_Parser p, int fd)
864{
865  enum XML_Status status = XML_ResumeParser(p);
866  switch (status) {
867    case XML_STATUS_ERROR:
868      /* handle error... */
869      return 0;
870    case XML_ERROR_NOT_SUSPENDED:
871      /* handle error... */
872      return 0;.
873    case XML_STATUS_SUSPENDED:
874      return 1;
875  }
876  return parse_xml(p, fd);
877}
878</pre>
879
880<p>Now that we've seen what a mess the top-level parsing loop can
881become, what have we gained?  Very simply, we can now use the <code><a
882href= "#XML_StopParser" >XML_StopParser</a></code> function to stop
883parsing, without having to go to great lengths to avoid additional
884processing that we're expecting to ignore.  As a bonus, we get to stop
885parsing <em>temporarily</em>, and come back to it when we're
886ready.</p>
887
888<p>To stop parsing from a handler function, use the <code><a href=
889"#XML_StopParser" >XML_StopParser</a></code> function.  This function
890takes two arguments; the parser being stopped and a flag indicating
891whether the parse can be resumed in the future.</p>
892
893<!-- XXX really need more here -->
894
895
896<hr />
897<!-- ================================================================ -->
898
899<h2><a name="reference">Expat Reference</a></h2>
900
901<h3><a name="creation">Parser Creation</a></h3>
902
903<pre class="fcndec" id="XML_ParserCreate">
904XML_Parser XMLCALL
905XML_ParserCreate(const XML_Char *encoding);
906</pre>
907<div class="fcndef">
908Construct a new parser. If encoding is non-null, it specifies a
909character encoding to use for the document. This overrides the document
910encoding declaration. There are four built-in encodings:
911<ul>
912<li>US-ASCII</li>
913<li>UTF-8</li>
914<li>UTF-16</li>
915<li>ISO-8859-1</li>
916</ul>
917Any other value will invoke a call to the UnknownEncodingHandler.
918</div>
919
920<pre class="fcndec" id="XML_ParserCreateNS">
921XML_Parser XMLCALL
922XML_ParserCreateNS(const XML_Char *encoding,
923                   XML_Char sep);
924</pre>
925<div class="fcndef">
926Constructs a new parser that has namespace processing in effect. Namespace
927expanded element names and attribute names are returned as a concatenation
928of the namespace URI, <em>sep</em>, and the local part of the name. This
929means that you should pick a character for <em>sep</em> that can't be part
930of an URI. Since Expat does not check namespace URIs for conformance, the
931only safe choice for a namespace separator is a character that is illegal
932in XML. For instance, <code>'\xFF'</code> is not legal in UTF-8, and
933<code>'\xFFFF'</code> is not legal in UTF-16. There is a special case when
934<em>sep</em> is the null character <code>'\0'</code>: the namespace URI and
935the local part will be concatenated without any separator - this is intended
936to support RDF processors. It is a programming error to use the null separator
937with <a href= "#XML_SetReturnNSTriplet">namespace triplets</a>.</div>
938
939<pre class="fcndec" id="XML_ParserCreate_MM">
940XML_Parser XMLCALL
941XML_ParserCreate_MM(const XML_Char *encoding,
942                    const XML_Memory_Handling_Suite *ms,
943		    const XML_Char *sep);
944</pre>
945<pre class="signature">
946typedef struct {
947  void *(XMLCALL *malloc_fcn)(size_t size);
948  void *(XMLCALL *realloc_fcn)(void *ptr, size_t size);
949  void (XMLCALL *free_fcn)(void *ptr);
950} XML_Memory_Handling_Suite;
951</pre>
952<div class="fcndef">
953<p>Construct a new parser using the suite of memory handling functions
954specified in <code>ms</code>. If <code>ms</code> is NULL, then use the
955standard set of memory management functions. If <code>sep</code> is
956non NULL, then namespace processing is enabled in the created parser
957and the character pointed at by sep is used as the separator between
958the namespace URI and the local part of the name.</p>
959</div>
960
961<pre class="fcndec" id="XML_ExternalEntityParserCreate">
962XML_Parser XMLCALL
963XML_ExternalEntityParserCreate(XML_Parser p,
964                               const XML_Char *context,
965                               const XML_Char *encoding);
966</pre>
967<div class="fcndef">
968Construct a new <code>XML_Parser</code> object for parsing an external
969general entity. Context is the context argument passed in a call to a
970ExternalEntityRefHandler. Other state information such as handlers,
971user data, namespace processing is inherited from the parser passed as
972the 1st argument. So you shouldn't need to call any of the behavior
973changing functions on this parser (unless you want it to act
974differently than the parent parser).
975</div>
976
977<pre class="fcndec" id="XML_ParserFree">
978void XMLCALL
979XML_ParserFree(XML_Parser p);
980</pre>
981<div class="fcndef">
982Free memory used by the parser. Your application is responsible for
983freeing any memory associated with <a href="#userdata">user data</a>.
984</div>
985
986<pre class="fcndec" id="XML_ParserReset">
987XML_Bool XMLCALL
988XML_ParserReset(XML_Parser p,
989                const XML_Char *encoding);
990</pre>
991<div class="fcndef">
992Clean up the memory structures maintained by the parser so that it may
993be used again.  After this has been called, <code>parser</code> is
994ready to start parsing a new document.  All handlers are cleared from
995the parser, except for the unknownEncodingHandler.  The parser's external
996state is re-initialized except for the values of ns and ns_triplets.
997This function may not be used on a parser created using <code><a href=
998"#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a
999></code>; it will return <code>XML_FALSE</code> in that case.  Returns
1000<code>XML_TRUE</code> on success.  Your application is responsible for
1001dealing with any memory associated with <a href="#userdata">user data</a>.
1002</div>
1003
1004<h3><a name="parsing">Parsing</a></h3>
1005
1006<p>To state the obvious: the three parsing functions <code><a href=
1007"#XML_Parse" >XML_Parse</a></code>, <code><a href= "#XML_ParseBuffer">
1008XML_ParseBuffer</a></code> and <code><a href= "#XML_GetBuffer">
1009XML_GetBuffer</a></code> must not be called from within a handler
1010unless they operate on a separate parser instance, that is, one that
1011did not call the handler. For example, it is OK to call the parsing
1012functions from within an <code>XML_ExternalEntityRefHandler</code>,
1013if they apply to the parser created by
1014<code><a href= "#XML_ExternalEntityParserCreate"
1015>XML_ExternalEntityParserCreate</a></code>.</p>
1016
1017<p>Note: the <code>len</code> argument passed to these functions
1018should be considerably less than the maximum value for an integer,
1019as it could create an integer overflow situation if the added
1020lengths of a buffer and the unprocessed portion of the previous buffer
1021exceed the maximum integer value. Input data at the end of a buffer
1022will remain unprocessed if it is part of an XML token for which the
1023end is not part of that buffer.</p>
1024
1025<pre class="fcndec" id="XML_Parse">
1026enum XML_Status XMLCALL
1027XML_Parse(XML_Parser p,
1028          const char *s,
1029          int len,
1030          int isFinal);
1031</pre>
1032<pre class="signature">
1033enum XML_Status {
1034  XML_STATUS_ERROR = 0,
1035  XML_STATUS_OK = 1
1036};
1037</pre>
1038<div class="fcndef">
1039Parse some more of the document. The string <code>s</code> is a buffer
1040containing part (or perhaps all) of the document. The number of bytes of s
1041that are part of the document is indicated by <code>len</code>. This means
1042that <code>s</code> doesn't have to be null terminated. It also means that
1043if <code>len</code> is larger than the number of bytes in the block of
1044memory that <code>s</code> points at, then a memory fault is likely. The
1045<code>isFinal</code> parameter informs the parser that this is the last
1046piece of the document. Frequently, the last piece is empty (i.e.
1047<code>len</code> is zero.)
1048If a parse error occurred, it returns <code>XML_STATUS_ERROR</code>.
1049Otherwise it returns <code>XML_STATUS_OK</code> value.
1050</div>
1051
1052<pre class="fcndec" id="XML_ParseBuffer">
1053enum XML_Status XMLCALL
1054XML_ParseBuffer(XML_Parser p,
1055                int len,
1056                int isFinal);
1057</pre>
1058<div class="fcndef">
1059This is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>,
1060except in this case Expat provides the buffer.  By obtaining the
1061buffer from Expat with the <code><a href= "#XML_GetBuffer"
1062>XML_GetBuffer</a></code> function, the application can avoid double
1063copying of the input.
1064</div>
1065
1066<pre class="fcndec" id="XML_GetBuffer">
1067void * XMLCALL
1068XML_GetBuffer(XML_Parser p,
1069              int len);
1070</pre>
1071<div class="fcndef">
1072Obtain a buffer of size <code>len</code> to read a piece of the document
1073into. A NULL value is returned if Expat can't allocate enough memory for
1074this buffer. This has to be called prior to every call to
1075<code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A
1076typical use would look like this:
1077
1078<pre class="eg">
1079for (;;) {
1080  int bytes_read;
1081  void *buff = XML_GetBuffer(p, BUFF_SIZE);
1082  if (buff == NULL) {
1083    /* handle error */
1084  }
1085
1086  bytes_read = read(docfd, buff, BUFF_SIZE);
1087  if (bytes_read &lt; 0) {
1088    /* handle error */
1089  }
1090
1091  if (! XML_ParseBuffer(p, bytes_read, bytes_read == 0)) {
1092    /* handle parse error */
1093  }
1094
1095  if (bytes_read == 0)
1096    break;
1097}
1098</pre>
1099</div>
1100
1101<pre class="fcndec" id="XML_StopParser">
1102enum XML_Status XMLCALL
1103XML_StopParser(XML_Parser p,
1104               XML_Bool resumable);
1105</pre>
1106<div class="fcndef">
1107
1108<p>Stops parsing, causing <code><a href= "#XML_Parse"
1109>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
1110>XML_ParseBuffer</a></code> to return.  Must be called from within a
1111call-back handler, except when aborting (when <code>resumable</code>
1112is <code>XML_FALSE</code>) an already suspended parser.  Some
1113call-backs may still follow because they would otherwise get
1114lost, including
1115<ul>
1116  <li> the end element handler for empty elements when stopped in the
1117       start element handler,</li>
1118  <li> the end namespace declaration handler when stopped in the end
1119       element handler,</li>
1120  <li> the character data handler when stopped in the character data handler
1121       while making multiple call-backs on a contiguous chunk of characters,</li>
1122</ul>
1123and possibly others.</p>
1124
1125<p>This can be called from most handlers, including DTD related
1126call-backs, except when parsing an external parameter entity and
1127<code>resumable</code> is <code>XML_TRUE</code>.  Returns
1128<code>XML_STATUS_OK</code> when successful,
1129<code>XML_STATUS_ERROR</code> otherwise.  The possible error codes
1130are:</p>
1131<dl>
1132  <dt><code>XML_ERROR_SUSPENDED</code></dt>
1133  <dd>when suspending an already suspended parser.</dd>
1134  <dt><code>XML_ERROR_FINISHED</code></dt>
1135  <dd>when the parser has already finished.</dd>
1136  <dt><code>XML_ERROR_SUSPEND_PE</code></dt>
1137  <dd>when suspending while parsing an external PE.</dd>
1138</dl>
1139
1140<p>Since the stop/resume feature requires application support in the
1141outer parsing loop, it is an error to call this function for a parser
1142not being handled appropriately; see <a href= "#stop-resume"
1143>Temporarily Stopping Parsing</a> for more information.</p>
1144
1145<p>When <code>resumable</code> is <code>XML_TRUE</code> then parsing
1146is <em>suspended</em>, that is, <code><a href= "#XML_Parse"
1147>XML_Parse</a></code> and <code><a href= "#XML_ParseBuffer"
1148>XML_ParseBuffer</a></code> return <code>XML_STATUS_SUSPENDED</code>.
1149Otherwise, parsing is <em>aborted</em>, that is, <code><a href=
1150"#XML_Parse" >XML_Parse</a></code> and <code><a href=
1151"#XML_ParseBuffer" >XML_ParseBuffer</a></code> return
1152<code>XML_STATUS_ERROR</code> with error code
1153<code>XML_ERROR_ABORTED</code>.</p>
1154
1155<p><strong>Note:</strong>
1156This will be applied to the current parser instance only, that is, if
1157there is a parent parser then it will continue parsing when the
1158external entity reference handler returns.  It is up to the
1159implementation of that handler to call <code><a href=
1160"#XML_StopParser" >XML_StopParser</a></code> on the parent parser
1161(recursively), if one wants to stop parsing altogether.</p>
1162
1163<p>When suspended, parsing can be resumed by calling <code><a href=
1164"#XML_ResumeParser" >XML_ResumeParser</a></code>.</p>
1165
1166<p>New in Expat 1.95.8.</p>
1167</div>
1168
1169<pre class="fcndec" id="XML_ResumeParser">
1170enum XML_Status XMLCALL
1171XML_ResumeParser(XML_Parser p);
1172</pre>
1173<div class="fcndef">
1174<p>Resumes parsing after it has been suspended with <code><a href=
1175"#XML_StopParser" >XML_StopParser</a></code>.  Must not be called from
1176within a handler call-back.  Returns same status codes as <code><a
1177href= "#XML_Parse">XML_Parse</a></code> or <code><a href=
1178"#XML_ParseBuffer" >XML_ParseBuffer</a></code>.  An additional error
1179code, <code>XML_ERROR_NOT_SUSPENDED</code>, will be returned if the
1180parser was not currently suspended.</p>
1181
1182<p><strong>Note:</strong>
1183This must be called on the most deeply nested child parser instance
1184first, and on its parent parser only after the child parser has
1185finished, to be applied recursively until the document entity's parser
1186is restarted.  That is, the parent parser will not resume by itself
1187and it is up to the application to call <code><a href=
1188"#XML_ResumeParser" >XML_ResumeParser</a></code> on it at the
1189appropriate moment.</p>
1190
1191<p>New in Expat 1.95.8.</p>
1192</div>
1193
1194<pre class="fcndec" id="XML_GetParsingStatus">
1195void XMLCALL
1196XML_GetParsingStatus(XML_Parser p,
1197                     XML_ParsingStatus *status);
1198</pre>
1199<pre class="signature">
1200enum XML_Parsing {
1201  XML_INITIALIZED,
1202  XML_PARSING,
1203  XML_FINISHED,
1204  XML_SUSPENDED
1205};
1206
1207typedef struct {
1208  enum XML_Parsing parsing;
1209  XML_Bool finalBuffer;
1210} XML_ParsingStatus;
1211</pre>
1212<div class="fcndef">
1213<p>Returns status of parser with respect to being initialized,
1214parsing, finished, or suspended, and whether the final buffer is being
1215processed.  The <code>status</code> parameter <em>must not</em> be
1216NULL.</p>
1217
1218<p>New in Expat 1.95.8.</p>
1219</div>
1220
1221
1222<h3><a name="setting">Handler Setting</a></h3>
1223
1224<p>Although handlers are typically set prior to parsing and left alone, an
1225application may choose to set or change the handler for a parsing event
1226while the parse is in progress. For instance, your application may choose
1227to ignore all text not descended from a <code>para</code> element. One
1228way it could do this is to set the character handler when a para start tag
1229is seen, and unset it for the corresponding end tag.</p>
1230
1231<p>A handler may be <em>unset</em> by providing a NULL pointer to the
1232appropriate handler setter. None of the handler setting functions have
1233a return value.</p>
1234
1235<p>Your handlers will be receiving strings in arrays of type
1236<code>XML_Char</code>. This type is conditionally defined in expat.h as
1237either <code>char</code>, <code>wchar_t</code> or <code>unsigned short</code>.
1238The former implies UTF-8 encoding, the latter two imply UTF-16 encoding.
1239Note that you'll receive them in this form independent of the original
1240encoding of the document.</p>
1241
1242<div class="handler">
1243<pre class="setter" id="XML_SetStartElementHandler">
1244void XMLCALL
1245XML_SetStartElementHandler(XML_Parser p,
1246                           XML_StartElementHandler start);
1247</pre>
1248<pre class="signature">
1249typedef void
1250(XMLCALL *XML_StartElementHandler)(void *userData,
1251                                   const XML_Char *name,
1252                                   const XML_Char **atts);
1253</pre>
1254<p>Set handler for start (and empty) tags. Attributes are passed to the start
1255handler as a pointer to a vector of char pointers. Each attribute seen in
1256a start (or empty) tag occupies 2 consecutive places in this vector: the
1257attribute name followed by the attribute value. These pairs are terminated
1258by a null pointer.</p>
1259<p>Note that an empty tag generates a call to both start and end handlers
1260(in that order).</p>
1261</div>
1262
1263<div class="handler">
1264<pre class="setter" id="XML_SetEndElementHandler">
1265void XMLCALL
1266XML_SetEndElementHandler(XML_Parser p,
1267                         XML_EndElementHandler);
1268</pre>
1269<pre class="signature">
1270typedef void
1271(XMLCALL *XML_EndElementHandler)(void *userData,
1272                                 const XML_Char *name);
1273</pre>
1274<p>Set handler for end (and empty) tags. As noted above, an empty tag
1275generates a call to both start and end handlers.</p>
1276</div>
1277
1278<div class="handler">
1279<pre class="setter" id="XML_SetElementHandler">
1280void XMLCALL
1281XML_SetElementHandler(XML_Parser p,
1282                      XML_StartElementHandler start,
1283                      XML_EndElementHandler end);
1284</pre>
1285<p>Set handlers for start and end tags with one call.</p>
1286</div>
1287
1288<div class="handler">
1289<pre class="setter" id="XML_SetCharacterDataHandler">
1290void XMLCALL
1291XML_SetCharacterDataHandler(XML_Parser p,
1292                            XML_CharacterDataHandler charhndl)
1293</pre>
1294<pre class="signature">
1295typedef void
1296(XMLCALL *XML_CharacterDataHandler)(void *userData,
1297                                    const XML_Char *s,
1298                                    int len);
1299</pre>
1300<p>Set a text handler. The string your handler receives
1301is <em>NOT nul-terminated</em>. You have to use the length argument
1302to deal with the end of the string. A single block of contiguous text
1303free of markup may still result in a sequence of calls to this handler.
1304In other words, if you're searching for a pattern in the text, it may
1305be split across calls to this handler. Note: Setting this handler to NULL
1306may <em>NOT immediately</em> terminate call-backs if the parser is currently
1307processing such a single block of contiguous markup-free text, as the parser
1308will continue calling back until the end of the block is reached.</p>
1309</div>
1310
1311<div class="handler">
1312<pre class="setter" id="XML_SetProcessingInstructionHandler">
1313void XMLCALL
1314XML_SetProcessingInstructionHandler(XML_Parser p,
1315                                    XML_ProcessingInstructionHandler proc)
1316</pre>
1317<pre class="signature">
1318typedef void
1319(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,
1320                                            const XML_Char *target,
1321                                            const XML_Char *data);
1322
1323</pre>
1324<p>Set a handler for processing instructions. The target is the first word
1325in the processing instruction. The data is the rest of the characters in
1326it after skipping all whitespace after the initial word.</p>
1327</div>
1328
1329<div class="handler">
1330<pre class="setter" id="XML_SetCommentHandler">
1331void XMLCALL
1332XML_SetCommentHandler(XML_Parser p,
1333                      XML_CommentHandler cmnt)
1334</pre>
1335<pre class="signature">
1336typedef void
1337(XMLCALL *XML_CommentHandler)(void *userData,
1338                              const XML_Char *data);
1339</pre>
1340<p>Set a handler for comments. The data is all text inside the comment
1341delimiters.</p>
1342</div>
1343
1344<div class="handler">
1345<pre class="setter" id="XML_SetStartCdataSectionHandler">
1346void XMLCALL
1347XML_SetStartCdataSectionHandler(XML_Parser p,
1348                                XML_StartCdataSectionHandler start);
1349</pre>
1350<pre class="signature">
1351typedef void
1352(XMLCALL *XML_StartCdataSectionHandler)(void *userData);
1353</pre>
1354<p>Set a handler that gets called at the beginning of a CDATA section.</p>
1355</div>
1356
1357<div class="handler">
1358<pre class="setter" id="XML_SetEndCdataSectionHandler">
1359void XMLCALL
1360XML_SetEndCdataSectionHandler(XML_Parser p,
1361                              XML_EndCdataSectionHandler end);
1362</pre>
1363<pre class="signature">
1364typedef void
1365(XMLCALL *XML_EndCdataSectionHandler)(void *userData);
1366</pre>
1367<p>Set a handler that gets called at the end of a CDATA section.</p>
1368</div>
1369
1370<div class="handler">
1371<pre class="setter" id="XML_SetCdataSectionHandler">
1372void XMLCALL
1373XML_SetCdataSectionHandler(XML_Parser p,
1374                           XML_StartCdataSectionHandler start,
1375                           XML_EndCdataSectionHandler end)
1376</pre>
1377<p>Sets both CDATA section handlers with one call.</p>
1378</div>
1379
1380<div class="handler">
1381<pre class="setter" id="XML_SetDefaultHandler">
1382void XMLCALL
1383XML_SetDefaultHandler(XML_Parser p,
1384                      XML_DefaultHandler hndl)
1385</pre>
1386<pre class="signature">
1387typedef void
1388(XMLCALL *XML_DefaultHandler)(void *userData,
1389                              const XML_Char *s,
1390                              int len);
1391</pre>
1392
1393<p>Sets a handler for any characters in the document which wouldn't
1394otherwise be handled. This includes both data for which no handlers
1395can be set (like some kinds of DTD declarations) and data which could
1396be reported but which currently has no handler set.  The characters
1397are passed exactly as they were present in the XML document except
1398that they will be encoded in UTF-8 or UTF-16. Line boundaries are not
1399normalized. Note that a byte order mark character is not passed to the
1400default handler. There are no guarantees about how characters are
1401divided between calls to the default handler: for example, a comment
1402might be split between multiple calls.  Setting the handler with
1403this call has the side effect of turning off expansion of references
1404to internally defined general entities. Instead these references are
1405passed to the default handler.</p>
1406
1407<p>See also <code><a
1408href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
1409</div>
1410
1411<div class="handler">
1412<pre class="setter" id="XML_SetDefaultHandlerExpand">
1413void XMLCALL
1414XML_SetDefaultHandlerExpand(XML_Parser p,
1415                            XML_DefaultHandler hndl)
1416</pre>
1417<pre class="signature">
1418typedef void
1419(XMLCALL *XML_DefaultHandler)(void *userData,
1420                              const XML_Char *s,
1421                              int len);
1422</pre>
1423<p>This sets a default handler, but doesn't inhibit the expansion of
1424internal entity references.  The entity reference will not be passed
1425to the default handler.</p>
1426
1427<p>See also <code><a
1428href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
1429</div>
1430
1431<div class="handler">
1432<pre class="setter" id="XML_SetExternalEntityRefHandler">
1433void XMLCALL
1434XML_SetExternalEntityRefHandler(XML_Parser p,
1435                                XML_ExternalEntityRefHandler hndl)
1436</pre>
1437<pre class="signature">
1438typedef int
1439(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser p,
1440                                        const XML_Char *context,
1441                                        const XML_Char *base,
1442                                        const XML_Char *systemId,
1443                                        const XML_Char *publicId);
1444</pre>
1445<p>Set an external entity reference handler. This handler is also
1446called for processing an external DTD subset if parameter entity parsing
1447is in effect. (See <a href="#XML_SetParamEntityParsing">
1448<code>XML_SetParamEntityParsing</code></a>.)</p>
1449
1450<p>The <code>context</code> parameter specifies the parsing context in
1451the format expected by the <code>context</code> argument to <code><a
1452href="#XML_ExternalEntityParserCreate"
1453>XML_ExternalEntityParserCreate</a></code>.  <code>code</code> is
1454valid only until the handler returns, so if the referenced entity is
1455to be parsed later, it must be copied.  <code>context</code> is NULL
1456only when the entity is a parameter entity, which is how one can
1457differentiate between general and parameter entities.</p>
1458
1459<p>The <code>base</code> parameter is the base to use for relative
1460system identifiers.  It is set by <code><a
1461href="#XML_SetBase">XML_SetBase</a></code> and may be NULL. The
1462<code>publicId</code> parameter is the public id given in the entity
1463declaration and may be NULL.  <code>systemId</code> is the system
1464identifier specified in the entity declaration and is never NULL.</p>
1465
1466<p>There are a couple of ways in which this handler differs from
1467others.  First, this handler returns a status indicator (an
1468integer). <code>XML_STATUS_OK</code> should be returned for successful
1469handling of the external entity reference.  Returning
1470<code>XML_STATUS_ERROR</code> indicates failure, and causes the
1471calling parser to return an
1472<code>XML_ERROR_EXTERNAL_ENTITY_HANDLING</code> error.</p>
1473
1474<p>Second, instead of having the user data as its first argument, it
1475receives the parser that encountered the entity reference. This, along
1476with the context parameter, may be used as arguments to a call to
1477<code><a href= "#XML_ExternalEntityParserCreate"
1478>XML_ExternalEntityParserCreate</a></code>.  Using the returned
1479parser, the body of the external entity can be recursively parsed.</p>
1480
1481<p>Since this handler may be called recursively, it should not be saving
1482information into global or static variables.</p>
1483</div>
1484
1485<pre class="fcndec" id="XML_SetExternalEntityRefHandlerArg">
1486void XMLCALL
1487XML_SetExternalEntityRefHandlerArg(XML_Parser p,
1488                                   void *arg)
1489</pre>
1490<div class="fcndef">
1491<p>Set the argument passed to the ExternalEntityRefHandler.  If
1492<code>arg</code> is not NULL, it is the new value passed to the
1493handler set using <code><a href="#XML_SetExternalEntityRefHandler"
1494>XML_SetExternalEntityRefHandler</a></code>; if <code>arg</code> is
1495NULL, the argument passed to the handler function will be the parser
1496object itself.</p>
1497
1498<p><strong>Note:</strong>
1499The type of <code>arg</code> and the type of the first argument to the
1500ExternalEntityRefHandler do not match.  This function takes a
1501<code>void *</code> to be passed to the handler, while the handler
1502accepts an <code>XML_Parser</code>.  This is a historical accident,
1503but will not be corrected before Expat 2.0 (at the earliest) to avoid
1504causing compiler warnings for code that's known to work with this
1505API.  It is the responsibility of the application code to know the
1506actual type of the argument passed to the handler and to manage it
1507properly.</p>
1508</div>
1509
1510<div class="handler">
1511<pre class="setter" id="XML_SetSkippedEntityHandler">
1512void XMLCALL
1513XML_SetSkippedEntityHandler(XML_Parser p,
1514                            XML_SkippedEntityHandler handler)
1515</pre>
1516<pre class="signature">
1517typedef void
1518(XMLCALL *XML_SkippedEntityHandler)(void *userData,
1519                                    const XML_Char *entityName,
1520                                    int is_parameter_entity);
1521</pre>
1522<p>Set a skipped entity handler. This is called in two situations:</p>
1523<ol>
1524   <li>An entity reference is encountered for which no declaration
1525       has been read <em>and</em> this is not an error.</li>
1526   <li>An internal entity reference is read, but not expanded, because
1527       <a href="#XML_SetDefaultHandler"><code>XML_SetDefaultHandler</code></a>
1528	   has been called.</li>
1529</ol>
1530<p>The <code>is_parameter_entity</code> argument will be non-zero for
1531a parameter entity and zero for a general entity.</p> <p>Note: skipped
1532parameter entities in declarations and skipped general entities in
1533attribute values cannot be reported, because the event would be out of
1534sync with the reporting of the declarations or attribute values</p>
1535</div>
1536
1537<div class="handler">
1538<pre class="setter" id="XML_SetUnknownEncodingHandler">
1539void XMLCALL
1540XML_SetUnknownEncodingHandler(XML_Parser p,
1541                              XML_UnknownEncodingHandler enchandler,
1542			      void *encodingHandlerData)
1543</pre>
1544<pre class="signature">
1545typedef int
1546(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
1547                                      const XML_Char *name,
1548                                      XML_Encoding *info);
1549
1550typedef struct {
1551  int map[256];
1552  void *data;
1553  int (XMLCALL *convert)(void *data, const char *s);
1554  void (XMLCALL *release)(void *data);
1555} XML_Encoding;
1556</pre>
1557<p>Set a handler to deal with encodings other than the <a
1558href="#builtin_encodings">built in set</a>. This should be done before
1559<code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href=
1560"#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the
1561given parser.</p> <p>If the handler knows how to deal with an encoding
1562with the given name, it should fill in the <code>info</code> data
1563structure and return <code>XML_STATUS_OK</code>. Otherwise it
1564should return <code>XML_STATUS_ERROR</code>. The handler will be called
1565at most once per parsed (external) entity. The optional application
1566data pointer <code>encodingHandlerData</code> will be passed back to
1567the handler.</p>
1568
1569<p>The map array contains information for every possible leading
1570byte in a byte sequence. If the corresponding value is &gt;= 0, then it's
1571a single byte sequence and the byte encodes that Unicode value. If the
1572value is -1, then that byte is invalid as the initial byte in a sequence.
1573If the value is -n, where n is an integer &gt; 1, then n is the number of
1574bytes in the sequence and the actual conversion is accomplished by a
1575call to the function pointed at by convert. This function may return -1
1576if the sequence itself is invalid. The convert pointer may be null if
1577there are only single byte codes. The data parameter passed to the convert
1578function is the data pointer from <code>XML_Encoding</code>. The
1579string s is <em>NOT</em> nul-terminated and points at the sequence of
1580bytes to be converted.</p>
1581
1582<p>The function pointed at by <code>release</code> is called by the
1583parser when it is finished with the encoding. It may be NULL.</p>
1584</div>
1585
1586<div class="handler">
1587<pre class="setter" id="XML_SetStartNamespaceDeclHandler">
1588void XMLCALL
1589XML_SetStartNamespaceDeclHandler(XML_Parser p,
1590			         XML_StartNamespaceDeclHandler start);
1591</pre>
1592<pre class="signature">
1593typedef void
1594(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,
1595                                         const XML_Char *prefix,
1596                                         const XML_Char *uri);
1597</pre>
1598<p>Set a handler to be called when a namespace is declared. Namespace
1599declarations occur inside start tags. But the namespace declaration start
1600handler is called before the start tag handler for each namespace declared
1601in that start tag.</p>
1602</div>
1603
1604<div class="handler">
1605<pre class="setter" id="XML_SetEndNamespaceDeclHandler">
1606void XMLCALL
1607XML_SetEndNamespaceDeclHandler(XML_Parser p,
1608			       XML_EndNamespaceDeclHandler end);
1609</pre>
1610<pre class="signature">
1611typedef void
1612(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,
1613                                       const XML_Char *prefix);
1614</pre>
1615<p>Set a handler to be called when leaving the scope of a namespace
1616declaration. This will be called, for each namespace declaration,
1617after the handler for the end tag of the element in which the
1618namespace was declared.</p>
1619</div>
1620
1621<div class="handler">
1622<pre class="setter" id="XML_SetNamespaceDeclHandler">
1623void XMLCALL
1624XML_SetNamespaceDeclHandler(XML_Parser p,
1625                            XML_StartNamespaceDeclHandler start,
1626                            XML_EndNamespaceDeclHandler end)
1627</pre>
1628<p>Sets both namespace declaration handlers with a single call.</p>
1629</div>
1630
1631<div class="handler">
1632<pre class="setter" id="XML_SetXmlDeclHandler">
1633void XMLCALL
1634XML_SetXmlDeclHandler(XML_Parser p,
1635		      XML_XmlDeclHandler xmldecl);
1636</pre>
1637<pre class="signature">
1638typedef void
1639(XMLCALL *XML_XmlDeclHandler)(void            *userData,
1640                              const XML_Char  *version,
1641                              const XML_Char  *encoding,
1642                              int             standalone);
1643</pre>
1644<p>Sets a handler that is called for XML declarations and also for
1645text declarations discovered in external entities. The way to
1646distinguish is that the <code>version</code> parameter will be NULL
1647for text declarations. The <code>encoding</code> parameter may be NULL
1648for an XML declaration. The <code>standalone</code> argument will
1649contain -1, 0, or 1 indicating respectively that there was no
1650standalone parameter in the declaration, that it was given as no, or
1651that it was given as yes.</p>
1652</div>
1653
1654<div class="handler">
1655<pre class="setter" id="XML_SetStartDoctypeDeclHandler">
1656void XMLCALL
1657XML_SetStartDoctypeDeclHandler(XML_Parser p,
1658			       XML_StartDoctypeDeclHandler start);
1659</pre>
1660<pre class="signature">
1661typedef void
1662(XMLCALL *XML_StartDoctypeDeclHandler)(void           *userData,
1663                                       const XML_Char *doctypeName,
1664                                       const XML_Char *sysid,
1665                                       const XML_Char *pubid,
1666                                       int            has_internal_subset);
1667</pre>
1668<p>Set a handler that is called at the start of a DOCTYPE declaration,
1669before any external or internal subset is parsed. Both <code>sysid</code>
1670and <code>pubid</code> may be NULL. The <code>has_internal_subset</code>
1671will be non-zero if the DOCTYPE declaration has an internal subset.</p>
1672</div>
1673
1674<div class="handler">
1675<pre class="setter" id="XML_SetEndDoctypeDeclHandler">
1676void XMLCALL
1677XML_SetEndDoctypeDeclHandler(XML_Parser p,
1678			     XML_EndDoctypeDeclHandler end);
1679</pre>
1680<pre class="signature">
1681typedef void
1682(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
1683</pre>
1684<p>Set a handler that is called at the end of a DOCTYPE declaration,
1685after parsing any external subset.</p>
1686</div>
1687
1688<div class="handler">
1689<pre class="setter" id="XML_SetDoctypeDeclHandler">
1690void XMLCALL
1691XML_SetDoctypeDeclHandler(XML_Parser p,
1692			  XML_StartDoctypeDeclHandler start,
1693			  XML_EndDoctypeDeclHandler end);
1694</pre>
1695<p>Set both doctype handlers with one call.</p>
1696</div>
1697
1698<div class="handler">
1699<pre class="setter" id="XML_SetElementDeclHandler">
1700void XMLCALL
1701XML_SetElementDeclHandler(XML_Parser p,
1702			  XML_ElementDeclHandler eldecl);
1703</pre>
1704<pre class="signature">
1705typedef void
1706(XMLCALL *XML_ElementDeclHandler)(void *userData,
1707                                  const XML_Char *name,
1708                                  XML_Content *model);
1709</pre>
1710<pre class="signature">
1711enum XML_Content_Type {
1712  XML_CTYPE_EMPTY = 1,
1713  XML_CTYPE_ANY,
1714  XML_CTYPE_MIXED,
1715  XML_CTYPE_NAME,
1716  XML_CTYPE_CHOICE,
1717  XML_CTYPE_SEQ
1718};
1719
1720enum XML_Content_Quant {
1721  XML_CQUANT_NONE,
1722  XML_CQUANT_OPT,
1723  XML_CQUANT_REP,
1724  XML_CQUANT_PLUS
1725};
1726
1727typedef struct XML_cp XML_Content;
1728
1729struct XML_cp {
1730  enum XML_Content_Type		type;
1731  enum XML_Content_Quant	quant;
1732  const XML_Char *		name;
1733  unsigned int			numchildren;
1734  XML_Content *			children;
1735};
1736</pre>
1737<p>Sets a handler for element declarations in a DTD. The handler gets
1738called with the name of the element in the declaration and a pointer
1739to a structure that contains the element model. It is the
1740application's responsibility to free this data structure using
1741<code><a href="#XML_FreeContentModel"
1742>XML_FreeContentModel</a></code>.</p>
1743
1744<p>The <code>model</code> argument is the root of a tree of
1745<code>XML_Content</code> nodes. If <code>type</code> equals
1746<code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then
1747<code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other
1748fields will be zero or NULL.  If <code>type</code> is
1749<code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be
1750<code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and
1751<code>numchildren</code> will contain the number of elements that are
1752allowed to be mixed in and <code>children</code> points to an array of
1753<code>XML_Content</code> structures that will all have type
1754XML_CTYPE_NAME with no quantification.  Only the root node can be type
1755<code>XML_CTYPE_EMPTY</code>, <code>XML_CTYPE_ANY</code>, or
1756<code>XML_CTYPE_MIXED</code>.</p>
1757
1758<p>For type <code>XML_CTYPE_NAME</code>, the <code>name</code> field
1759points to the name and the <code>numchildren</code> and
1760<code>children</code> fields will be zero and NULL. The
1761<code>quant</code> field will indicate any quantifiers placed on the
1762name.</p>
1763
1764<p>Types <code>XML_CTYPE_CHOICE</code> and <code>XML_CTYPE_SEQ</code>
1765indicate a choice or sequence respectively. The
1766<code>numchildren</code> field indicates how many nodes in the choice
1767or sequence and <code>children</code> points to the nodes.</p>
1768</div>
1769
1770<div class="handler">
1771<pre class="setter" id="XML_SetAttlistDeclHandler">
1772void XMLCALL
1773XML_SetAttlistDeclHandler(XML_Parser p,
1774                          XML_AttlistDeclHandler attdecl);
1775</pre>
1776<pre class="signature">
1777typedef void
1778(XMLCALL *XML_AttlistDeclHandler)(void           *userData,
1779                                  const XML_Char *elname,
1780                                  const XML_Char *attname,
1781                                  const XML_Char *att_type,
1782                                  const XML_Char *dflt,
1783                                  int            isrequired);
1784</pre>
1785<p>Set a handler for attlist declarations in the DTD. This handler is
1786called for <em>each</em> attribute. So a single attlist declaration
1787with multiple attributes declared will generate multiple calls to this
1788handler. The <code>elname</code> parameter returns the name of the
1789element for which the attribute is being declared. The attribute name
1790is in the <code>attname</code> parameter. The attribute type is in the
1791<code>att_type</code> parameter.  It is the string representing the
1792type in the declaration with whitespace removed.</p>
1793
1794<p>The <code>dflt</code> parameter holds the default value. It will be
1795NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. You can
1796distinguish these two cases by checking the <code>isrequired</code>
1797parameter, which will be true in the case of "#REQUIRED" attributes.
1798Attributes which are "#FIXED" will have also have a true
1799<code>isrequired</code>, but they will have the non-NULL fixed value
1800in the <code>dflt</code> parameter.</p>
1801</div>
1802
1803<div class="handler">
1804<pre class="setter" id="XML_SetEntityDeclHandler">
1805void XMLCALL
1806XML_SetEntityDeclHandler(XML_Parser p,
1807			 XML_EntityDeclHandler handler);
1808</pre>
1809<pre class="signature">
1810typedef void
1811(XMLCALL *XML_EntityDeclHandler)(void           *userData,
1812                                 const XML_Char *entityName,
1813                                 int            is_parameter_entity,
1814                                 const XML_Char *value,
1815                                 int            value_length,
1816                                 const XML_Char *base,
1817                                 const XML_Char *systemId,
1818                                 const XML_Char *publicId,
1819                                 const XML_Char *notationName);
1820</pre>
1821<p>Sets a handler that will be called for all entity declarations.
1822The <code>is_parameter_entity</code> argument will be non-zero in the
1823case of parameter entities and zero otherwise.</p>
1824
1825<p>For internal entities (<code>&lt;!ENTITY foo "bar"&gt;</code>),
1826<code>value</code> will be non-NULL and <code>systemId</code>,
1827<code>publicId</code>, and <code>notationName</code> will all be NULL.
1828The value string is <em>not</em> NULL terminated; the length is
1829provided in the <code>value_length</code> parameter. Do not use
1830<code>value_length</code> to test for internal entities, since it is
1831legal to have zero-length values. Instead check for whether or not
1832<code>value</code> is NULL.</p> <p>The <code>notationName</code>
1833argument will have a non-NULL value only for unparsed entity
1834declarations.</p>
1835</div>
1836
1837<div class="handler">
1838<pre class="setter" id="XML_SetUnparsedEntityDeclHandler">
1839void XMLCALL
1840XML_SetUnparsedEntityDeclHandler(XML_Parser p,
1841                                 XML_UnparsedEntityDeclHandler h)
1842</pre>
1843<pre class="signature">
1844typedef void
1845(XMLCALL *XML_UnparsedEntityDeclHandler)(void *userData,
1846                                         const XML_Char *entityName,
1847                                         const XML_Char *base,
1848                                         const XML_Char *systemId,
1849                                         const XML_Char *publicId,
1850                                         const XML_Char *notationName);
1851</pre>
1852<p>Set a handler that receives declarations of unparsed entities. These
1853are entity declarations that have a notation (NDATA) field:</p>
1854
1855<div id="eg"><pre>
1856&lt;!ENTITY logo SYSTEM "images/logo.gif" NDATA gif&gt;
1857</pre></div>
1858<p>This handler is obsolete and is provided for backwards
1859compatibility.  Use instead <a href= "#XML_SetEntityDeclHandler"
1860>XML_SetEntityDeclHandler</a>.</p>
1861</div>
1862
1863<div class="handler">
1864<pre class="setter" id="XML_SetNotationDeclHandler">
1865void XMLCALL
1866XML_SetNotationDeclHandler(XML_Parser p,
1867                           XML_NotationDeclHandler h)
1868</pre>
1869<pre class="signature">
1870typedef void
1871(XMLCALL *XML_NotationDeclHandler)(void *userData,
1872                                   const XML_Char *notationName,
1873                                   const XML_Char *base,
1874                                   const XML_Char *systemId,
1875                                   const XML_Char *publicId);
1876</pre>
1877<p>Set a handler that receives notation declarations.</p>
1878</div>
1879
1880<div class="handler">
1881<pre class="setter" id="XML_SetNotStandaloneHandler">
1882void XMLCALL
1883XML_SetNotStandaloneHandler(XML_Parser p,
1884                            XML_NotStandaloneHandler h)
1885</pre>
1886<pre class="signature">
1887typedef int
1888(XMLCALL *XML_NotStandaloneHandler)(void *userData);
1889</pre>
1890<p>Set a handler that is called if the document is not "standalone".
1891This happens when there is an external subset or a reference to a
1892parameter entity, but does not have standalone set to "yes" in an XML
1893declaration.  If this handler returns <code>XML_STATUS_ERROR</code>,
1894then the parser will throw an <code>XML_ERROR_NOT_STANDALONE</code>
1895error.</p>
1896</div>
1897
1898<h3><a name="position">Parse position and error reporting functions</a></h3>
1899
1900<p>These are the functions you'll want to call when the parse
1901functions return <code>XML_STATUS_ERROR</code> (a parse error has
1902occurred), although the position reporting functions are useful outside
1903of errors. The position reported is the byte position (in the original
1904document or entity encoding) of the first of the sequence of
1905characters that generated the current event (or the error that caused
1906the parse functions to return <code>XML_STATUS_ERROR</code>.)  The
1907exceptions are callbacks trigged by declarations in the document
1908prologue, in which case they exact position reported is somewhere in the
1909relevant markup, but not necessarily as meaningful as for other
1910events.</p>
1911
1912<p>The position reporting functions are accurate only outside of the
1913DTD.  In other words, they usually return bogus information when
1914called from within a DTD declaration handler.</p>
1915
1916<pre class="fcndec" id="XML_GetErrorCode">
1917enum XML_Error XMLCALL
1918XML_GetErrorCode(XML_Parser p);
1919</pre>
1920<div class="fcndef">
1921Return what type of error has occurred.
1922</div>
1923
1924<pre class="fcndec" id="XML_ErrorString">
1925const XML_LChar * XMLCALL
1926XML_ErrorString(enum XML_Error code);
1927</pre>
1928<div class="fcndef">
1929Return a string describing the error corresponding to code.
1930The code should be one of the enums that can be returned from
1931<code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>.
1932</div>
1933
1934<pre class="fcndec" id="XML_GetCurrentByteIndex">
1935XML_Index XMLCALL
1936XML_GetCurrentByteIndex(XML_Parser p);
1937</pre>
1938<div class="fcndef">
1939Return the byte offset of the position.  This always corresponds to
1940the values returned by <code><a href= "#XML_GetCurrentLineNumber"
1941>XML_GetCurrentLineNumber</a></code> and <code><a href=
1942"#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>.
1943</div>
1944
1945<pre class="fcndec" id="XML_GetCurrentLineNumber">
1946XML_Size XMLCALL
1947XML_GetCurrentLineNumber(XML_Parser p);
1948</pre>
1949<div class="fcndef">
1950Return the line number of the position.  The first line is reported as
1951<code>1</code>.
1952</div>
1953
1954<pre class="fcndec" id="XML_GetCurrentColumnNumber">
1955XML_Size XMLCALL
1956XML_GetCurrentColumnNumber(XML_Parser p);
1957</pre>
1958<div class="fcndef">
1959Return the offset, from the beginning of the current line, of
1960the position.
1961</div>
1962
1963<pre class="fcndec" id="XML_GetCurrentByteCount">
1964int XMLCALL
1965XML_GetCurrentByteCount(XML_Parser p);
1966</pre>
1967<div class="fcndef">
1968Return the number of bytes in the current event. Returns
1969<code>0</code> if the event is inside a reference to an internal
1970entity and for the end-tag event for empty element tags (the later can
1971be used to distinguish empty-element tags from empty elements using
1972separate start and end tags).
1973</div>
1974
1975<pre class="fcndec" id="XML_GetInputContext">
1976const char * XMLCALL
1977XML_GetInputContext(XML_Parser p,
1978                    int *offset,
1979                    int *size);
1980</pre>
1981<div class="fcndef">
1982
1983<p>Returns the parser's input buffer, sets the integer pointed at by
1984<code>offset</code> to the offset within this buffer of the current
1985parse position, and set the integer pointed at by <code>size</code> to
1986the size of the returned buffer.</p>
1987
1988<p>This should only be called from within a handler during an active
1989parse and the returned buffer should only be referred to from within
1990the handler that made the call. This input buffer contains the
1991untranslated bytes of the input.</p>
1992
1993<p>Only a limited amount of context is kept, so if the event
1994triggering a call spans over a very large amount of input, the actual
1995parse position may be before the beginning of the buffer.</p>
1996
1997<p>If <code>XML_CONTEXT_BYTES</code> is not defined, this will always
1998return NULL.</p>
1999</div>
2000
2001<h3><a name="miscellaneous">Miscellaneous functions</a></h3>
2002
2003<p>The functions in this section either obtain state information from
2004the parser or can be used to dynamically set parser options.</p>
2005
2006<pre class="fcndec" id="XML_SetUserData">
2007void XMLCALL
2008XML_SetUserData(XML_Parser p,
2009                void *userData);
2010</pre>
2011<div class="fcndef">
2012This sets the user data pointer that gets passed to handlers.  It
2013overwrites any previous value for this pointer. Note that the
2014application is responsible for freeing the memory associated with
2015<code>userData</code> when it is finished with the parser. So if you
2016call this when there's already a pointer there, and you haven't freed
2017the memory associated with it, then you've probably just leaked
2018memory.
2019</div>
2020
2021<pre class="fcndec" id="XML_GetUserData">
2022void * XMLCALL
2023XML_GetUserData(XML_Parser p);
2024</pre>
2025<div class="fcndef">
2026This returns the user data pointer that gets passed to handlers.
2027It is actually implemented as a macro.
2028</div>
2029
2030<pre class="fcndec" id="XML_UseParserAsHandlerArg">
2031void XMLCALL
2032XML_UseParserAsHandlerArg(XML_Parser p);
2033</pre>
2034<div class="fcndef">
2035After this is called, handlers receive the parser in their
2036<code>userData</code> arguments.  The user data can still be obtained
2037using the <code><a href= "#XML_GetUserData"
2038>XML_GetUserData</a></code> function.
2039</div>
2040
2041<pre class="fcndec" id="XML_SetBase">
2042enum XML_Status XMLCALL
2043XML_SetBase(XML_Parser p,
2044            const XML_Char *base);
2045</pre>
2046<div class="fcndef">
2047Set the base to be used for resolving relative URIs in system
2048identifiers.  The return value is <code>XML_STATUS_ERROR</code> if
2049there's no memory to store base, otherwise it's
2050<code>XML_STATUS_OK</code>.
2051</div>
2052
2053<pre class="fcndec" id="XML_GetBase">
2054const XML_Char * XMLCALL
2055XML_GetBase(XML_Parser p);
2056</pre>
2057<div class="fcndef">
2058Return the base for resolving relative URIs.
2059</div>
2060
2061<pre class="fcndec" id="XML_GetSpecifiedAttributeCount">
2062int XMLCALL
2063XML_GetSpecifiedAttributeCount(XML_Parser p);
2064</pre>
2065<div class="fcndef">
2066When attributes are reported to the start handler in the atts vector,
2067attributes that were explicitly set in the element occur before any
2068attributes that receive their value from default information in an
2069ATTLIST declaration. This function returns the number of attributes
2070that were explicitly set times two, thus giving the offset in the
2071<code>atts</code> array passed to the start tag handler of the first
2072attribute set due to defaults. It supplies information for the last
2073call to a start handler. If called inside a start handler, then that
2074means the current call.
2075</div>
2076
2077<pre class="fcndec" id="XML_GetIdAttributeIndex">
2078int XMLCALL
2079XML_GetIdAttributeIndex(XML_Parser p);
2080</pre>
2081<div class="fcndef">
2082Returns the index of the ID attribute passed in the atts array in the
2083last call to <code><a href= "#XML_StartElementHandler"
2084>XML_StartElementHandler</a></code>, or -1 if there is no ID
2085attribute. If called inside a start handler, then that means the
2086current call.
2087</div>
2088
2089<pre class="fcndec" id="XML_GetAttributeInfo">
2090const XML_AttrInfo * XMLCALL
2091XML_GetAttributeInfo(XML_Parser parser);
2092</pre>
2093<pre class="signature">
2094typedef struct {
2095  XML_Index  nameStart;  /* Offset to beginning of the attribute name. */
2096  XML_Index  nameEnd;    /* Offset after the attribute name's last byte. */
2097  XML_Index  valueStart; /* Offset to beginning of the attribute value. */
2098  XML_Index  valueEnd;   /* Offset after the attribute value's last byte. */
2099} XML_AttrInfo;
2100</pre>
2101<div class="fcndef">
2102Returns an array of <code>XML_AttrInfo</code> structures for the
2103attribute/value pairs passed in the last call to the
2104<code>XML_StartElementHandler</code> that were specified
2105in the start-tag rather than defaulted. Each attribute/value pair counts
2106as 1; thus the number of entries in the array is
2107<code>XML_GetSpecifiedAttributeCount(parser) / 2</code>.
2108</div>
2109
2110<pre class="fcndec" id="XML_SetEncoding">
2111enum XML_Status XMLCALL
2112XML_SetEncoding(XML_Parser p,
2113                const XML_Char *encoding);
2114</pre>
2115<div class="fcndef">
2116Set the encoding to be used by the parser. It is equivalent to
2117passing a non-null encoding argument to the parser creation functions.
2118It must not be called after <code><a href= "#XML_Parse"
2119>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
2120>XML_ParseBuffer</a></code> have been called on the given parser.
2121Returns <code>XML_STATUS_OK</code> on success or
2122<code>XML_STATUS_ERROR</code> on error.
2123</div>
2124
2125<pre class="fcndec" id="XML_SetParamEntityParsing">
2126int XMLCALL
2127XML_SetParamEntityParsing(XML_Parser p,
2128                          enum XML_ParamEntityParsing code);
2129</pre>
2130<div class="fcndef">
2131This enables parsing of parameter entities, including the external
2132parameter entity that is the external DTD subset, according to
2133<code>code</code>.
2134The choices for <code>code</code> are:
2135<ul>
2136<li><code>XML_PARAM_ENTITY_PARSING_NEVER</code></li>
2137<li><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></li>
2138<li><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></li>
2139</ul>
2140<b>Note:</b> If <code>XML_SetParamEntityParsing</code> is called after
2141<code>XML_Parse</code> or <code>XML_ParseBuffer</code>, then it has
2142no effect and will always return 0.
2143</div>
2144
2145<pre class="fcndec" id="XML_SetHashSalt">
2146int XMLCALL
2147XML_SetHashSalt(XML_Parser p,
2148                unsigned long hash_salt);
2149</pre>
2150<div class="fcndef">
2151Sets the hash salt to use for internal hash calculations.
2152Helps in preventing DoS attacks based on predicting hash
2153function behavior. In order to have an effect this must be called
2154before parsing has started. Returns 1 if successful, 0 when called
2155after <code>XML_Parse</code> or <code>XML_ParseBuffer</code>.
2156<p><b>Note:</b>This call is optional, as the parser will auto-generate
2157a new random salt value if no value has been set at the start of parsing.</p>
2158<p><b>Note:</b>One should not call <code>XML_SetHashSalt</code> with a
2159hash salt value of 0, as this value is used as sentinel value to indicate
2160that <code>XML_SetHashSalt</code> has <b>not</b> been called. Consequently
2161such a call will have no effect, even if it returns 1.</p>
2162</div>
2163
2164<pre class="fcndec" id="XML_UseForeignDTD">
2165enum XML_Error XMLCALL
2166XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
2167</pre>
2168<div class="fcndef">
2169<p>This function allows an application to provide an external subset
2170for the document type declaration for documents which do not specify
2171an external subset of their own.  For documents which specify an
2172external subset in their DOCTYPE declaration, the application-provided
2173subset will be ignored.  If the document does not contain a DOCTYPE
2174declaration at all and <code>useDTD</code> is true, the
2175application-provided subset will be parsed, but the
2176<code>startDoctypeDeclHandler</code> and
2177<code>endDoctypeDeclHandler</code> functions, if set, will not be
2178called.  The setting of parameter entity parsing, controlled using
2179<code><a href= "#XML_SetParamEntityParsing"
2180>XML_SetParamEntityParsing</a></code>, will be honored.</p>
2181
2182<p>The application-provided external subset is read by calling the
2183external entity reference handler set via <code><a href=
2184"#XML_SetExternalEntityRefHandler"
2185>XML_SetExternalEntityRefHandler</a></code> with both
2186<code>publicId</code> and <code>systemId</code> set to NULL.</p>
2187
2188<p>If this function is called after parsing has begun, it returns
2189<code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores
2190<code>useDTD</code>.  If called when Expat has been compiled without
2191DTD support, it returns
2192<code>XML_ERROR_FEATURE_REQUIRES_XML_DTD</code>.  Otherwise, it
2193returns <code>XML_ERROR_NONE</code>.</p>
2194
2195<p><b>Note:</b> For the purpose of checking WFC: Entity Declared, passing
2196<code>useDTD == XML_TRUE</code> will make the parser behave as if
2197the document had a DTD with an external subset. This holds true even if
2198the external entity reference handler returns without action.</p>
2199</div>
2200
2201<pre class="fcndec" id="XML_SetReturnNSTriplet">
2202void XMLCALL
2203XML_SetReturnNSTriplet(XML_Parser parser,
2204                       int        do_nst);
2205</pre>
2206<div class="fcndef">
2207<p>
2208This function only has an effect when using a parser created with
2209<code><a href= "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>,
2210i.e. when namespace processing is in effect. The <code>do_nst</code>
2211sets whether or not prefixes are returned with names qualified with a
2212namespace prefix. If this function is called with <code>do_nst</code>
2213non-zero, then afterwards namespace qualified names (that is qualified
2214with a prefix as opposed to belonging to a default namespace) are
2215returned as a triplet with the three parts separated by the namespace
2216separator specified when the parser was created.  The order of
2217returned parts is URI, local name, and prefix.</p> <p>If
2218<code>do_nst</code> is zero, then namespaces are reported in the
2219default manner, URI then local_name separated by the namespace
2220separator.</p>
2221</div>
2222
2223<pre class="fcndec" id="XML_DefaultCurrent">
2224void XMLCALL
2225XML_DefaultCurrent(XML_Parser parser);
2226</pre>
2227<div class="fcndef">
2228This can be called within a handler for a start element, end element,
2229processing instruction or character data.  It causes the corresponding
2230markup to be passed to the default handler set by <code><a
2231href="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or
2232<code><a href="#XML_SetDefaultHandlerExpand"
2233>XML_SetDefaultHandlerExpand</a></code>.  It does nothing if there is
2234not a default handler.
2235</div>
2236
2237<pre class="fcndec" id="XML_ExpatVersion">
2238XML_LChar * XMLCALL
2239XML_ExpatVersion();
2240</pre>
2241<div class="fcndef">
2242Return the library version as a string (e.g. <code>"expat_1.95.1"</code>).
2243</div>
2244
2245<pre class="fcndec" id="XML_ExpatVersionInfo">
2246struct XML_Expat_Version XMLCALL
2247XML_ExpatVersionInfo();
2248</pre>
2249<pre class="signature">
2250typedef struct {
2251  int major;
2252  int minor;
2253  int micro;
2254} XML_Expat_Version;
2255</pre>
2256<div class="fcndef">
2257Return the library version information as a structure.
2258Some macros are also defined that support compile-time tests of the
2259library version:
2260<ul>
2261<li><code>XML_MAJOR_VERSION</code></li>
2262<li><code>XML_MINOR_VERSION</code></li>
2263<li><code>XML_MICRO_VERSION</code></li>
2264</ul>
2265Testing these constants is currently the best way to determine if
2266particular parts of the Expat API are available.
2267</div>
2268
2269<pre class="fcndec" id="XML_GetFeatureList">
2270const XML_Feature * XMLCALL
2271XML_GetFeatureList();
2272</pre>
2273<pre class="signature">
2274enum XML_FeatureEnum {
2275  XML_FEATURE_END = 0,
2276  XML_FEATURE_UNICODE,
2277  XML_FEATURE_UNICODE_WCHAR_T,
2278  XML_FEATURE_DTD,
2279  XML_FEATURE_CONTEXT_BYTES,
2280  XML_FEATURE_MIN_SIZE,
2281  XML_FEATURE_SIZEOF_XML_CHAR,
2282  XML_FEATURE_SIZEOF_XML_LCHAR,
2283  XML_FEATURE_NS,
2284  XML_FEATURE_LARGE_SIZE
2285};
2286
2287typedef struct {
2288  enum XML_FeatureEnum  feature;
2289  XML_LChar            *name;
2290  long int              value;
2291} XML_Feature;
2292</pre>
2293<div class="fcndef">
2294<p>Returns a list of "feature" records, providing details on how
2295Expat was configured at compile time.  Most applications should not
2296need to worry about this, but this information is otherwise not
2297available from Expat.  This function allows code that does need to
2298check these features to do so at runtime.</p>
2299
2300<p>The return value is an array of <code>XML_Feature</code>,
2301terminated by a record with a <code>feature</code> of
2302<code>XML_FEATURE_END</code> and <code>name</code> of NULL,
2303identifying the feature-test macros Expat was compiled with.  Since an
2304application that requires this kind of information needs to determine
2305the type of character the <code>name</code> points to, records for the
2306<code>XML_FEATURE_SIZEOF_XML_CHAR</code> and
2307<code>XML_FEATURE_SIZEOF_XML_LCHAR</code> will be located at the
2308beginning of the list, followed by <code>XML_FEATURE_UNICODE</code>
2309and <code>XML_FEATURE_UNICODE_WCHAR_T</code>, if they are present at
2310all.</p>
2311
2312<p>Some features have an associated value.  If there isn't an
2313associated value, the <code>value</code> field is set to 0.  At this
2314time, the following features have been defined to have values:</p>
2315
2316<dl>
2317  <dt><code>XML_FEATURE_SIZEOF_XML_CHAR</code></dt>
2318  <dd>The number of bytes occupied by one <code>XML_Char</code>
2319  character.</dd>
2320  <dt><code>XML_FEATURE_SIZEOF_XML_LCHAR</code></dt>
2321  <dd>The number of bytes occupied by one <code>XML_LChar</code>
2322  character.</dd>
2323  <dt><code>XML_FEATURE_CONTEXT_BYTES</code></dt>
2324  <dd>The maximum number of characters of context which can be
2325  reported by <code><a href= "#XML_GetInputContext"
2326  >XML_GetInputContext</a></code>.</dd>
2327</dl>
2328</div>
2329
2330<pre class="fcndec" id="XML_FreeContentModel">
2331void XMLCALL
2332XML_FreeContentModel(XML_Parser parser, XML_Content *model);
2333</pre>
2334<div class="fcndef">
2335Function to deallocate the <code>model</code> argument passed to the
2336<code>XML_ElementDeclHandler</code> callback set using <code><a
2337href="#XML_SetElementDeclHandler" >XML_ElementDeclHandler</a></code>.
2338This function should not be used for any other purpose.
2339</div>
2340
2341<p>The following functions allow external code to share the memory
2342allocator an <code>XML_Parser</code> has been configured to use.  This
2343is especially useful for third-party libraries that interact with a
2344parser object created by application code, or heavily layered
2345applications.  This can be essential when using dynamically loaded
2346libraries which use different C standard libraries (this can happen on
2347Windows, at least).</p>
2348
2349<pre class="fcndec" id="XML_MemMalloc">
2350void * XMLCALL
2351XML_MemMalloc(XML_Parser parser, size_t size);
2352</pre>
2353<div class="fcndef">
2354Allocate <code>size</code> bytes of memory using the allocator the
2355<code>parser</code> object has been configured to use.  Returns a
2356pointer to the memory or NULL on failure.  Memory allocated in this
2357way must be freed using <code><a href="#XML_MemFree"
2358>XML_MemFree</a></code>.
2359</div>
2360
2361<pre class="fcndec" id="XML_MemRealloc">
2362void * XMLCALL
2363XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
2364</pre>
2365<div class="fcndef">
2366Allocate <code>size</code> bytes of memory using the allocator the
2367<code>parser</code> object has been configured to use.
2368<code>ptr</code> must point to a block of memory allocated by <code><a
2369href="#XML_MemMalloc" >XML_MemMalloc</a></code> or
2370<code>XML_MemRealloc</code>, or be NULL.  This function tries to
2371expand the block pointed to by <code>ptr</code> if possible.  Returns
2372a pointer to the memory or NULL on failure.  On success, the original
2373block has either been expanded or freed.  On failure, the original
2374block has not been freed; the caller is responsible for freeing the
2375original block.  Memory allocated in this way must be freed using
2376<code><a href="#XML_MemFree"
2377>XML_MemFree</a></code>.
2378</div>
2379
2380<pre class="fcndec" id="XML_MemFree">
2381void XMLCALL
2382XML_MemFree(XML_Parser parser, void *ptr);
2383</pre>
2384<div class="fcndef">
2385Free a block of memory pointed to by <code>ptr</code>.  The block must
2386have been allocated by <code><a href="#XML_MemMalloc"
2387>XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be NULL.
2388</div>
2389
2390<hr />
2391<p><a href="http://validator.w3.org/check/referer"><img
2392        src="valid-xhtml10.png" alt="Valid XHTML 1.0!"
2393        height="31" width="88" class="noborder" /></a></p>
2394</div>
2395</body>
2396</html>
2397