Deleted Added
full compact
reference.html (104349) reference.html (178848)
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>
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4<html>
5<head>
6<!-- Copyright 1999,2000 Clark Cooper <coopercc@netheaven.com>
7 All rights reserved.
8 This is free software. You may distribute or modify according to
9 the terms of the MIT/X License -->
10 <title>Expat XML Parser</title>
11 <meta name="author" content="Clark Cooper, coopercc@netheaven.com" />
12 <meta http-equiv="Content-Style-Type" content="text/css" />
13 <link href="style.css" rel="stylesheet" type="text/css" />
14</head>
15<body>
16<h1>Expat XML Parser</h1>
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">
17
18<p>Expat is a library, written in C, for parsing XML documents. It's
19the underlying XML parser for the open source Mozilla project, Perl's
20<code>XML::Parser</code>, Python's <code>xml.parsers.expat</code>, and
21other open-source XML parsers.</p>
22
23<p>This library is the creation of James Clark, who's also given us
24groff (an nroff look-alike), Jade (an implemention of ISO's DSSSL
25stylesheet language for SGML), XP (a Java XML parser package), XT (a
26Java XSL engine). James was also the technical lead on the XML
27Working Group at W3C that produced the XML specification.</p>
28
29<p>This is free software, licensed under the <a
30href="../COPYING">MIT/X Consortium license</a>. You may download it
31from <a href="http://www.libexpat.org/">the Expat home page</a>.
32</p>
33
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 implemention 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
34<p>The bulk of this document was originally commissioned as an article by
35XML.com. They graciously allowed
36Clark Cooper to retain copyright and to distribute it with Expat.</p>
44

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>

37
38<hr />
39<h2>Table of Contents</h2>
40<ul>
41 <li><a href="#overview">Overview</a></li>
42 <li><a href="#building">Building and Installing</a></li>
43 <li><a href="#using">Using Expat</a></li>
44 <li><a href="#reference">Reference</a>

--- 8 unchanged lines hidden (view full) ---

53 <li><a href="#XML_ParserReset">XML_ParserReset</a></li>
54 </ul>
55 </li>
56 <li><a href="#parsing">Parsing Functions</a>
57 <ul>
58 <li><a href="#XML_Parse">XML_Parse</a></li>
59 <li><a href="#XML_ParseBuffer">XML_ParseBuffer</a></li>
60 <li><a href="#XML_GetBuffer">XML_GetBuffer</a></li>
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>

--- 8 unchanged lines hidden (view full) ---

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>
61 </ul>
62 </li>
63 <li><a href="#setting">Handler Setting Functions</a>
64 <ul>
65 <li><a href="#XML_SetStartElementHandler">XML_SetStartElementHandler</a></li>
66 <li><a href="#XML_SetEndElementHandler">XML_SetEndElementHandler</a></li>
67 <li><a href="#XML_SetElementHandler">XML_SetElementHandler</a></li>
68 <li><a href="#XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</a></li>
69 <li><a href="#XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</a></li>
70 <li><a href="#XML_SetCommentHandler">XML_SetCommentHandler</a></li>
71 <li><a href="#XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</a></li>
72 <li><a href="#XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</a></li>
73 <li><a href="#XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</a></li>
74 <li><a href="#XML_SetDefaultHandler">XML_SetDefaultHandler</a></li>
75 <li><a href="#XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</a></li>
76 <li><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></li>
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>
77 <li><a href="#XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</a></li>
78 <li><a href="#XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</a></li>
79 <li><a href="#XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</a></li>
80 <li><a href="#XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</a></li>
81 <li><a href="#XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</a></li>
82 <li><a href="#XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</a></li>
83 <li><a href="#XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</a></li>
84 <li><a href="#XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</a></li>

--- 29 unchanged lines hidden (view full) ---

114 <li><a href="#XML_SetEncoding">XML_SetEncoding</a></li>
115 <li><a href="#XML_SetParamEntityParsing">XML_SetParamEntityParsing</a></li>
116 <li><a href="#XML_UseForeignDTD">XML_UseForeignDTD</a></li>
117 <li><a href="#XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a></li>
118 <li><a href="#XML_DefaultCurrent">XML_DefaultCurrent</a></li>
119 <li><a href="#XML_ExpatVersion">XML_ExpatVersion</a></li>
120 <li><a href="#XML_ExpatVersionInfo">XML_ExpatVersionInfo</a></li>
121 <li><a href="#XML_GetFeatureList">XML_GetFeatureList</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>

--- 29 unchanged lines hidden (view full) ---

132 <li><a href="#XML_SetEncoding">XML_SetEncoding</a></li>
133 <li><a href="#XML_SetParamEntityParsing">XML_SetParamEntityParsing</a></li>
134 <li><a href="#XML_UseForeignDTD">XML_UseForeignDTD</a></li>
135 <li><a href="#XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a></li>
136 <li><a href="#XML_DefaultCurrent">XML_DefaultCurrent</a></li>
137 <li><a href="#XML_ExpatVersion">XML_ExpatVersion</a></li>
138 <li><a href="#XML_ExpatVersionInfo">XML_ExpatVersionInfo</a></li>
139 <li><a href="#XML_GetFeatureList">XML_GetFeatureList</a></li>
140 <li><a href="#XML_FreeContentModel">XML_FreeContentModel</a></li>
141 <li><a href="#XML_MemMalloc">XML_MemMalloc</a></li>
142 <li><a href="#XML_MemRealloc">XML_MemRealloc</a></li>
143 <li><a href="#XML_MemFree">XML_MemFree</a></li>
122 </ul>
123 </li>
124 </ul>
125 </li>
126</ul>
127
128<hr />
129<h2><a name="overview">Overview</a></h2>

--- 42 unchanged lines hidden (view full) ---

172work. It prints two indenting spaces for every level of ancestor
173elements, then it prints the element and attribute
174information. Finally it increments the global <code>Depth</code>
175variable.</p>
176
177<pre class="eg">
178int Depth;
179
144 </ul>
145 </li>
146 </ul>
147 </li>
148</ul>
149
150<hr />
151<h2><a name="overview">Overview</a></h2>

--- 42 unchanged lines hidden (view full) ---

194work. It prints two indenting spaces for every level of ancestor
195elements, then it prints the element and attribute
196information. Finally it increments the global <code>Depth</code>
197variable.</p>
198
199<pre class="eg">
200int Depth;
201
180void
202void XMLCALL
181start(void *data, const char *el, const char **attr) {
182 int i;
183
184 for (i = 0; i &lt; Depth; i++)
185 printf(" ");
186
187 printf("%s", el);
188

--- 4 unchanged lines hidden (view full) ---

193 printf("\n");
194 Depth++;
195} /* End of start handler */
196</pre>
197
198<p>The end tag simply does the bookkeeping work of decrementing
199<code>Depth</code>.</p>
200<pre class="eg">
203start(void *data, const char *el, const char **attr) {
204 int i;
205
206 for (i = 0; i &lt; Depth; i++)
207 printf(" ");
208
209 printf("%s", el);
210

--- 4 unchanged lines hidden (view full) ---

215 printf("\n");
216 Depth++;
217} /* End of start handler */
218</pre>
219
220<p>The end tag simply does the bookkeeping work of decrementing
221<code>Depth</code>.</p>
222<pre class="eg">
201void
223void XMLCALL
202end(void *data, const char *el) {
203 Depth--;
204} /* End of end handler */
205</pre>
206
224end(void *data, const char *el) {
225 Depth--;
226} /* End of end handler */
227</pre>
228
229<p>Note the <code>XMLCALL</code> annotation used for the callbacks.
230This is used to ensure that the Expat and the callbacks are using the
231same calling convention in case the compiler options used for Expat
232itself and the client code are different. Expat tries not to care
233what the default calling convention is, though it may require that it
234be compiled with a default convention of "cdecl" on some platforms.
235For code which uses Expat, however, the calling convention is
236specified by the <code>XMLCALL</code> annotation on most platforms;
237callbacks should be defined using this annotation.</p>
238
239<p>The <code>XMLCALL</code> annotation was added in Expat 1.95.7, but
240existing working Expat applications don't need to add it (since they
241are already using the "cdecl" calling convention, or they wouldn't be
242working). The annotation is only needed if the default calling
243convention may be something other than "cdecl". To use the annotation
244safely with older versions of Expat, you can conditionally define it
245<em>after</em> including Expat's header file:</p>
246
247<pre class="eg">
248#include &lt;expat.h&gt;
249
250#ifndef XMLCALL
251#if defined(_MSC_EXTENSIONS) &amp;&amp; !defined(__BEOS__) &amp;&amp; !defined(__CYGWIN__)
252#define XMLCALL __cdecl
253#elif defined(__GNUC__)
254#define XMLCALL __attribute__((cdecl))
255#else
256#define XMLCALL
257#endif
258#endif
259</pre>
260
207<p>After creating the parser, the main program just has the job of
208shoveling the document to the parser so that it can do its work.</p>
209
210<hr />
211<h2><a name="building">Building and Installing Expat</a></h2>
212
213<p>The Expat distribution comes as a compressed (with GNU gzip) tar
214file. You may download the latest version from <a href=

--- 17 unchanged lines hidden (view full) ---

232<p>First you'll need to run the configure shell script in order to
233configure the Makefiles and headers for your system.</p>
234
235<p>If you're happy with all the defaults that configure picks for you,
236and you have permission on your system to install into /usr/local, you
237can install Expat with this sequence of commands:</p>
238
239<pre class="eg">
261<p>After creating the parser, the main program just has the job of
262shoveling the document to the parser so that it can do its work.</p>
263
264<hr />
265<h2><a name="building">Building and Installing Expat</a></h2>
266
267<p>The Expat distribution comes as a compressed (with GNU gzip) tar
268file. You may download the latest version from <a href=

--- 17 unchanged lines hidden (view full) ---

286<p>First you'll need to run the configure shell script in order to
287configure the Makefiles and headers for your system.</p>
288
289<p>If you're happy with all the defaults that configure picks for you,
290and you have permission on your system to install into /usr/local, you
291can install Expat with this sequence of commands:</p>
292
293<pre class="eg">
240 ./configure
241 make
242 make install
294./configure
295make
296make install
243</pre>
244
245<p>There are some options that you can provide to this script, but the
246only one we'll mention here is the <code>--prefix</code> option. You
247can find out all the options available by running configure with just
248the <code>--help</code> option.</p>
249
250<p>By default, the configure script sets things up so that the library
251gets installed in <code>/usr/local/lib</code> and the associated
252header file in <code>/usr/local/include</code>. But if you were to
253give the option, <code>--prefix=/home/me/mystuff</code>, then the
254library and header would get installed in
255<code>/home/me/mystuff/lib</code> and
256<code>/home/me/mystuff/include</code> respectively.</p>
257
297</pre>
298
299<p>There are some options that you can provide to this script, but the
300only one we'll mention here is the <code>--prefix</code> option. You
301can find out all the options available by running configure with just
302the <code>--help</code> option.</p>
303
304<p>By default, the configure script sets things up so that the library
305gets installed in <code>/usr/local/lib</code> and the associated
306header file in <code>/usr/local/include</code>. But if you were to
307give the option, <code>--prefix=/home/me/mystuff</code>, then the
308library and header would get installed in
309<code>/home/me/mystuff/lib</code> and
310<code>/home/me/mystuff/include</code> respectively.</p>
311
312<h3>Configuring Expat Using the Pre-Processor</h3>
313
314<p>Expat's feature set can be configured using a small number of
315pre-processor definitions. The definition of this symbols does not
316affect the set of entry points for Expat, only the behavior of the API
317and the definition of character types in the case of
318<code>XML_UNICODE_WCHAR_T</code>. The symbols are:</p>
319
320<dl class="cpp-symbols">
321<dt>XML_DTD</dt>
322<dd>Include support for using and reporting DTD-based content. If
323this is defined, default attribute values from an external DTD subset
324are reported and attribute value normalization occurs based on the
325type of attributes defined in the external subset. Without
326this, Expat has a smaller memory footprint and can be faster, but will
327not load external entities or process conditional sections. This does
328not affect the set of functions available in the API.</dd>
329
330<dt>XML_NS</dt>
331<dd>When defined, support for the <cite><a href=
332"http://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite>
333specification is included.</dd>
334
335<dt>XML_UNICODE</dt>
336<dd>When defined, character data reported to the application is
337encoded in UTF-16 using wide characters of the type
338<code>XML_Char</code>. This is implied if
339<code>XML_UNICODE_WCHAR_T</code> is defined.</dd>
340
341<dt>XML_UNICODE_WCHAR_T</dt>
342<dd>If defined, causes the <code>XML_Char</code> character type to be
343defined using the <code>wchar_t</code> type; otherwise, <code>unsigned
344short</code> is used. Defining this implies
345<code>XML_UNICODE</code>.</dd>
346
347<dt>XML_LARGE_SIZE</dt>
348<dd>If defined, causes the <code>XML_Size</code> and <code>XML_Index</code>
349integer types to be at least 64 bits in size. This is intended to support
350processing of very large input streams, where the return values of
351<code><a href="#XML_GetCurrentByteIndex" >XML_GetCurrentByteIndex</a></code>,
352<code><a href="#XML_GetCurrentLineNumber" >XML_GetCurrentLineNumber</a></code> and
353<code><a href="#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>
354could overflow. It may not be supported by all compilers, and is turned
355off by default.</dd>
356
357<dt>XML_CONTEXT_BYTES</dt>
358<dd>The number of input bytes of markup context which the parser will
359ensure are available for reporting via <code><a href=
360"#XML_GetInputContext" >XML_GetInputContext</a></code>. This is
361normally set to 1024, and must be set to a positive interger. If this
362is not defined, the input context will not be available and <code><a
363href= "#XML_GetInputContext" >XML_GetInputContext</a></code> will
364always report NULL. Without this, Expat has a smaller memory
365footprint and can be faster.</dd>
366
367<dt>XML_STATIC</dt>
368<dd>On Windows, this should be set if Expat is going to be linked
369statically with the code that calls it; this is required to get all
370the right MSVC magic annotations correct. This is ignored on other
371platforms.</dd>
372</dl>
373
258<hr />
259<h2><a name="using">Using Expat</a></h2>
260
261<h3>Compiling and Linking Against Expat</h3>
262
263<p>Unless you installed Expat in a location not expected by your
264compiler and linker, all you have to do to use Expat in your programs
265is to include the Expat header (<code>#include &lt;expat.h&gt;</code>)
266in your files that make calls to it and to tell the linker that it
267needs to link against the Expat library. On Unix systems, this would
268usually be done with the <code>-lexpat</code> argument. Otherwise,
269you'll need to tell the compiler where to look for the Expat header
270and the linker where to find the Expat library. You may also need to
374<hr />
375<h2><a name="using">Using Expat</a></h2>
376
377<h3>Compiling and Linking Against Expat</h3>
378
379<p>Unless you installed Expat in a location not expected by your
380compiler and linker, all you have to do to use Expat in your programs
381is to include the Expat header (<code>#include &lt;expat.h&gt;</code>)
382in your files that make calls to it and to tell the linker that it
383needs to link against the Expat library. On Unix systems, this would
384usually be done with the <code>-lexpat</code> argument. Otherwise,
385you'll need to tell the compiler where to look for the Expat header
386and the linker where to find the Expat library. You may also need to
271take steps to tell the operating system where to find this libary at
387take steps to tell the operating system where to find this library at
272run time.</p>
273
274<p>On a Unix-based system, here's what a Makefile might look like when
275Expat is installed in a standard location:</p>
276
277<pre class="eg">
278CC=cc
279LDFLAGS=

--- 28 unchanged lines hidden (view full) ---

308parser object. However, only two of these (<code><a href=
309"#XML_ParserCreate" >XML_ParserCreate</a></code> and <code><a href=
310"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>) can be used for
311constructing a parser for a top-level document. The object returned
312by these functions is an opaque pointer (i.e. "expat.h" declares it as
313void *) to data with further internal structure. In order to free the
314memory associated with this object you must call <code><a href=
315"#XML_ParserFree" >XML_ParserFree</a></code>. Note that if you have
388run time.</p>
389
390<p>On a Unix-based system, here's what a Makefile might look like when
391Expat is installed in a standard location:</p>
392
393<pre class="eg">
394CC=cc
395LDFLAGS=

--- 28 unchanged lines hidden (view full) ---

424parser object. However, only two of these (<code><a href=
425"#XML_ParserCreate" >XML_ParserCreate</a></code> and <code><a href=
426"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>) can be used for
427constructing a parser for a top-level document. The object returned
428by these functions is an opaque pointer (i.e. "expat.h" declares it as
429void *) to data with further internal structure. In order to free the
430memory associated with this object you must call <code><a href=
431"#XML_ParserFree" >XML_ParserFree</a></code>. Note that if you have
316provided any user data that gets stored in the
432provided any <a href="#userdata">user data</a> that gets stored in the
317parser, then your application is responsible for freeing it prior to
318calling <code>XML_ParserFree</code>.</p>
319
320<p>The objects returned by the parser creation functions are good for
321parsing only one XML document or external parsed entity. If your
322application needs to parse many XML documents, then it needs to create
323a parser object for each one. The best way to deal with this is to
324create a higher level object that contains all the default

--- 25 unchanged lines hidden (view full) ---

350<pre class="eg">
351void
352init_info(Parseinfo *info) {
353 info->skip = 0;
354 info->depth = 1;
355 /* Other initializations here */
356} /* End of init_info */
357
433parser, then your application is responsible for freeing it prior to
434calling <code>XML_ParserFree</code>.</p>
435
436<p>The objects returned by the parser creation functions are good for
437parsing only one XML document or external parsed entity. If your
438application needs to parse many XML documents, then it needs to create
439a parser object for each one. The best way to deal with this is to
440create a higher level object that contains all the default

--- 25 unchanged lines hidden (view full) ---

466<pre class="eg">
467void
468init_info(Parseinfo *info) {
469 info->skip = 0;
470 info->depth = 1;
471 /* Other initializations here */
472} /* End of init_info */
473
358void
474void XMLCALL
359rawstart(void *data, const char *el, const char **attr) {
360 Parseinfo *inf = (Parseinfo *) data;
361
362 if (! inf->skip) {
363 if (should_skip(inf, el, attr)) {
364 inf->skip = inf->depth;
365 }
366 else
367 start(inf, el, attr); /* This does rest of start handling */
368 }
369
370 inf->depth++;
371} /* End of rawstart */
372
475rawstart(void *data, const char *el, const char **attr) {
476 Parseinfo *inf = (Parseinfo *) data;
477
478 if (! inf->skip) {
479 if (should_skip(inf, el, attr)) {
480 inf->skip = inf->depth;
481 }
482 else
483 start(inf, el, attr); /* This does rest of start handling */
484 }
485
486 inf->depth++;
487} /* End of rawstart */
488
373void
489void XMLCALL
374rawend(void *data, const char *el) {
375 Parseinfo *inf = (Parseinfo *) data;
376
377 inf->depth--;
378
379 if (! inf->skip)
380 end(inf, el); /* This does rest of end handling */
381

--- 13 unchanged lines hidden (view full) ---

395handler.</p>
396
397<h3 id="userdata">Communicating between handlers</h3>
398
399<p>In order to be able to pass information between different handlers
400without using globals, you'll need to define a data structure to hold
401the shared variables. You can then tell Expat (with the <code><a href=
402"#XML_SetUserData" >XML_SetUserData</a></code> function) to pass a
490rawend(void *data, const char *el) {
491 Parseinfo *inf = (Parseinfo *) data;
492
493 inf->depth--;
494
495 if (! inf->skip)
496 end(inf, el); /* This does rest of end handling */
497

--- 13 unchanged lines hidden (view full) ---

511handler.</p>
512
513<h3 id="userdata">Communicating between handlers</h3>
514
515<p>In order to be able to pass information between different handlers
516without using globals, you'll need to define a data structure to hold
517the shared variables. You can then tell Expat (with the <code><a href=
518"#XML_SetUserData" >XML_SetUserData</a></code> function) to pass a
403pointer to this structure to the handlers. This is typically the first
404argument received by most handlers.</p>
519pointer to this structure to the handlers. This is the first
520argument received by most handlers. In the <a href="#reference"
521>reference section</a>, an argument to a callback function is named
522<code>userData</code> and have type <code>void *</code> if the user
523data is passed; it will have the type <code>XML_Parser</code> if the
524parser itself is passed. When the parser is passed, the user data may
525be retrieved using <code><a href="#XML_GetUserData"
526>XML_GetUserData</a></code>.</p>
405
527
528<p>One common case where multiple calls to a single handler may need
529to communicate using an application data structure is the case when
530content passed to the character data handler (set by <code><a href=
531"#XML_SetCharacterDataHandler"
532>XML_SetCharacterDataHandler</a></code>) needs to be accumulated. A
533common first-time mistake with any of the event-oriented interfaces to
534an XML parser is to expect all the text contained in an element to be
535reported by a single call to the character data handler. Expat, like
536many other XML parsers, reports such data as a sequence of calls;
537there's no way to know when the end of the sequence is reached until a
538different callback is made. A buffer referenced by the user data
539structure proves both an effective and convenient place to accumulate
540character data.</p>
541
542<!-- XXX example needed here -->
543
544
406<h3>XML Version</h3>
407
408<p>Expat is an XML 1.0 parser, and as such never complains based on
409the value of the <code>version</code> pseudo-attribute in the XML
410declaration, if present.</p>
411
412<p>If an application needs to check the version number (to support
413alternate processing), it should use the <code><a href=
414"#XML_SetXmlDeclHandler" >XML_SetXmlDeclHandler</a></code> function to
415set a handler that uses the information in the XML declaration to
416determine what to do. This example shows how to check that only a
417version number of <code>"1.0"</code> is accepted:</p>
418
419<pre class="eg">
420static int wrong_version;
421static XML_Parser parser;
422
545<h3>XML Version</h3>
546
547<p>Expat is an XML 1.0 parser, and as such never complains based on
548the value of the <code>version</code> pseudo-attribute in the XML
549declaration, if present.</p>
550
551<p>If an application needs to check the version number (to support
552alternate processing), it should use the <code><a href=
553"#XML_SetXmlDeclHandler" >XML_SetXmlDeclHandler</a></code> function to
554set a handler that uses the information in the XML declaration to
555determine what to do. This example shows how to check that only a
556version number of <code>"1.0"</code> is accepted:</p>
557
558<pre class="eg">
559static int wrong_version;
560static XML_Parser parser;
561
423static void
562static void XMLCALL
424xmldecl_handler(void *userData,
425 const XML_Char *version,
426 const XML_Char *encoding,
427 int standalone)
428{
429 static const XML_Char Version_1_0[] = {'1', '.', '0', 0};
430
431 int i;

--- 25 unchanged lines hidden (view full) ---

457><code>XML_SetNamespaceDeclHandler</code></a>.</p>
458
459<p>Element type and attribute names that belong to a given namespace
460are passed to the appropriate handler in expanded form. By default
461this expanded form is a concatenation of the namespace URI, the
462separator character (which is the 2nd argument to <code><a href=
463"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>), and the local
464name (i.e. the part after the colon). Names with undeclared prefixes
563xmldecl_handler(void *userData,
564 const XML_Char *version,
565 const XML_Char *encoding,
566 int standalone)
567{
568 static const XML_Char Version_1_0[] = {'1', '.', '0', 0};
569
570 int i;

--- 25 unchanged lines hidden (view full) ---

596><code>XML_SetNamespaceDeclHandler</code></a>.</p>
597
598<p>Element type and attribute names that belong to a given namespace
599are passed to the appropriate handler in expanded form. By default
600this expanded form is a concatenation of the namespace URI, the
601separator character (which is the 2nd argument to <code><a href=
602"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>), and the local
603name (i.e. the part after the colon). Names with undeclared prefixes
465are passed through to the handlers unchanged, with the prefix and
466colon still attached. Unprefixed attribute names are never expanded,
604are not well-formed when namespace processing is enabled, and will
605trigger an error. Unprefixed attribute names are never expanded,
467and unprefixed element names are only expanded when they are in the
468scope of a default namespace.</p>
469
606and unprefixed element names are only expanded when they are in the
607scope of a default namespace.</p>
608
470

However if

609<p>However if <code><a href= "#XML_SetReturnNSTriplet"
471>XML_SetReturnNSTriplet</a></code> has been called with a non-zero
472<code>do_nst</code> parameter, then the expanded form for names with
473an explicit prefix is a concatenation of: URI, separator, local name,
474separator, prefix.</p>
475
476<p>You can set handlers for the start of a namespace declaration and
477for the end of a scope of a declaration with the <code><a href=
478"#XML_SetNamespaceDeclHandler" >XML_SetNamespaceDeclHandler</a></code>
479function. The StartNamespaceDeclHandler is called prior to the start
610>XML_SetReturnNSTriplet</a></code> has been called with a non-zero
611<code>do_nst</code> parameter, then the expanded form for names with
612an explicit prefix is a concatenation of: URI, separator, local name,
613separator, prefix.</p>
614
615<p>You can set handlers for the start of a namespace declaration and
616for the end of a scope of a declaration with the <code><a href=
617"#XML_SetNamespaceDeclHandler" >XML_SetNamespaceDeclHandler</a></code>
618function. The StartNamespaceDeclHandler is called prior to the start
480tag handler and the EndNamespaceDeclHandler is called before the
619tag handler and the EndNamespaceDeclHandler is called after the
481corresponding end tag that ends the namespace's scope. The namespace
482start handler gets passed the prefix and URI for the namespace. For a
483default namespace declaration (xmlns='...'), the prefix will be null.
484The URI will be null for the case where the default namespace is being
485unset. The namespace end handler just gets the prefix for the closing
486scope.</p>
487
488<p>These handlers are called for each declaration. So if, for

--- 31 unchanged lines hidden (view full) ---

520<li>ISO-8859-1</li>
521<li>US-ASCII</li>
522</ul>
523
524<p>Anything else discovered in an encoding declaration or in the
525protocol encoding specified in the parser constructor, triggers a call
526to the <code>UnknownEncodingHandler</code>. This handler gets passed
527the encoding name and a pointer to an <code>XML_Encoding</code> data
620corresponding end tag that ends the namespace's scope. The namespace
621start handler gets passed the prefix and URI for the namespace. For a
622default namespace declaration (xmlns='...'), the prefix will be null.
623The URI will be null for the case where the default namespace is being
624unset. The namespace end handler just gets the prefix for the closing
625scope.</p>
626
627<p>These handlers are called for each declaration. So if, for

--- 31 unchanged lines hidden (view full) ---

659<li>ISO-8859-1</li>
660<li>US-ASCII</li>
661</ul>
662
663<p>Anything else discovered in an encoding declaration or in the
664protocol encoding specified in the parser constructor, triggers a call
665to the <code>UnknownEncodingHandler</code>. This handler gets passed
666the encoding name and a pointer to an <code>XML_Encoding</code> data
528structure. Your handler must fill in this structure and return 1 if it
529knows how to deal with the encoding. Otherwise the handler should
530return 0. The handler also gets passed a pointer to an optional
531application data structure that you may indicate when you set the
532handler.</p>
667structure. Your handler must fill in this structure and return
668<code>XML_STATUS_OK</code> if it knows how to deal with the
669encoding. Otherwise the handler should return
670<code>XML_STATUS_ERROR</code>. The handler also gets passed a pointer
671to an optional application data structure that you may indicate when
672you set the handler.</p>
533
534<p>Expat places restrictions on character encodings that it can
535support by filling in the <code>XML_Encoding</code> structure.
536include file:</p>
537<ol>
538<li>Every ASCII character that can appear in a well-formed XML document
539must be represented by a single byte, and that byte must correspond to
540it's ASCII encoding (except for the characters $@\^'{}~)</li>

--- 55 unchanged lines hidden (view full) ---

596<code>standalone</code> was set to "yes" in the XML declaration.</dd>
597<dt><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></dt>
598<dd>Always parse parameter entities and the external subset</dd>
599</dl>
600
601<p>In order to read an external DTD, you also have to set an external
602entity reference handler as described above.</p>
603
673
674<p>Expat places restrictions on character encodings that it can
675support by filling in the <code>XML_Encoding</code> structure.
676include file:</p>
677<ol>
678<li>Every ASCII character that can appear in a well-formed XML document
679must be represented by a single byte, and that byte must correspond to
680it's ASCII encoding (except for the characters $@\^'{}~)</li>

--- 55 unchanged lines hidden (view full) ---

736<code>standalone</code> was set to "yes" in the XML declaration.</dd>
737<dt><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></dt>
738<dd>Always parse parameter entities and the external subset</dd>
739</dl>
740
741<p>In order to read an external DTD, you also have to set an external
742entity reference handler as described above.</p>
743
744<h3 id="stop-resume">Temporarily Stopping Parsing</h3>
745
746<p>Expat 1.95.8 introduces a new feature: its now possible to stop
747parsing temporarily from within a handler function, even if more data
748has already been passed into the parser. Applications for this
749include</p>
750
751<ul>
752 <li>Supporting the <a href= "http://www.w3.org/TR/xinclude/"
753 >XInclude</a> specification.</li>
754
755 <li>Delaying further processing until additional information is
756 available from some other source.</li>
757
758 <li>Adjusting processor load as task priorities shift within an
759 application.</li>
760
761 <li>Stopping parsing completely (simply free or reset the parser
762 instead of resuming in the outer parsing loop). This can be useful
763 if a application-domain error is found in the XML being parsed or if
764 the result of the parse is determined not to be useful after
765 all.</li>
766</ul>
767
768<p>To take advantage of this feature, the main parsing loop of an
769application needs to support this specifically. It cannot be
770supported with a parsing loop compatible with Expat 1.95.7 or
771earlier (though existing loops will continue to work without
772supporting the stop/resume feature).</p>
773
774<p>An application that uses this feature for a single parser will have
775the rough structure (in pseudo-code):</p>
776
777<pre class="pseudocode">
778fd = open_input()
779p = create_parser()
780
781if parse_xml(p, fd) {
782 /* suspended */
783
784 int suspended = 1;
785
786 while (suspended) {
787 do_something_else()
788 if ready_to_resume() {
789 suspended = continue_parsing(p, fd);
790 }
791 }
792}
793</pre>
794
795<p>An application that may resume any of several parsers based on
796input (either from the XML being parsed or some other source) will
797certainly have more interesting control structures.</p>
798
799<p>This C function could be used for the <code>parse_xml</code>
800function mentioned in the pseudo-code above:</p>
801
802<pre class="eg">
803#define BUFF_SIZE 10240
804
805/* Parse a document from the open file descriptor 'fd' until the parse
806 is complete (the document has been completely parsed, or there's
807 been an error), or the parse is stopped. Return non-zero when
808 the parse is merely suspended.
809*/
810int
811parse_xml(XML_Parser p, int fd)
812{
813 for (;;) {
814 int last_chunk;
815 int bytes_read;
816 enum XML_Status status;
817
818 void *buff = XML_GetBuffer(p, BUFF_SIZE);
819 if (buff == NULL) {
820 /* handle error... */
821 return 0;
822 }
823 bytes_read = read(fd, buff, BUFF_SIZE);
824 if (bytes_read &lt; 0) {
825 /* handle error... */
826 return 0;
827 }
828 status = XML_ParseBuffer(p, bytes_read, bytes_read == 0);
829 switch (status) {
830 case XML_STATUS_ERROR:
831 /* handle error... */
832 return 0;
833 case XML_STATUS_SUSPENDED:
834 return 1;
835 }
836 if (bytes_read == 0)
837 return 0;
838 }
839}
840</pre>
841
842<p>The corresponding <code>continue_parsing</code> function is
843somewhat simpler, since it only need deal with the return code from
844<code><a href= "#XML_ResumeParser">XML_ResumeParser</a></code>; it can
845delegate the input handling to the <code>parse_xml</code>
846function:</p>
847
848<pre class="eg">
849/* Continue parsing a document which had been suspended. The 'p' and
850 'fd' arguments are the same as passed to parse_xml(). Return
851 non-zero when the parse is suspended.
852*/
853int
854continue_parsing(XML_Parser p, int fd)
855{
856 enum XML_Status status = XML_ResumeParser(p);
857 switch (status) {
858 case XML_STATUS_ERROR:
859 /* handle error... */
860 return 0;
861 case XML_ERROR_NOT_SUSPENDED:
862 /* handle error... */
863 return 0;.
864 case XML_STATUS_SUSPENDED:
865 return 1;
866 }
867 return parse_xml(p, fd);
868}
869</pre>
870
871<p>Now that we've seen what a mess the top-level parsing loop can
872become, what have we gained? Very simply, we can now use the <code><a
873href= "#XML_StopParser" >XML_StopParser</a></code> function to stop
874parsing, without having to go to great lengths to avoid additional
875processing that we're expecting to ignore. As a bonus, we get to stop
876parsing <em>temporarily</em>, and come back to it when we're
877ready.</p>
878
879<p>To stop parsing from a handler function, use the <code><a href=
880"#XML_StopParser" >XML_StopParser</a></code> function. This function
881takes two arguments; the parser being stopped and a flag indicating
882whether the parse can be resumed in the future.</p>
883
884<!-- XXX really need more here -->
885
886
604<hr />
605<!-- ================================================================ -->
606
607<h2><a name="reference">Expat Reference</a></h2>
608
609<h3><a name="creation">Parser Creation</a></h3>
610
611<pre class="fcndec" id="XML_ParserCreate">
887<hr />
888<!-- ================================================================ -->
889
890<h2><a name="reference">Expat Reference</a></h2>
891
892<h3><a name="creation">Parser Creation</a></h3>
893
894<pre class="fcndec" id="XML_ParserCreate">
612XML_Parser
895XML_Parser XMLCALL
613XML_ParserCreate(const XML_Char *encoding);
614</pre>
615<div class="fcndef">
616Construct a new parser. If encoding is non-null, it specifies a
617character encoding to use for the document. This overrides the document
618encoding declaration. There are four built-in encodings:
619<ul>
620<li>US-ASCII</li>
621<li>UTF-8</li>
622<li>UTF-16</li>
623<li>ISO-8859-1</li>
624</ul>
625Any other value will invoke a call to the UnknownEncodingHandler.
626</div>
627
628<pre class="fcndec" id="XML_ParserCreateNS">
896XML_ParserCreate(const XML_Char *encoding);
897</pre>
898<div class="fcndef">
899Construct a new parser. If encoding is non-null, it specifies a
900character encoding to use for the document. This overrides the document
901encoding declaration. There are four built-in encodings:
902<ul>
903<li>US-ASCII</li>
904<li>UTF-8</li>
905<li>UTF-16</li>
906<li>ISO-8859-1</li>
907</ul>
908Any other value will invoke a call to the UnknownEncodingHandler.
909</div>
910
911<pre class="fcndec" id="XML_ParserCreateNS">
629XML_Parser
912XML_Parser XMLCALL
630XML_ParserCreateNS(const XML_Char *encoding,
631 XML_Char sep);
632</pre>
633<div class="fcndef">
634Constructs a new parser that has namespace processing in effect. Namespace
635expanded element names and attribute names are returned as a concatenation
636of the namespace URI, <em>sep</em>, and the local part of the name. This
637means that you should pick a character for <em>sep</em> that can't be
913XML_ParserCreateNS(const XML_Char *encoding,
914 XML_Char sep);
915</pre>
916<div class="fcndef">
917Constructs a new parser that has namespace processing in effect. Namespace
918expanded element names and attribute names are returned as a concatenation
919of the namespace URI, <em>sep</em>, and the local part of the name. This
920means that you should pick a character for <em>sep</em> that can't be
638part of a legal URI.</div>
921part of a legal URI. There is a special case when <em>sep</em> is the null
922character <code>'\0'</code>: the namespace URI and the local part will be
923concatenated without any separator - this is intended to support RDF processors.
924It is a programming error to use the null separator with
925<a href= "#XML_SetReturnNSTriplet">namespace triplets</a>.</div>
639
640<pre class="fcndec" id="XML_ParserCreate_MM">
926
927<pre class="fcndec" id="XML_ParserCreate_MM">
641XML_Parser
928XML_Parser XMLCALL
642XML_ParserCreate_MM(const XML_Char *encoding,
643 const XML_Memory_Handling_Suite *ms,
644 const XML_Char *sep);
645</pre>
646<pre class="signature">
647typedef struct {
929XML_ParserCreate_MM(const XML_Char *encoding,
930 const XML_Memory_Handling_Suite *ms,
931 const XML_Char *sep);
932</pre>
933<pre class="signature">
934typedef struct {
648 void *(*malloc_fcn)(size_t size);
649 void *(*realloc_fcn)(void *ptr, size_t size);
650 void (*free_fcn)(void *ptr);
935 void *(XMLCALL *malloc_fcn)(size_t size);
936 void *(XMLCALL *realloc_fcn)(void *ptr, size_t size);
937 void (XMLCALL *free_fcn)(void *ptr);
651} XML_Memory_Handling_Suite;
652</pre>
653<div class="fcndef">
654<p>Construct a new parser using the suite of memory handling functions
655specified in <code>ms</code>. If <code>ms</code> is NULL, then use the
656standard set of memory management functions. If <code>sep</code> is
657non NULL, then namespace processing is enabled in the created parser
658and the character pointed at by sep is used as the separator between
659the namespace URI and the local part of the name.</p>
660</div>
661
662<pre class="fcndec" id="XML_ExternalEntityParserCreate">
938} XML_Memory_Handling_Suite;
939</pre>
940<div class="fcndef">
941<p>Construct a new parser using the suite of memory handling functions
942specified in <code>ms</code>. If <code>ms</code> is NULL, then use the
943standard set of memory management functions. If <code>sep</code> is
944non NULL, then namespace processing is enabled in the created parser
945and the character pointed at by sep is used as the separator between
946the namespace URI and the local part of the name.</p>
947</div>
948
949<pre class="fcndec" id="XML_ExternalEntityParserCreate">
663XML_Parser
950XML_Parser XMLCALL
664XML_ExternalEntityParserCreate(XML_Parser p,
665 const XML_Char *context,
666 const XML_Char *encoding);
667</pre>
668<div class="fcndef">
669Construct a new <code>XML_Parser</code> object for parsing an external
670general entity. Context is the context argument passed in a call to a
671ExternalEntityRefHandler. Other state information such as handlers,
672user data, namespace processing is inherited from the parser passed as
673the 1st argument. So you shouldn't need to call any of the behavior
674changing functions on this parser (unless you want it to act
675differently than the parent parser).
676</div>
677
678<pre class="fcndec" id="XML_ParserFree">
951XML_ExternalEntityParserCreate(XML_Parser p,
952 const XML_Char *context,
953 const XML_Char *encoding);
954</pre>
955<div class="fcndef">
956Construct a new <code>XML_Parser</code> object for parsing an external
957general entity. Context is the context argument passed in a call to a
958ExternalEntityRefHandler. Other state information such as handlers,
959user data, namespace processing is inherited from the parser passed as
960the 1st argument. So you shouldn't need to call any of the behavior
961changing functions on this parser (unless you want it to act
962differently than the parent parser).
963</div>
964
965<pre class="fcndec" id="XML_ParserFree">
679void
966void XMLCALL
680XML_ParserFree(XML_Parser p);
681</pre>
682<div class="fcndef">
683Free memory used by the parser. Your application is responsible for
684freeing any memory associated with <a href="#userdata">user data</a>.
685</div>
686
687<pre class="fcndec" id="XML_ParserReset">
967XML_ParserFree(XML_Parser p);
968</pre>
969<div class="fcndef">
970Free memory used by the parser. Your application is responsible for
971freeing any memory associated with <a href="#userdata">user data</a>.
972</div>
973
974<pre class="fcndec" id="XML_ParserReset">
688XML_Bool
689XML_ParserReset(XML_Parser p);
975XML_Bool XMLCALL
976XML_ParserReset(XML_Parser p,
977 const XML_Char *encoding);
690</pre>
691<div class="fcndef">
692Clean up the memory structures maintained by the parser so that it may
693be used again. After this has been called, <code>parser</code> is
978</pre>
979<div class="fcndef">
980Clean up the memory structures maintained by the parser so that it may
981be used again. After this has been called, <code>parser</code> is
694ready to start parsing a new document. This function may not be used
695on a parser created using <code><a href=
982ready to start parsing a new document. All handlers are cleared from
983the parser, except for the unknownEncodingHandler. The parser's external
984state is re-initialized except for the values of ns and ns_triplets.
985This function may not be used on a parser created using <code><a href=
696"#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a
697></code>; it will return <code>XML_FALSE</code> in that case. Returns
698<code>XML_TRUE</code> on success. Your application is responsible for
699dealing with any memory associated with <a href="#userdata">user data</a>.
700</div>
701
702<h3><a name="parsing">Parsing</a></h3>
703
704<p>To state the obvious: the three parsing functions <code><a href=
986"#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a
987></code>; it will return <code>XML_FALSE</code> in that case. Returns
988<code>XML_TRUE</code> on success. Your application is responsible for
989dealing with any memory associated with <a href="#userdata">user data</a>.
990</div>
991
992<h3><a name="parsing">Parsing</a></h3>
993
994<p>To state the obvious: the three parsing functions <code><a href=
705"#XML_Parse" >XML_Parse, 706>XML_ParseBuffer</a></code> and <code><a href= "#XML_GetBuffer"
707>>XML_GetBuffer</a></code> must not be
708called from within a handler unless they operate on a separate parser
709instance, that is, one that did not call the handler. For example, it
710is OK to call the parsing functions from within an
711<code>XML_ExternalEntityRefHandler</code>, if they apply to the parser
712created by <code><a href= "#XML_ExternalEntityParserCreate"
995"#XML_Parse" >XML_Parse</a></code>, <code><a href= "#XML_ParseBuffer">
996XML_ParseBuffer</a></code> and <code><a href= "#XML_GetBuffer">
997XML_GetBuffer</a></code> must not be called from within a handler
998unless they operate on a separate parser instance, that is, one that
999did not call the handler. For example, it is OK to call the parsing
1000functions from within an <code>XML_ExternalEntityRefHandler</code>,
1001if they apply to the parser created by
1002
713>XML_ExternalEntityParserCreate</a></code>.</p>
714
1003>XML_ExternalEntityParserCreate</a></code>.</p>
1004
1005<p>Note: the <code>len</code> argument passed to these functions
1006should be considerably less than the maximum value for an integer,
1007as it could create an integer overflow situation if the added
1008lengths of a buffer and the unprocessed portion of the previous buffer
1009exceed the maximum integer value. Input data at the end of a buffer
1010will remain unprocessed if it is part of an XML token for which the
1011end is not part of that buffer.</p>
1012
715<pre class="fcndec" id="XML_Parse">
1013<pre class="fcndec" id="XML_Parse">
716XML_Status
1014enum XML_Status XMLCALL
717XML_Parse(XML_Parser p,
718 const char *s,
719 int len,
720 int isFinal);
721</pre>
722<pre class="signature">
723enum XML_Status {
724 XML_STATUS_ERROR = 0,

--- 10 unchanged lines hidden (view full) ---

735<code>isFinal</code> parameter informs the parser that this is the last
736piece of the document. Frequently, the last piece is empty (i.e.
737<code>len</code> is zero.)
738If a parse error occurred, it returns <code>XML_STATUS_ERROR</code>.
739Otherwise it returns <code>XML_STATUS_OK</code> value.
740</div>
741
742<pre class="fcndec" id="XML_ParseBuffer">
1015XML_Parse(XML_Parser p,
1016 const char *s,
1017 int len,
1018 int isFinal);
1019</pre>
1020<pre class="signature">
1021enum XML_Status {
1022 XML_STATUS_ERROR = 0,

--- 10 unchanged lines hidden (view full) ---

1033<code>isFinal</code> parameter informs the parser that this is the last
1034piece of the document. Frequently, the last piece is empty (i.e.
1035<code>len</code> is zero.)
1036If a parse error occurred, it returns <code>XML_STATUS_ERROR</code>.
1037Otherwise it returns <code>XML_STATUS_OK</code> value.
1038</div>
1039
1040<pre class="fcndec" id="XML_ParseBuffer">
743XML_Status
1041enum XML_Status XMLCALL
744XML_ParseBuffer(XML_Parser p,
745 int len,
746 int isFinal);
747</pre>
748<div class="fcndef">
749This is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>,
750except in this case Expat provides the buffer. By obtaining the
751buffer from Expat with the <code><a href= "#XML_GetBuffer"
752>XML_GetBuffer</a></code> function, the application can avoid double
753copying of the input.
754</div>
755
756<pre class="fcndec" id="XML_GetBuffer">
1042XML_ParseBuffer(XML_Parser p,
1043 int len,
1044 int isFinal);
1045</pre>
1046<div class="fcndef">
1047This is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>,
1048except in this case Expat provides the buffer. By obtaining the
1049buffer from Expat with the <code><a href= "#XML_GetBuffer"
1050>XML_GetBuffer</a></code> function, the application can avoid double
1051copying of the input.
1052</div>
1053
1054<pre class="fcndec" id="XML_GetBuffer">
757void *
1055void * XMLCALL
758XML_GetBuffer(XML_Parser p,
759 int len);
760</pre>
761<div class="fcndef">
762Obtain a buffer of size <code>len</code> to read a piece of the document
763into. A NULL value is returned if Expat can't allocate enough memory for
764this buffer. This has to be called prior to every call to
765<code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A

--- 17 unchanged lines hidden (view full) ---

783 }
784
785 if (bytes_read == 0)
786 break;
787}
788</pre>
789</div>
790
1056XML_GetBuffer(XML_Parser p,
1057 int len);
1058</pre>
1059<div class="fcndef">
1060Obtain a buffer of size <code>len</code> to read a piece of the document
1061into. A NULL value is returned if Expat can't allocate enough memory for
1062this buffer. This has to be called prior to every call to
1063<code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A

--- 17 unchanged lines hidden (view full) ---

1081 }
1082
1083 if (bytes_read == 0)
1084 break;
1085}
1086</pre>
1087</div>
1088
1089<pre class="fcndec" id="XML_StopParser">
1090enum XML_Status XMLCALL
1091XML_StopParser(XML_Parser p,
1092 XML_Bool resumable);
1093</pre>
1094<div class="fcndef">
1095
1096<p>Stops parsing, causing <code><a href= "#XML_Parse"
1097>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
1098>XML_ParseBuffer</a></code> to return. Must be called from within a
1099call-back handler, except when aborting (when <code>resumable</code>
1100is <code>XML_FALSE</code>) an already suspended parser. Some
1101call-backs may still follow because they would otherwise get
1102lost, including
1103<ul>
1104 <li> the end element handler for empty elements when stopped in the
1105 start element handler,</li>
1106 <li> the end namespace declaration handler when stopped in the end
1107 element handler,</li>
1108 <li> the character data handler when stopped in the character data handler
1109 while making multiple call-backs on a contiguous chunk of characters,</li>
1110</ul>
1111and possibly others.</p>
1112
1113<p>This can be called from most handlers, including DTD related
1114call-backs, except when parsing an external parameter entity and
1115<code>resumable</code> is <code>XML_TRUE</code>. Returns
1116<code>XML_STATUS_OK</code> when successful,
1117<code>XML_STATUS_ERROR</code> otherwise. The possible error codes
1118are:</p>
1119<dl>
1120 <dt><code>XML_ERROR_SUSPENDED</code></dt>
1121 <dd>when suspending an already suspended parser.</dd>
1122 <dt><code>XML_ERROR_FINISHED</code></dt>
1123 <dd>when the parser has already finished.</dd>
1124 <dt><code>XML_ERROR_SUSPEND_PE</code></dt>
1125 <dd>when suspending while parsing an external PE.</dd>
1126</dl>
1127
1128<p>Since the stop/resume feature requires application support in the
1129outer parsing loop, it is an error to call this function for a parser
1130not being handled appropriately; see <a href= "#stop-resume"
1131>Temporarily Stopping Parsing</a> for more information.</p>
1132
1133<p>When <code>resumable</code> is <code>XML_TRUE</code> then parsing
1134is <em>suspended</em>, that is, <code><a href= "#XML_Parse"
1135>XML_Parse</a></code> and <code><a href= "#XML_ParseBuffer"
1136>XML_ParseBuffer</a></code> return <code>XML_STATUS_SUSPENDED</code>.
1137Otherwise, parsing is <em>aborted</em>, that is, <code><a href=
1138"#XML_Parse" >XML_Parse</a></code> and <code><a href=
1139"#XML_ParseBuffer" >XML_ParseBuffer</a></code> return
1140<code>XML_STATUS_ERROR</code> with error code
1141<code>XML_ERROR_ABORTED</code>.</p>
1142
1143<p><strong>Note:</strong>
1144This will be applied to the current parser instance only, that is, if
1145there is a parent parser then it will continue parsing when the
1146external entity reference handler returns. It is up to the
1147implementation of that handler to call <code><a href=
1148"#XML_StopParser" >XML_StopParser</a></code> on the parent parser
1149(recursively), if one wants to stop parsing altogether.</p>
1150
1151<p>When suspended, parsing can be resumed by calling <code><a href=
1152"#XML_ResumeParser" >XML_ResumeParser</a></code>.</p>
1153
1154<p>New in Expat 1.95.8.</p>
1155</div>
1156
1157<pre class="fcndec" id="XML_ResumeParser">
1158enum XML_Status XMLCALL
1159XML_ResumeParser(XML_Parser p);
1160</pre>
1161<div class="fcndef">
1162<p>Resumes parsing after it has been suspended with <code><a href=
1163"#XML_StopParser" >XML_StopParser</a></code>. Must not be called from
1164within a handler call-back. Returns same status codes as <code><a
1165href= "#XML_Parse">XML_Parse</a></code> or <code><a href=
1166"#XML_ParseBuffer" >XML_ParseBuffer</a></code>. An additional error
1167code, <code>XML_ERROR_NOT_SUSPENDED</code>, will be returned if the
1168parser was not currently suspended.</p>
1169
1170<p><strong>Note:</strong>
1171This must be called on the most deeply nested child parser instance
1172first, and on its parent parser only after the child parser has
1173finished, to be applied recursively until the document entity's parser
1174is restarted. That is, the parent parser will not resume by itself
1175and it is up to the application to call <code><a href=
1176"#XML_ResumeParser" >XML_ResumeParser</a></code> on it at the
1177appropriate moment.</p>
1178
1179<p>New in Expat 1.95.8.</p>
1180</div>
1181
1182<pre class="fcndec" id="XML_GetParsingStatus">
1183void XMLCALL
1184XML_GetParsingStatus(XML_Parser p,
1185 XML_ParsingStatus *status);
1186</pre>
1187<pre class="signature">
1188enum XML_Parsing {
1189 XML_INITIALIZED,
1190 XML_PARSING,
1191 XML_FINISHED,
1192 XML_SUSPENDED
1193};
1194
1195typedef struct {
1196 enum XML_Parsing parsing;
1197 XML_Bool finalBuffer;
1198} XML_ParsingStatus;
1199</pre>
1200<div class="fcndef">
1201<p>Returns status of parser with respect to being initialized,
1202parsing, finished, or suspended, and whether the final buffer is being
1203processed. The <code>status</code> parameter <em>must not</em> be
1204NULL.</p>
1205
1206<p>New in Expat 1.95.8.</p>
1207</div>
1208
1209
791<h3><a name="setting">Handler Setting</a></h3>
792
793<p>Although handlers are typically set prior to parsing and left alone, an
794application may choose to set or change the handler for a parsing event
795while the parse is in progress. For instance, your application may choose
796to ignore all text not descended from a <code>para</code> element. One
797way it could do this is to set the character handler when a para start tag
798is seen, and unset it for the corresponding end tag.</p>
799
800<p>A handler may be <em>unset</em> by providing a NULL pointer to the
801appropriate handler setter. None of the handler setting functions have
802a return value.</p>
803
804<p>Your handlers will be receiving strings in arrays of type
1210<h3><a name="setting">Handler Setting</a></h3>
1211
1212<p>Although handlers are typically set prior to parsing and left alone, an
1213application may choose to set or change the handler for a parsing event
1214while the parse is in progress. For instance, your application may choose
1215to ignore all text not descended from a <code>para</code> element. One
1216way it could do this is to set the character handler when a para start tag
1217is seen, and unset it for the corresponding end tag.</p>
1218
1219<p>A handler may be <em>unset</em> by providing a NULL pointer to the
1220appropriate handler setter. None of the handler setting functions have
1221a return value.</p>
1222
1223<p>Your handlers will be receiving strings in arrays of type
805<code>XML_Char</code>. This type is defined in expat.h as <code>char
806*</code> and contains bytes encoding UTF-8. Note that you'll receive
807them in this form independent of the original encoding of the
808document.</p>
1224<code>XML_Char</code>. This type is conditionally defined in expat.h as
1225either <code>char</code>, <code>wchar_t</code> or <code>unsigned short</code>.
1226The former implies UTF-8 encoding, the latter two imply UTF-16 encoding.
1227Note that you'll receive them in this form independent of the original
1228encoding of the document.</p>
809
810<div class="handler">
811<pre class="setter" id="XML_SetStartElementHandler">
1229
1230<div class="handler">
1231<pre class="setter" id="XML_SetStartElementHandler">
1232void XMLCALL
812XML_SetStartElementHandler(XML_Parser p,
813 XML_StartElementHandler start);
814</pre>
815<pre class="signature">
816typedef void
1233XML_SetStartElementHandler(XML_Parser p,
1234 XML_StartElementHandler start);
1235</pre>
1236<pre class="signature">
1237typedef void
817(*XML_StartElementHandler)(void *userData,
818 const XML_Char *name,
819 const XML_Char **atts);
1238(XMLCALL *XML_StartElementHandler)(void *userData,
1239 const XML_Char *name,
1240 const XML_Char **atts);
820</pre>
821<p>Set handler for start (and empty) tags. Attributes are passed to the start
822handler as a pointer to a vector of char pointers. Each attribute seen in
823a start (or empty) tag occupies 2 consecutive places in this vector: the
824attribute name followed by the attribute value. These pairs are terminated
825by a null pointer.</p>
826<p>Note that an empty tag generates a call to both start and end handlers
827(in that order).</p>
828</div>
829
830<div class="handler">
831<pre class="setter" id="XML_SetEndElementHandler">
1241</pre>
1242<p>Set handler for start (and empty) tags. Attributes are passed to the start
1243handler as a pointer to a vector of char pointers. Each attribute seen in
1244a start (or empty) tag occupies 2 consecutive places in this vector: the
1245attribute name followed by the attribute value. These pairs are terminated
1246by a null pointer.</p>
1247<p>Note that an empty tag generates a call to both start and end handlers
1248(in that order).</p>
1249</div>
1250
1251<div class="handler">
1252<pre class="setter" id="XML_SetEndElementHandler">
1253void XMLCALL
832XML_SetEndElementHandler(XML_Parser p,
833 XML_EndElementHandler);
834</pre>
835<pre class="signature">
836typedef void
1254XML_SetEndElementHandler(XML_Parser p,
1255 XML_EndElementHandler);
1256</pre>
1257<pre class="signature">
1258typedef void
837(*XML_EndElementHandler)(void *userData,
838 const XML_Char *name);
1259(XMLCALL *XML_EndElementHandler)(void *userData,
1260 const XML_Char *name);
839</pre>
840<p>Set handler for end (and empty) tags. As noted above, an empty tag
841generates a call to both start and end handlers.</p>
842</div>
843
844<div class="handler">
845<pre class="setter" id="XML_SetElementHandler">
1261</pre>
1262<p>Set handler for end (and empty) tags. As noted above, an empty tag
1263generates a call to both start and end handlers.</p>
1264</div>
1265
1266<div class="handler">
1267<pre class="setter" id="XML_SetElementHandler">
1268void XMLCALL
846XML_SetElementHandler(XML_Parser p,
847 XML_StartElementHandler start,
848 XML_EndElementHandler end);
849</pre>
850<p>Set handlers for start and end tags with one call.</p>
851</div>
852
853<div class="handler">
854<pre class="setter" id="XML_SetCharacterDataHandler">
1269XML_SetElementHandler(XML_Parser p,
1270 XML_StartElementHandler start,
1271 XML_EndElementHandler end);
1272</pre>
1273<p>Set handlers for start and end tags with one call.</p>
1274</div>
1275
1276<div class="handler">
1277<pre class="setter" id="XML_SetCharacterDataHandler">
1278void XMLCALL
855XML_SetCharacterDataHandler(XML_Parser p,
856 XML_CharacterDataHandler charhndl)
857</pre>
858<pre class="signature">
859typedef void
1279XML_SetCharacterDataHandler(XML_Parser p,
1280 XML_CharacterDataHandler charhndl)
1281</pre>
1282<pre class="signature">
1283typedef void
860(*XML_CharacterDataHandler)(void *userData,
861 const XML_Char *s,
862 int len);
1284(XMLCALL *XML_CharacterDataHandler)(void *userData,
1285 const XML_Char *s,
1286 int len);
863</pre>
864<p>Set a text handler. The string your handler receives
865is <em>NOT nul-terminated</em>. You have to use the length argument
866to deal with the end of the string. A single block of contiguous text
867free of markup may still result in a sequence of calls to this handler.
868In other words, if you're searching for a pattern in the text, it may
1287</pre>
1288<p>Set a text handler. The string your handler receives
1289is <em>NOT nul-terminated</em>. You have to use the length argument
1290to deal with the end of the string. A single block of contiguous text
1291free of markup may still result in a sequence of calls to this handler.
1292In other words, if you're searching for a pattern in the text, it may
869be split across calls to this handler.</p>
1293be split across calls to this handler. Note: Setting this handler to NULL
1294may <em>NOT immediately</em> terminate call-backs if the parser is currently
1295processing such a single block of contiguous markup-free text, as the parser
1296will continue calling back until the end of the block is reached.</p>
870</div>
871
872<div class="handler">
873<pre class="setter" id="XML_SetProcessingInstructionHandler">
1297</div>
1298
1299<div class="handler">
1300<pre class="setter" id="XML_SetProcessingInstructionHandler">
1301void XMLCALL
874XML_SetProcessingInstructionHandler(XML_Parser p,
875 XML_ProcessingInstructionHandler proc)
876</pre>
877<pre class="signature">
878typedef void
1302XML_SetProcessingInstructionHandler(XML_Parser p,
1303 XML_ProcessingInstructionHandler proc)
1304</pre>
1305<pre class="signature">
1306typedef void
879(*XML_ProcessingInstructionHandler)(void *userData,
880 const XML_Char *target,
881 const XML_Char *data);
1307(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,
1308 const XML_Char *target,
1309 const XML_Char *data);
882
883</pre>
884<p>Set a handler for processing instructions. The target is the first word
885in the processing instruction. The data is the rest of the characters in
886it after skipping all whitespace after the initial word.</p>
887</div>
888
889<div class="handler">
890<pre class="setter" id="XML_SetCommentHandler">
1310
1311</pre>
1312<p>Set a handler for processing instructions. The target is the first word
1313in the processing instruction. The data is the rest of the characters in
1314it after skipping all whitespace after the initial word.</p>
1315</div>
1316
1317<div class="handler">
1318<pre class="setter" id="XML_SetCommentHandler">
1319void XMLCALL
891XML_SetCommentHandler(XML_Parser p,
892 XML_CommentHandler cmnt)
893</pre>
894<pre class="signature">
895typedef void
1320XML_SetCommentHandler(XML_Parser p,
1321 XML_CommentHandler cmnt)
1322</pre>
1323<pre class="signature">
1324typedef void
896(*XML_CommentHandler)(void *userData,
897 const XML_Char *data);
1325(XMLCALL *XML_CommentHandler)(void *userData,
1326 const XML_Char *data);
898</pre>
899<p>Set a handler for comments. The data is all text inside the comment
900delimiters.</p>
901</div>
902
903<div class="handler">
904<pre class="setter" id="XML_SetStartCdataSectionHandler">
1327</pre>
1328<p>Set a handler for comments. The data is all text inside the comment
1329delimiters.</p>
1330</div>
1331
1332<div class="handler">
1333<pre class="setter" id="XML_SetStartCdataSectionHandler">
1334void XMLCALL
905XML_SetStartCdataSectionHandler(XML_Parser p,
906 XML_StartCdataSectionHandler start);
907</pre>
908<pre class="signature">
909typedef void
1335XML_SetStartCdataSectionHandler(XML_Parser p,
1336 XML_StartCdataSectionHandler start);
1337</pre>
1338<pre class="signature">
1339typedef void
910(*XML_StartCdataSectionHandler)(void *userData);
1340(XMLCALL *XML_StartCdataSectionHandler)(void *userData);
911</pre>
912<p>Set a handler that gets called at the beginning of a CDATA section.</p>
913</div>
914
915<div class="handler">
916<pre class="setter" id="XML_SetEndCdataSectionHandler">
1341</pre>
1342<p>Set a handler that gets called at the beginning of a CDATA section.</p>
1343</div>
1344
1345<div class="handler">
1346<pre class="setter" id="XML_SetEndCdataSectionHandler">
1347void XMLCALL
917XML_SetEndCdataSectionHandler(XML_Parser p,
918 XML_EndCdataSectionHandler end);
919</pre>
920<pre class="signature">
921typedef void
1348XML_SetEndCdataSectionHandler(XML_Parser p,
1349 XML_EndCdataSectionHandler end);
1350</pre>
1351<pre class="signature">
1352typedef void
922(*XML_EndCdataSectionHandler)(void *userData);
1353(XMLCALL *XML_EndCdataSectionHandler)(void *userData);
923</pre>
924<p>Set a handler that gets called at the end of a CDATA section.</p>
925</div>
926
927<div class="handler">
928<pre class="setter" id="XML_SetCdataSectionHandler">
1354</pre>
1355<p>Set a handler that gets called at the end of a CDATA section.</p>
1356</div>
1357
1358<div class="handler">
1359<pre class="setter" id="XML_SetCdataSectionHandler">
1360void XMLCALL
929XML_SetCdataSectionHandler(XML_Parser p,
930 XML_StartCdataSectionHandler start,
931 XML_EndCdataSectionHandler end)
932</pre>
933<p>Sets both CDATA section handlers with one call.</p>
934</div>
935
936<div class="handler">
937<pre class="setter" id="XML_SetDefaultHandler">
1361XML_SetCdataSectionHandler(XML_Parser p,
1362 XML_StartCdataSectionHandler start,
1363 XML_EndCdataSectionHandler end)
1364</pre>
1365<p>Sets both CDATA section handlers with one call.</p>
1366</div>
1367
1368<div class="handler">
1369<pre class="setter" id="XML_SetDefaultHandler">
1370void XMLCALL
938XML_SetDefaultHandler(XML_Parser p,
939 XML_DefaultHandler hndl)
940</pre>
941<pre class="signature">
942typedef void
1371XML_SetDefaultHandler(XML_Parser p,
1372 XML_DefaultHandler hndl)
1373</pre>
1374<pre class="signature">
1375typedef void
943(*XML_DefaultHandler)(void *userData,
944 const XML_Char *s,
945 int len);
1376(XMLCALL *XML_DefaultHandler)(void *userData,
1377 const XML_Char *s,
1378 int len);
946</pre>
947
948<p>Sets a handler for any characters in the document which wouldn't
949otherwise be handled. This includes both data for which no handlers
950can be set (like some kinds of DTD declarations) and data which could
951be reported but which currently has no handler set. The characters
952are passed exactly as they were present in the XML document except
953that they will be encoded in UTF-8 or UTF-16. Line boundaries are not

--- 6 unchanged lines hidden (view full) ---

960passed to the default handler.</p>
961
962<p>See also <code><a
963href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
964</div>
965
966<div class="handler">
967<pre class="setter" id="XML_SetDefaultHandlerExpand">
1379</pre>
1380
1381<p>Sets a handler for any characters in the document which wouldn't
1382otherwise be handled. This includes both data for which no handlers
1383can be set (like some kinds of DTD declarations) and data which could
1384be reported but which currently has no handler set. The characters
1385are passed exactly as they were present in the XML document except
1386that they will be encoded in UTF-8 or UTF-16. Line boundaries are not

--- 6 unchanged lines hidden (view full) ---

1393passed to the default handler.</p>
1394
1395<p>See also <code><a
1396href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
1397</div>
1398
1399<div class="handler">
1400<pre class="setter" id="XML_SetDefaultHandlerExpand">
1401void XMLCALL
968XML_SetDefaultHandlerExpand(XML_Parser p,
969 XML_DefaultHandler hndl)
970</pre>
971<pre class="signature">
972typedef void
1402XML_SetDefaultHandlerExpand(XML_Parser p,
1403 XML_DefaultHandler hndl)
1404</pre>
1405<pre class="signature">
1406typedef void
973(*XML_DefaultHandler)(void *userData,
974 const XML_Char *s,
975 int len);
1407(XMLCALL *XML_DefaultHandler)(void *userData,
1408 const XML_Char *s,
1409 int len);
976</pre>
977<p>This sets a default handler, but doesn't inhibit the expansion of
978internal entity references. The entity reference will not be passed
979to the default handler.</p>
980
981<p>See also <code><a
982href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
983</div>
984
985<div class="handler">
986<pre class="setter" id="XML_SetExternalEntityRefHandler">
1410</pre>
1411<p>This sets a default handler, but doesn't inhibit the expansion of
1412internal entity references. The entity reference will not be passed
1413to the default handler.</p>
1414
1415<p>See also <code><a
1416href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
1417</div>
1418
1419<div class="handler">
1420<pre class="setter" id="XML_SetExternalEntityRefHandler">
1421void XMLCALL
987XML_SetExternalEntityRefHandler(XML_Parser p,
988 XML_ExternalEntityRefHandler hndl)
989</pre>
990<pre class="signature">
991typedef int
1422XML_SetExternalEntityRefHandler(XML_Parser p,
1423 XML_ExternalEntityRefHandler hndl)
1424</pre>
1425<pre class="signature">
1426typedef int
992(*XML_ExternalEntityRefHandler)(XML_Parser p,
993 const XML_Char *context,
994 const XML_Char *base,
995 const XML_Char *systemId,
996 const XML_Char *publicId);
1427(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser p,
1428 const XML_Char *context,
1429 const XML_Char *base,
1430 const XML_Char *systemId,
1431 const XML_Char *publicId);
997</pre>
998<p>Set an external entity reference handler. This handler is also
999called for processing an external DTD subset if parameter entity parsing
1000is in effect. (See <a href="#XML_SetParamEntityParsing">
1001<code>XML_SetParamEntityParsing</code></a>.)</p>
1002
1432</pre>
1433<p>Set an external entity reference handler. This handler is also
1434called for processing an external DTD subset if parameter entity parsing
1435is in effect. (See <a href="#XML_SetParamEntityParsing">
1436<code>XML_SetParamEntityParsing</code></a>.)</p>
1437
1438<p>The <code>context</code> parameter specifies the parsing context in
1439the format expected by the <code>context</code> argument to <code><a
1440href="#XML_ExternalEntityParserCreate"
1441>XML_ExternalEntityParserCreate</a></code>. <code>code</code> is
1442valid only until the handler returns, so if the referenced entity is
1443to be parsed later, it must be copied. <code>context</code> is NULL
1444only when the entity is a parameter entity, which is how one can
1445differentiate between general and parameter entities.</p>
1003
1446
1004<p>The base parameter is the base to use for relative system identifiers.
1005It is set by <a href="#XML_SetBase">XML_SetBase</a> and may be null. The
1006public id parameter is the public id given in the entity declaration and
1007may be null. The system id is the system identifier specified in the entity
1008declaration and is never null.</p>
1447<p>The <code>base</code> parameter is the base to use for relative
1448system identifiers. It is set by <code><a
1449href="#XML_SetBase">XML_SetBase</a></code> and may be NULL. The
1450<code>publicId</code> parameter is the public id given in the entity
1451declaration and may be NULL. <code>systemId</code> is the system
1452identifier specified in the entity declaration and is never NULL.</p>
1009
1453
1010<p>There are a couple of ways in which this handler differs from others.
1011First, this handler returns an integer. A non-zero value should be returned
1012for successful handling of the external entity reference. Returning a zero
1013indicates failure, and causes the calling parser to return
1014an <code>XML_ERROR_EXTERNAL_ENTITY_HANDLING</code> error.</p>
1454

There are a couple of ways in which this handler differs from
1455others. First, this handler returns a status indicator (an
1456integer). <code>XML_STATUS_OK</code> should be returned for successful
1457handling of the external entity reference. Returning
1458<code>XML_STATUS_ERROR</code> indicates failure, and causes the
1459calling parser to return an
1460<code>XML_ERROR_EXTERNAL_ENTITY_HANDLING</code> error.</p>

1015
1461
1016<p>Second, instead of having userData as its first argument, it receives the
1017parser that encountered the entity reference. This, along with the context
1018parameter, may be used as arguments to a call to
1019<a href="#XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</a>.
1020Using the returned parser, the body of the external entity can be recursively
1021parsed.


1462<p>Second, instead of having the user data as its first argument, it
1463receives the parser that encountered the entity reference. This, along
1464with the context parameter, may be used as arguments to a call to
1465<code><a href= "#XML_ExternalEntityParserCreate"
1466>XML_ExternalEntityParserCreate</a></code>. Using the returned
1467parser, the body of the external entity can be recursively parsed.</p>
1022
1023<p>Since this handler may be called recursively, it should not be saving
1024information into global or static variables.</p>
1025</div>
1026
1468
1469<p>Since this handler may be called recursively, it should not be saving
1470information into global or static variables.</p>
1471</div>
1472
1473<pre class="fcndec" id="XML_SetExternalEntityRefHandlerArg">
1474void XMLCALL
1475XML_SetExternalEntityRefHandlerArg(XML_Parser p,
1476 void *arg)
1477</pre>
1478<div class="fcndef">
1479<p>Set the argument passed to the ExternalEntityRefHandler. If
1480<code>arg</code> is not NULL, it is the new value passed to the
1481handler set using <code><a href="#XML_SetExternalEntityRefHandler"
1482>XML_SetExternalEntityRefHandler</a></code>; if <code>arg</code> is
1483NULL, the argument passed to the handler function will be the parser
1484object itself.</p>
1485
1486<p><strong>Note:</strong>
1487The type of <code>arg</code> and the type of the first argument to the
1488ExternalEntityRefHandler do not match. This function takes a
1489<code>void *</code> to be passed to the handler, while the handler
1490accepts an <code>XML_Parser</code>. This is a historical accident,
1491but will not be corrected before Expat 2.0 (at the earliest) to avoid
1492causing compiler warnings for code that's known to work with this
1493API. It is the responsibility of the application code to know the
1494actual type of the argument passed to the handler and to manage it
1495properly.</p>
1496</div>
1497
1027<div class="handler">
1028<pre class="setter" id="XML_SetSkippedEntityHandler">
1498<div class="handler">
1499<pre class="setter" id="XML_SetSkippedEntityHandler">
1500void XMLCALL
1029XML_SetSkippedEntityHandler(XML_Parser p,
1030 XML_SkippedEntityHandler handler)
1031</pre>
1032<pre class="signature">
1033typedef void
1501XML_SetSkippedEntityHandler(XML_Parser p,
1502 XML_SkippedEntityHandler handler)
1503</pre>
1504<pre class="signature">
1505typedef void
1034(*XML_SkippedEntityHandler)(void *userData,
1035 const XML_Char *entityName,
1036 int is_parameter_entity);
1506(XMLCALL *XML_SkippedEntityHandler)(void *userData,
1507 const XML_Char *entityName,
1508 int is_parameter_entity);
1037</pre>
1038<p>Set a skipped entity handler. This is called in two situations:</p>
1039<ol>
1040 <li>An entity reference is encountered for which no declaration
1041 has been read <em>and</em> this is not an error.</li>
1042 <li>An internal entity reference is read, but not expanded, because
1043 <a href="#XML_SetDefaultHandler"><code>XML_SetDefaultHandler</code></a>
1044 has been called.</li>
1045</ol>
1046<p>The <code>is_parameter_entity</code> argument will be non-zero for
1047a parameter entity and zero for a general entity.</p> <p>Note: skipped
1048parameter entities in declarations and skipped general entities in
1049attribute values cannot be reported, because the event would be out of
1050sync with the reporting of the declarations or attribute values</p>
1051</div>
1052
1053<div class="handler">
1054<pre class="setter" id="XML_SetUnknownEncodingHandler">
1509</pre>
1510<p>Set a skipped entity handler. This is called in two situations:</p>
1511<ol>
1512 <li>An entity reference is encountered for which no declaration
1513 has been read <em>and</em> this is not an error.</li>
1514 <li>An internal entity reference is read, but not expanded, because
1515 <a href="#XML_SetDefaultHandler"><code>XML_SetDefaultHandler</code></a>
1516 has been called.</li>
1517</ol>
1518<p>The <code>is_parameter_entity</code> argument will be non-zero for
1519a parameter entity and zero for a general entity.</p> <p>Note: skipped
1520parameter entities in declarations and skipped general entities in
1521attribute values cannot be reported, because the event would be out of
1522sync with the reporting of the declarations or attribute values</p>
1523</div>
1524
1525<div class="handler">
1526<pre class="setter" id="XML_SetUnknownEncodingHandler">
1527void XMLCALL
1055XML_SetUnknownEncodingHandler(XML_Parser p,
1056 XML_UnknownEncodingHandler enchandler,
1057 void *encodingHandlerData)
1058</pre>
1059<pre class="signature">
1060typedef int
1528XML_SetUnknownEncodingHandler(XML_Parser p,
1529 XML_UnknownEncodingHandler enchandler,
1530 void *encodingHandlerData)
1531</pre>
1532<pre class="signature">
1533typedef int
1061(*XML_UnknownEncodingHandler)(void *encodingHandlerData,
1062 const XML_Char *name,
1063 XML_Encoding *info);
1534(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
1535 const XML_Char *name,
1536 XML_Encoding *info);
1064
1065typedef struct {
1066 int map[256];
1067 void *data;
1537
1538typedef struct {
1539 int map[256];
1540 void *data;
1068 int (*convert)(void *data, const char *s);
1069 void (*release)(void *data);
1541 int (XMLCALL *convert)(void *data, const char *s);
1542 void (XMLCALL *release)(void *data);
1070} XML_Encoding;
1071</pre>
1543} XML_Encoding;
1544</pre>
1072

Set a handler to deal with encodings other than the
1073<a href="#builtin_encodings">built in set</a>. This should be done before

1545<p>Set a handler to deal with encodings other than the <a
1546href="#builtin_encodings">built in set</a>. This should be done before
1074<code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href=
1075"#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the
1547<code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href=
1548"#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the
1076given parser.


1077<p>If the handler knows how to deal with an encoding with the given
1078name, it should fill in the <code>info</code> data structure and return
10791. Otherwise it should return 0. The handler will be called at most
1080once per parsed (external) entity. The optional application data
1081pointer <code>encodingHandlerData</code> will be passed back to the
1082handler.


1549given parser.</p> <p>If the handler knows how to deal with an encoding
1550with the given name, it should fill in the <code>info</code> data
1551structure and return <code>XML_STATUS_OK</code>. Otherwise it
1552should return <code>XML_STATUS_ERROR</code>. The handler will be called
1553at most once per parsed (external) entity. The optional application
1554data pointer <code>encodingHandlerData</code> will be passed back to
1555the handler.</p>
1083
1084<p>The map array contains information for every possible possible leading
1085byte in a byte sequence. If the corresponding value is &gt;= 0, then it's
1086a single byte sequence and the byte encodes that Unicode value. If the
1087value is -1, then that byte is invalid as the initial byte in a sequence.
1088If the value is -n, where n is an integer &gt; 1, then n is the number of
1089bytes in the sequence and the actual conversion is accomplished by a
1090call to the function pointed at by convert. This function may return -1

--- 4 unchanged lines hidden (view full) ---

1095bytes to be converted.</p>
1096
1097<p>The function pointed at by <code>release</code> is called by the
1098parser when it is finished with the encoding. It may be NULL.</p>
1099</div>
1100
1101<div class="handler">
1102<pre class="setter" id="XML_SetStartNamespaceDeclHandler">
1556
1557<p>The map array contains information for every possible possible leading
1558byte in a byte sequence. If the corresponding value is &gt;= 0, then it's
1559a single byte sequence and the byte encodes that Unicode value. If the
1560value is -1, then that byte is invalid as the initial byte in a sequence.
1561If the value is -n, where n is an integer &gt; 1, then n is the number of
1562bytes in the sequence and the actual conversion is accomplished by a
1563call to the function pointed at by convert. This function may return -1

--- 4 unchanged lines hidden (view full) ---

1568bytes to be converted.</p>
1569
1570<p>The function pointed at by <code>release</code> is called by the
1571parser when it is finished with the encoding. It may be NULL.</p>
1572</div>
1573
1574<div class="handler">
1575<pre class="setter" id="XML_SetStartNamespaceDeclHandler">
1576void XMLCALL
1103XML_SetStartNamespaceDeclHandler(XML_Parser p,
1104 XML_StartNamespaceDeclHandler start);
1105</pre>
1106<pre class="signature">
1107typedef void
1577XML_SetStartNamespaceDeclHandler(XML_Parser p,
1578 XML_StartNamespaceDeclHandler start);
1579</pre>
1580<pre class="signature">
1581typedef void
1108(*XML_StartNamespaceDeclHandler)(void *userData,
1109 const XML_Char *prefix,
1110 const XML_Char *uri);
1582(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,
1583 const XML_Char *prefix,
1584 const XML_Char *uri);
1111</pre>
1112<p>Set a handler to be called when a namespace is declared. Namespace
1113declarations occur inside start tags. But the namespace declaration start
1114handler is called before the start tag handler for each namespace declared
1115in that start tag.</p>
1116</div>
1117
1118<div class="handler">
1119<pre class="setter" id="XML_SetEndNamespaceDeclHandler">
1585</pre>
1586<p>Set a handler to be called when a namespace is declared. Namespace
1587declarations occur inside start tags. But the namespace declaration start
1588handler is called before the start tag handler for each namespace declared
1589in that start tag.</p>
1590</div>
1591
1592<div class="handler">
1593<pre class="setter" id="XML_SetEndNamespaceDeclHandler">
1594void XMLCALL
1120XML_SetEndNamespaceDeclHandler(XML_Parser p,
1121 XML_EndNamespaceDeclHandler end);
1122</pre>
1123<pre class="signature">
1124typedef void
1595XML_SetEndNamespaceDeclHandler(XML_Parser p,
1596 XML_EndNamespaceDeclHandler end);
1597</pre>
1598<pre class="signature">
1599typedef void
1125(*XML_EndNamespaceDeclHandler)(void *userData,
1126 const XML_Char *prefix);
1600(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,
1601 const XML_Char *prefix);
1127</pre>
1128<p>Set a handler to be called when leaving the scope of a namespace
1129declaration. This will be called, for each namespace declaration,
1130after the handler for the end tag of the element in which the
1131namespace was declared.</p>
1132</div>
1133
1134<div class="handler">
1135<pre class="setter" id="XML_SetNamespaceDeclHandler">
1602</pre>
1603<p>Set a handler to be called when leaving the scope of a namespace
1604declaration. This will be called, for each namespace declaration,
1605after the handler for the end tag of the element in which the
1606namespace was declared.</p>
1607</div>
1608
1609<div class="handler">
1610<pre class="setter" id="XML_SetNamespaceDeclHandler">
1611void XMLCALL
1136XML_SetNamespaceDeclHandler(XML_Parser p,
1137 XML_StartNamespaceDeclHandler start,
1138 XML_EndNamespaceDeclHandler end)
1139</pre>
1612XML_SetNamespaceDeclHandler(XML_Parser p,
1613 XML_StartNamespaceDeclHandler start,
1614 XML_EndNamespaceDeclHandler end)
1615</pre>
1140

Sets both namespace declaration handlers with a single call


1616<p>Sets both namespace declaration handlers with a single call.</p>
1141</div>
1142
1143<div class="handler">
1144<pre class="setter" id="XML_SetXmlDeclHandler">
1617</div>
1618
1619<div class="handler">
1620<pre class="setter" id="XML_SetXmlDeclHandler">
1621void XMLCALL
1145XML_SetXmlDeclHandler(XML_Parser p,
1146 XML_XmlDeclHandler xmldecl);
1147</pre>
1148<pre class="signature">
1149typedef void
1622XML_SetXmlDeclHandler(XML_Parser p,
1623 XML_XmlDeclHandler xmldecl);
1624</pre>
1625<pre class="signature">
1626typedef void
1150(*XML_XmlDeclHandler) (void *userData,
1151 const XML_Char *version,
1152 const XML_Char *encoding,
1153 int standalone);
1627(XMLCALL *XML_XmlDeclHandler)(void *userData,
1628 const XML_Char *version,
1629 const XML_Char *encoding,
1630 int standalone);
1154</pre>
1155<p>Sets a handler that is called for XML declarations and also for
1156text declarations discovered in external entities. The way to
1157distinguish is that the <code>version</code> parameter will be NULL
1158for text declarations. The <code>encoding</code> parameter may be NULL
1159for an XML declaration. The <code>standalone</code> argument will
1160contain -1, 0, or 1 indicating respectively that there was no
1161standalone parameter in the declaration, that it was given as no, or
1162that it was given as yes.</p>
1163</div>
1164
1165<div class="handler">
1166<pre class="setter" id="XML_SetStartDoctypeDeclHandler">
1631</pre>
1632<p>Sets a handler that is called for XML declarations and also for
1633text declarations discovered in external entities. The way to
1634distinguish is that the <code>version</code> parameter will be NULL
1635for text declarations. The <code>encoding</code> parameter may be NULL
1636for an XML declaration. The <code>standalone</code> argument will
1637contain -1, 0, or 1 indicating respectively that there was no
1638standalone parameter in the declaration, that it was given as no, or
1639that it was given as yes.</p>
1640</div>
1641
1642<div class="handler">
1643<pre class="setter" id="XML_SetStartDoctypeDeclHandler">
1644void XMLCALL
1167XML_SetStartDoctypeDeclHandler(XML_Parser p,
1168 XML_StartDoctypeDeclHandler start);
1169</pre>
1170<pre class="signature">
1171typedef void
1645XML_SetStartDoctypeDeclHandler(XML_Parser p,
1646 XML_StartDoctypeDeclHandler start);
1647</pre>
1648<pre class="signature">
1649typedef void
1172(*XML_StartDoctypeDeclHandler)(void *userData,
1173 const XML_Char *doctypeName,
1174 const XML_Char *sysid,
1175 const XML_Char *pubid,
1176 int has_internal_subset);
1650(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,
1651 const XML_Char *doctypeName,
1652 const XML_Char *sysid,
1653 const XML_Char *pubid,
1654 int has_internal_subset);
1177</pre>
1178<p>Set a handler that is called at the start of a DOCTYPE declaration,
1179before any external or internal subset is parsed. Both <code>sysid</code>
1180and <code>pubid</code> may be NULL. The <code>has_internal_subset</code>
1181will be non-zero if the DOCTYPE declaration has an internal subset.</p>
1182</div>
1183
1184<div class="handler">
1185<pre class="setter" id="XML_SetEndDoctypeDeclHandler">
1655</pre>
1656<p>Set a handler that is called at the start of a DOCTYPE declaration,
1657before any external or internal subset is parsed. Both <code>sysid</code>
1658and <code>pubid</code> may be NULL. The <code>has_internal_subset</code>
1659will be non-zero if the DOCTYPE declaration has an internal subset.</p>
1660</div>
1661
1662<div class="handler">
1663<pre class="setter" id="XML_SetEndDoctypeDeclHandler">
1664void XMLCALL
1186XML_SetEndDoctypeDeclHandler(XML_Parser p,
1187 XML_EndDoctypeDeclHandler end);
1188</pre>
1189<pre class="signature">
1190typedef void
1665XML_SetEndDoctypeDeclHandler(XML_Parser p,
1666 XML_EndDoctypeDeclHandler end);
1667</pre>
1668<pre class="signature">
1669typedef void
1191(*XML_EndDoctypeDeclHandler)(void *userData);
1670(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
1192</pre>
1193<p>Set a handler that is called at the end of a DOCTYPE declaration,
1194after parsing any external subset.</p>
1195</div>
1196
1197<div class="handler">
1198<pre class="setter" id="XML_SetDoctypeDeclHandler">
1671</pre>
1672<p>Set a handler that is called at the end of a DOCTYPE declaration,
1673after parsing any external subset.</p>
1674</div>
1675
1676<div class="handler">
1677<pre class="setter" id="XML_SetDoctypeDeclHandler">
1678void XMLCALL
1199XML_SetDoctypeDeclHandler(XML_Parser p,
1200 XML_StartDoctypeDeclHandler start,
1201 XML_EndDoctypeDeclHandler end);
1202</pre>
1203<p>Set both doctype handlers with one call.</p>
1204</div>
1205
1206<div class="handler">
1207<pre class="setter" id="XML_SetElementDeclHandler">
1679XML_SetDoctypeDeclHandler(XML_Parser p,
1680 XML_StartDoctypeDeclHandler start,
1681 XML_EndDoctypeDeclHandler end);
1682</pre>
1683<p>Set both doctype handlers with one call.</p>
1684</div>
1685
1686<div class="handler">
1687<pre class="setter" id="XML_SetElementDeclHandler">
1688void XMLCALL
1208XML_SetElementDeclHandler(XML_Parser p,
1209 XML_ElementDeclHandler eldecl);
1210</pre>
1211<pre class="signature">
1212typedef void
1689XML_SetElementDeclHandler(XML_Parser p,
1690 XML_ElementDeclHandler eldecl);
1691</pre>
1692<pre class="signature">
1693typedef void
1213(*XML_ElementDeclHandler)(void *userData,
1214 const XML_Char *name,
1215 XML_Content *model);
1694(XMLCALL *XML_ElementDeclHandler)(void *userData,
1695 const XML_Char *name,
1696 XML_Content *model);
1216</pre>
1217<pre class="signature">
1218enum XML_Content_Type {
1219 XML_CTYPE_EMPTY = 1,
1220 XML_CTYPE_ANY,
1221 XML_CTYPE_MIXED,
1222 XML_CTYPE_NAME,
1223 XML_CTYPE_CHOICE,

--- 15 unchanged lines hidden (view full) ---

1239 const XML_Char * name;
1240 unsigned int numchildren;
1241 XML_Content * children;
1242};
1243</pre>
1244<p>Sets a handler for element declarations in a DTD. The handler gets
1245called with the name of the element in the declaration and a pointer
1246to a structure that contains the element model. It is the
1697</pre>
1698<pre class="signature">
1699enum XML_Content_Type {
1700 XML_CTYPE_EMPTY = 1,
1701 XML_CTYPE_ANY,
1702 XML_CTYPE_MIXED,
1703 XML_CTYPE_NAME,
1704 XML_CTYPE_CHOICE,

--- 15 unchanged lines hidden (view full) ---

1720 const XML_Char * name;
1721 unsigned int numchildren;
1722 XML_Content * children;
1723};
1724</pre>
1725<p>Sets a handler for element declarations in a DTD. The handler gets
1726called with the name of the element in the declaration and a pointer
1727to a structure that contains the element model. It is the
1247application's responsibility to free this data structure.</p>
1728application's responsibility to free this data structure using
1729<code><a href="#XML_FreeContentModel"
1730>XML_FreeContentModel</a></code>.</p>
1248
1249<p>The <code>model</code> argument is the root of a tree of
1250<code>XML_Content</code> nodes. If <code>type</code> equals
1251<code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then
1252<code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other
1253fields will be zero or NULL. If <code>type</code> is
1254<code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be
1255<code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and

--- 13 unchanged lines hidden (view full) ---

1269<p>Types <code>XML_CTYPE_CHOICE</code> and <code>XML_CTYPE_SEQ</code>
1270indicate a choice or sequence respectively. The
1271<code>numchildren</code> field indicates how many nodes in the choice
1272or sequence and <code>children</code> points to the nodes.</p>
1273</div>
1274
1275<div class="handler">
1276<pre class="setter" id="XML_SetAttlistDeclHandler">
1731
1732<p>The <code>model</code> argument is the root of a tree of
1733<code>XML_Content</code> nodes. If <code>type</code> equals
1734<code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then
1735<code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other
1736fields will be zero or NULL. If <code>type</code> is
1737<code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be
1738<code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and

--- 13 unchanged lines hidden (view full) ---

1752<p>Types <code>XML_CTYPE_CHOICE</code> and <code>XML_CTYPE_SEQ</code>
1753indicate a choice or sequence respectively. The
1754<code>numchildren</code> field indicates how many nodes in the choice
1755or sequence and <code>children</code> points to the nodes.</p>
1756</div>
1757
1758<div class="handler">
1759<pre class="setter" id="XML_SetAttlistDeclHandler">
1760void XMLCALL
1277XML_SetAttlistDeclHandler(XML_Parser p,
1278 XML_AttlistDeclHandler attdecl);
1279</pre>
1280<pre class="signature">
1281typedef void
1761XML_SetAttlistDeclHandler(XML_Parser p,
1762 XML_AttlistDeclHandler attdecl);
1763</pre>
1764<pre class="signature">
1765typedef void
1282(*XML_AttlistDeclHandler) (void *userData,
1283 const XML_Char *elname,
1284 const XML_Char *attname,
1285 const XML_Char *att_type,
1286 const XML_Char *dflt,
1287 int isrequired);
1766(XMLCALL *XML_AttlistDeclHandler)(void *userData,
1767 const XML_Char *elname,
1768 const XML_Char *attname,
1769 const XML_Char *att_type,
1770 const XML_Char *dflt,
1771 int isrequired);
1288</pre>
1289<p>Set a handler for attlist declarations in the DTD. This handler is
1290called for <em>each</em> attribute. So a single attlist declaration
1291with multiple attributes declared will generate multiple calls to this
1292handler. The <code>elname</code> parameter returns the name of the
1293element for which the attribute is being declared. The attribute name
1294is in the <code>attname</code> parameter. The attribute type is in the
1295<code>att_type</code> parameter. It is the string representing the

--- 5 unchanged lines hidden (view full) ---

1301parameter, which will be true in the case of "#REQUIRED" attributes.
1302Attributes which are "#FIXED" will have also have a true
1303<code>isrequired</code>, but they will have the non-NULL fixed value
1304in the <code>dflt</code> parameter.</p>
1305</div>
1306
1307<div class="handler">
1308<pre class="setter" id="XML_SetEntityDeclHandler">
1772</pre>
1773<p>Set a handler for attlist declarations in the DTD. This handler is
1774called for <em>each</em> attribute. So a single attlist declaration
1775with multiple attributes declared will generate multiple calls to this
1776handler. The <code>elname</code> parameter returns the name of the
1777element for which the attribute is being declared. The attribute name
1778is in the <code>attname</code> parameter. The attribute type is in the
1779<code>att_type</code> parameter. It is the string representing the

--- 5 unchanged lines hidden (view full) ---

1785parameter, which will be true in the case of "#REQUIRED" attributes.
1786Attributes which are "#FIXED" will have also have a true
1787<code>isrequired</code>, but they will have the non-NULL fixed value
1788in the <code>dflt</code> parameter.</p>
1789</div>
1790
1791<div class="handler">
1792<pre class="setter" id="XML_SetEntityDeclHandler">
1793void XMLCALL
1309XML_SetEntityDeclHandler(XML_Parser p,
1310 XML_EntityDeclHandler handler);
1311</pre>
1312<pre class="signature">
1313typedef void
1794XML_SetEntityDeclHandler(XML_Parser p,
1795 XML_EntityDeclHandler handler);
1796</pre>
1797<pre class="signature">
1798typedef void
1314(*XML_EntityDeclHandler) (void *userData,
1315 const XML_Char *entityName,
1316 int is_parameter_entity,
1317 const XML_Char *value,
1318 int value_length,
1319 const XML_Char *base,
1320 const XML_Char *systemId,
1321 const XML_Char *publicId,
1322 const XML_Char *notationName);
1799(XMLCALL *XML_EntityDeclHandler)(void *userData,
1800 const XML_Char *entityName,
1801 int is_parameter_entity,
1802 const XML_Char *value,
1803 int value_length,
1804 const XML_Char *base,
1805 const XML_Char *systemId,
1806 const XML_Char *publicId,
1807 const XML_Char *notationName);
1323</pre>
1324<p>Sets a handler that will be called for all entity declarations.
1325The <code>is_parameter_entity</code> argument will be non-zero in the
1326case of parameter entities and zero otherwise.</p>
1327
1328<p>For internal entities (<code>&lt;!ENTITY foo "bar"&gt;</code>),
1329<code>value</code> will be non-NULL and <code>systemId</code>,
1330<code>publicId</code>, and <code>notationName</code> will all be NULL.
1331The value string is <em>not</em> NULL terminated; the length is
1332provided in the <code>value_length</code> parameter. Do not use
1333<code>value_length</code> to test for internal entities, since it is
1334legal to have zero-length values. Instead check for whether or not
1335<code>value</code> is NULL.</p> <p>The <code>notationName</code>
1336argument will have a non-NULL value only for unparsed entity
1337declarations.</p>
1338</div>
1339
1340<div class="handler">
1341<pre class="setter" id="XML_SetUnparsedEntityDeclHandler">
1808</pre>
1809<p>Sets a handler that will be called for all entity declarations.
1810The <code>is_parameter_entity</code> argument will be non-zero in the
1811case of parameter entities and zero otherwise.</p>
1812
1813<p>For internal entities (<code>&lt;!ENTITY foo "bar"&gt;</code>),
1814<code>value</code> will be non-NULL and <code>systemId</code>,
1815<code>publicId</code>, and <code>notationName</code> will all be NULL.
1816The value string is <em>not</em> NULL terminated; the length is
1817provided in the <code>value_length</code> parameter. Do not use
1818<code>value_length</code> to test for internal entities, since it is
1819legal to have zero-length values. Instead check for whether or not
1820<code>value</code> is NULL.</p> <p>The <code>notationName</code>
1821argument will have a non-NULL value only for unparsed entity
1822declarations.</p>
1823</div>
1824
1825<div class="handler">
1826<pre class="setter" id="XML_SetUnparsedEntityDeclHandler">
1827void XMLCALL
1342XML_SetUnparsedEntityDeclHandler(XML_Parser p,
1343 XML_UnparsedEntityDeclHandler h)
1344</pre>
1345<pre class="signature">
1346typedef void
1828XML_SetUnparsedEntityDeclHandler(XML_Parser p,
1829 XML_UnparsedEntityDeclHandler h)
1830</pre>
1831<pre class="signature">
1832typedef void
1347(*XML_UnparsedEntityDeclHandler)(void *userData,
1348 const XML_Char *entityName,
1349 const XML_Char *base,
1350 const XML_Char *systemId,
1351 const XML_Char *publicId,
1352 const XML_Char *notationName);
1833(XMLCALL *XML_UnparsedEntityDeclHandler)(void *userData,
1834 const XML_Char *entityName,
1835 const XML_Char *base,
1836 const XML_Char *systemId,
1837 const XML_Char *publicId,
1838 const XML_Char *notationName);
1353</pre>
1354<p>Set a handler that receives declarations of unparsed entities. These
1355are entity declarations that have a notation (NDATA) field:</p>
1356
1357<div id="eg"><pre>
1358&lt;!ENTITY logo SYSTEM "images/logo.gif" NDATA gif&gt;
1359</pre></div>
1360<p>This handler is obsolete and is provided for backwards
1361compatibility. Use instead <a href= "#XML_SetEntityDeclHandler"
1362>XML_SetEntityDeclHandler</a>.</p>
1363</div>
1364
1365<div class="handler">
1366<pre class="setter" id="XML_SetNotationDeclHandler">
1839</pre>
1840<p>Set a handler that receives declarations of unparsed entities. These
1841are entity declarations that have a notation (NDATA) field:</p>
1842
1843<div id="eg"><pre>
1844&lt;!ENTITY logo SYSTEM "images/logo.gif" NDATA gif&gt;
1845</pre></div>
1846<p>This handler is obsolete and is provided for backwards
1847compatibility. Use instead <a href= "#XML_SetEntityDeclHandler"
1848>XML_SetEntityDeclHandler</a>.</p>
1849</div>
1850
1851<div class="handler">
1852<pre class="setter" id="XML_SetNotationDeclHandler">
1853void XMLCALL
1367XML_SetNotationDeclHandler(XML_Parser p,
1368 XML_NotationDeclHandler h)
1369</pre>
1370<pre class="signature">
1371typedef void
1854XML_SetNotationDeclHandler(XML_Parser p,
1855 XML_NotationDeclHandler h)
1856</pre>
1857<pre class="signature">
1858typedef void
1372(*XML_NotationDeclHandler)(void *userData,
1373 const XML_Char *notationName,
1374 const XML_Char *base,
1375 const XML_Char *systemId,
1376 const XML_Char *publicId);
1859(XMLCALL *XML_NotationDeclHandler)(void *userData,
1860 const XML_Char *notationName,
1861 const XML_Char *base,
1862 const XML_Char *systemId,
1863 const XML_Char *publicId);
1377</pre>
1378<p>Set a handler that receives notation declarations.</p>
1379</div>
1380
1381<div class="handler">
1382<pre class="setter" id="XML_SetNotStandaloneHandler">
1864</pre>
1865<p>Set a handler that receives notation declarations.</p>
1866</div>
1867
1868<div class="handler">
1869<pre class="setter" id="XML_SetNotStandaloneHandler">
1870void XMLCALL
1383XML_SetNotStandaloneHandler(XML_Parser p,
1384 XML_NotStandaloneHandler h)
1385</pre>
1386<pre class="signature">
1387typedef int
1871XML_SetNotStandaloneHandler(XML_Parser p,
1872 XML_NotStandaloneHandler h)
1873</pre>
1874<pre class="signature">
1875typedef int
1388(*XML_NotStandaloneHandler)(void *userData);
1876(XMLCALL *XML_NotStandaloneHandler)(void *userData);
1389</pre>
1390<p>Set a handler that is called if the document is not "standalone".
1391This happens when there is an external subset or a reference to a
1392parameter entity, but does not have standalone set to "yes" in an XML
1877</pre>
1878<p>Set a handler that is called if the document is not "standalone".
1879This happens when there is an external subset or a reference to a
1880parameter entity, but does not have standalone set to "yes" in an XML
1393declaration. If this handler returns 0, then the parser will throw an
1394<code>XML_ERROR_NOT_STANDALONE</code> error.</p>
1881declaration. If this handler returns <code>XML_STATUS_ERROR</code>,
1882then the parser will throw an <code>XML_ERROR_NOT_STANDALONE</code>
1883error.</p>
1395</div>
1396
1397<h3><a name="position">Parse position and error reporting functions</a></h3>
1398
1399<p>These are the functions you'll want to call when the parse
1884</div>
1885
1886<h3><a name="position">Parse position and error reporting functions</a></h3>
1887
1888<p>These are the functions you'll want to call when the parse
1400functions return 0 (i.e. a parse error has ocurred), although the
1401position reporting functions are useful outside of errors. The
1402position reported is the byte position (in the original document or
1403entity encoding) of the first of the sequence of characters that
1404generated the current event (or the error that caused the parse
1405functions to return 0.)</p>
1889functions return <code>XML_STATUS_ERROR</code> (a parse error has
1890occurred), although the position reporting functions are useful outside
1891of errors. The position reported is the byte position (in the original
1892document or entity encoding) of the first of the sequence of
1893characters that generated the current event (or the error that caused
1894the parse functions to return <code>XML_STATUS_ERROR</code>.) The
1895exceptions are callbacks trigged by declarations in the document
1896prologue, in which case they exact position reported is somewhere in the
1897relevant markup, but not necessarily as meaningful as for other
1898events.</p>
1406
1407<p>The position reporting functions are accurate only outside of the
1408DTD. In other words, they usually return bogus information when
1409called from within a DTD declaration handler.</p>
1410
1411<pre class="fcndec" id="XML_GetErrorCode">
1899
1900<p>The position reporting functions are accurate only outside of the
1901DTD. In other words, they usually return bogus information when
1902called from within a DTD declaration handler.</p>
1903
1904<pre class="fcndec" id="XML_GetErrorCode">
1412enum XML_Error
1905enum XML_Error XMLCALL
1413XML_GetErrorCode(XML_Parser p);
1414</pre>
1415<div class="fcndef">
1416Return what type of error has occurred.
1417</div>
1418
1419<pre class="fcndec" id="XML_ErrorString">
1906XML_GetErrorCode(XML_Parser p);
1907</pre>
1908<div class="fcndef">
1909Return what type of error has occurred.
1910</div>
1911
1912<pre class="fcndec" id="XML_ErrorString">
1420const XML_LChar *
1421XML_ErrorString(int code);
1913const XML_LChar * XMLCALL
1914XML_ErrorString(enum XML_Error code);
1422</pre>
1423<div class="fcndef">
1424Return a string describing the error corresponding to code.
1425The code should be one of the enums that can be returned from
1426<code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>.
1427</div>
1428
1429<pre class="fcndec" id="XML_GetCurrentByteIndex">
1915</pre>
1916<div class="fcndef">
1917Return a string describing the error corresponding to code.
1918The code should be one of the enums that can be returned from
1919<code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>.
1920</div>
1921
1922<pre class="fcndec" id="XML_GetCurrentByteIndex">
1430long
1923XML_Index XMLCALL
1431XML_GetCurrentByteIndex(XML_Parser p);
1432</pre>
1433<div class="fcndef">
1924XML_GetCurrentByteIndex(XML_Parser p);
1925</pre>
1926<div class="fcndef">
1434Return the byte offset of the position.
1927Return the byte offset of the position. This always corresponds to
1928the values returned by <code><a href= "#XML_GetCurrentLineNumber"
1929>XML_GetCurrentLineNumber</a></code> and <code><a href=
1930"#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>.
1435</div>
1436
1437<pre class="fcndec" id="XML_GetCurrentLineNumber">
1931</div>
1932
1933<pre class="fcndec" id="XML_GetCurrentLineNumber">
1438int
1934XML_Size XMLCALL
1439XML_GetCurrentLineNumber(XML_Parser p);
1440</pre>
1441<div class="fcndef">
1935XML_GetCurrentLineNumber(XML_Parser p);
1936</pre>
1937<div class="fcndef">
1442Return the line number of the position.
1938Return the line number of the position. The first line is reported as
1939<code>1</code>.
1443</div>
1444
1445<pre class="fcndec" id="XML_GetCurrentColumnNumber">
1940</div>
1941
1942<pre class="fcndec" id="XML_GetCurrentColumnNumber">
1446int
1943XML_Size XMLCALL
1447XML_GetCurrentColumnNumber(XML_Parser p);
1448</pre>
1449<div class="fcndef">
1450Return the offset, from the beginning of the current line, of
1451the position.
1452</div>
1453
1454<pre class="fcndec" id="XML_GetCurrentByteCount">
1944XML_GetCurrentColumnNumber(XML_Parser p);
1945</pre>
1946<div class="fcndef">
1947Return the offset, from the beginning of the current line, of
1948the position.
1949</div>
1950
1951<pre class="fcndec" id="XML_GetCurrentByteCount">
1455int
1952int XMLCALL
1456XML_GetCurrentByteCount(XML_Parser p);
1457</pre>
1458<div class="fcndef">
1459Return the number of bytes in the current event. Returns
1460<code>0</code> if the event is inside a reference to an internal
1461entity and for the end-tag event for empty element tags (the later can
1462be used to distinguish empty-element tags from empty elements using
1463separate start and end tags).
1464</div>
1465
1466<pre class="fcndec" id="XML_GetInputContext">
1953XML_GetCurrentByteCount(XML_Parser p);
1954</pre>
1955<div class="fcndef">
1956Return the number of bytes in the current event. Returns
1957<code>0</code> if the event is inside a reference to an internal
1958entity and for the end-tag event for empty element tags (the later can
1959be used to distinguish empty-element tags from empty elements using
1960separate start and end tags).
1961</div>
1962
1963<pre class="fcndec" id="XML_GetInputContext">
1467const char *
1964const char * XMLCALL
1468XML_GetInputContext(XML_Parser p,
1469 int *offset,
1470 int *size);
1471</pre>
1472<div class="fcndef">
1473
1474<p>Returns the parser's input buffer, sets the integer pointed at by
1475<code>offset</code> to the offset within this buffer of the current
1476parse position, and set the integer pointed at by <code>size</code> to
1477the size of the returned buffer.</p>
1478
1479<p>This should only be called from within a handler during an active
1480parse and the returned buffer should only be referred to from within
1481the handler that made the call. This input buffer contains the
1482untranslated bytes of the input.</p>
1483
1484<p>Only a limited amount of context is kept, so if the event
1485triggering a call spans over a very large amount of input, the actual
1486parse position may be before the beginning of the buffer.</p>
1965XML_GetInputContext(XML_Parser p,
1966 int *offset,
1967 int *size);
1968</pre>
1969<div class="fcndef">
1970
1971<p>Returns the parser's input buffer, sets the integer pointed at by
1972<code>offset</code> to the offset within this buffer of the current
1973parse position, and set the integer pointed at by <code>size</code> to
1974the size of the returned buffer.</p>
1975
1976<p>This should only be called from within a handler during an active
1977parse and the returned buffer should only be referred to from within
1978the handler that made the call. This input buffer contains the
1979untranslated bytes of the input.</p>
1980
1981<p>Only a limited amount of context is kept, so if the event
1982triggering a call spans over a very large amount of input, the actual
1983parse position may be before the beginning of the buffer.</p>
1984
1985<p>If <code>XML_CONTEXT_BYTES</code> is not defined, this will always
1986return NULL.</p>
1487</div>
1488
1489<h3><a name="miscellaneous">Miscellaneous functions</a></h3>
1490
1491<p>The functions in this section either obtain state information from
1492the parser or can be used to dynamicly set parser options.</p>
1493
1494<pre class="fcndec" id="XML_SetUserData">
1987</div>
1988
1989<h3><a name="miscellaneous">Miscellaneous functions</a></h3>
1990
1991<p>The functions in this section either obtain state information from
1992the parser or can be used to dynamicly set parser options.</p>
1993
1994<pre class="fcndec" id="XML_SetUserData">
1495void
1995void XMLCALL
1496XML_SetUserData(XML_Parser p,
1497 void *userData);
1498</pre>
1499<div class="fcndef">
1500This sets the user data pointer that gets passed to handlers. It
1501overwrites any previous value for this pointer. Note that the
1502application is responsible for freeing the memory associated with
1503<code>userData</code> when it is finished with the parser. So if you
1504call this when there's already a pointer there, and you haven't freed
1505the memory associated with it, then you've probably just leaked
1506memory.
1507</div>
1508
1509<pre class="fcndec" id="XML_GetUserData">
1996XML_SetUserData(XML_Parser p,
1997 void *userData);
1998</pre>
1999<div class="fcndef">
2000This sets the user data pointer that gets passed to handlers. It
2001overwrites any previous value for this pointer. Note that the
2002application is responsible for freeing the memory associated with
2003<code>userData</code> when it is finished with the parser. So if you
2004call this when there's already a pointer there, and you haven't freed
2005the memory associated with it, then you've probably just leaked
2006memory.
2007</div>
2008
2009<pre class="fcndec" id="XML_GetUserData">
1510void *
2010void * XMLCALL
1511XML_GetUserData(XML_Parser p);
1512</pre>
1513<div class="fcndef">
1514This returns the user data pointer that gets passed to handlers.
1515It is actually implemented as a macro.
1516</div>
1517
1518<pre class="fcndec" id="XML_UseParserAsHandlerArg">
2011XML_GetUserData(XML_Parser p);
2012</pre>
2013<div class="fcndef">
2014This returns the user data pointer that gets passed to handlers.
2015It is actually implemented as a macro.
2016</div>
2017
2018<pre class="fcndec" id="XML_UseParserAsHandlerArg">
1519void
2019void XMLCALL
1520XML_UseParserAsHandlerArg(XML_Parser p);
1521</pre>
1522<div class="fcndef">
2020XML_UseParserAsHandlerArg(XML_Parser p);
2021</pre>
2022<div class="fcndef">
1523After this is called, handlers receive the parser in the userData
1524argument. The userData information can still be obtained using the
1525<code><a href= "#XML_GetUserData" >XML_GetUserData</a></code>
1526function.
2023After this is called, handlers receive the parser in their
2024<code>userData</code> arguments. The user data can still be obtained
2025using the <code><a href= "#XML_GetUserData"
2026>XML_GetUserData</a></code> function.
1527</div>
1528
1529<pre class="fcndec" id="XML_SetBase">
2027</div>
2028
2029<pre class="fcndec" id="XML_SetBase">
1530int
2030enum XML_Status XMLCALL
1531XML_SetBase(XML_Parser p,
1532 const XML_Char *base);
1533</pre>
1534<div class="fcndef">
1535Set the base to be used for resolving relative URIs in system
2031XML_SetBase(XML_Parser p,
2032 const XML_Char *base);
2033</pre>
2034<div class="fcndef">
2035Set the base to be used for resolving relative URIs in system
1536identifiers. The return value is 0 if there's no memory to store
1537base, otherwise it's non-zero.
2036identifiers. The return value is <code>XML_STATUS_ERROR</code> if
2037there's no memory to store base, otherwise it's
2038<code>XML_STATUS_OK</code>.
1538</div>
1539
1540<pre class="fcndec" id="XML_GetBase">
2039</div>
2040
2041<pre class="fcndec" id="XML_GetBase">
1541const XML_Char *
2042const XML_Char * XMLCALL
1542XML_GetBase(XML_Parser p);
1543</pre>
1544<div class="fcndef">
1545Return the base for resolving relative URIs.
1546</div>
1547
1548<pre class="fcndec" id="XML_GetSpecifiedAttributeCount">
2043XML_GetBase(XML_Parser p);
2044</pre>
2045<div class="fcndef">
2046Return the base for resolving relative URIs.
2047</div>
2048
2049<pre class="fcndec" id="XML_GetSpecifiedAttributeCount">
1549int
2050int XMLCALL
1550XML_GetSpecifiedAttributeCount(XML_Parser p);
1551</pre>
1552<div class="fcndef">
1553When attributes are reported to the start handler in the atts vector,
1554attributes that were explicitly set in the element occur before any
1555attributes that receive their value from default information in an
1556ATTLIST declaration. This function returns the number of attributes
1557that were explicitly set times two, thus giving the offset in the
1558<code>atts</code> array passed to the start tag handler of the first
1559attribute set due to defaults. It supplies information for the last
1560call to a start handler. If called inside a start handler, then that
1561means the current call.
1562</div>
1563
1564<pre class="fcndec" id="XML_GetIdAttributeIndex">
2051XML_GetSpecifiedAttributeCount(XML_Parser p);
2052</pre>
2053<div class="fcndef">
2054When attributes are reported to the start handler in the atts vector,
2055attributes that were explicitly set in the element occur before any
2056attributes that receive their value from default information in an
2057ATTLIST declaration. This function returns the number of attributes
2058that were explicitly set times two, thus giving the offset in the
2059<code>atts</code> array passed to the start tag handler of the first
2060attribute set due to defaults. It supplies information for the last
2061call to a start handler. If called inside a start handler, then that
2062means the current call.
2063</div>
2064
2065<pre class="fcndec" id="XML_GetIdAttributeIndex">
1565int
2066int XMLCALL
1566XML_GetIdAttributeIndex(XML_Parser p);
1567</pre>
1568<div class="fcndef">
1569Returns the index of the ID attribute passed in the atts array in the
1570last call to <code><a href= "#XML_StartElementHandler"
1571>XML_StartElementHandler</a></code>, or -1 if there is no ID
1572attribute. If called inside a start handler, then that means the
1573current call.
1574</div>
1575
1576<pre class="fcndec" id="XML_SetEncoding">
2067XML_GetIdAttributeIndex(XML_Parser p);
2068</pre>
2069<div class="fcndef">
2070Returns the index of the ID attribute passed in the atts array in the
2071last call to <code><a href= "#XML_StartElementHandler"
2072>XML_StartElementHandler</a></code>, or -1 if there is no ID
2073attribute. If called inside a start handler, then that means the
2074current call.
2075</div>
2076
2077<pre class="fcndec" id="XML_SetEncoding">
1577int
2078enum XML_Status XMLCALL
1578XML_SetEncoding(XML_Parser p,
1579 const XML_Char *encoding);
1580</pre>
1581<div class="fcndef">
1582Set the encoding to be used by the parser. It is equivalent to
1583passing a non-null encoding argument to the parser creation functions.
1584It must not be called after <code><a href= "#XML_Parse"
1585>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
1586>XML_ParseBuffer</a></code> have been called on the given parser.
2079XML_SetEncoding(XML_Parser p,
2080 const XML_Char *encoding);
2081</pre>
2082<div class="fcndef">
2083Set the encoding to be used by the parser. It is equivalent to
2084passing a non-null encoding argument to the parser creation functions.
2085It must not be called after <code><a href= "#XML_Parse"
2086>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
2087>XML_ParseBuffer</a></code> have been called on the given parser.
2088Returns <code>XML_STATUS_OK</code> on success or
2089<code>XML_STATUS_ERROR</code> on error.
1587</div>
1588
1589<pre class="fcndec" id="XML_SetParamEntityParsing">
2090</div>
2091
2092<pre class="fcndec" id="XML_SetParamEntityParsing">
1590int
2093int XMLCALL
1591XML_SetParamEntityParsing(XML_Parser p,
1592 enum XML_ParamEntityParsing code);
1593</pre>
1594<div class="fcndef">
1595This enables parsing of parameter entities, including the external
1596parameter entity that is the external DTD subset, according to
1597<code>code</code>.
1598The choices for <code>code</code> are:
1599<ul>
1600<li><code>XML_PARAM_ENTITY_PARSING_NEVER</code></li>
1601<li><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></li>
1602<li><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></li>
1603</ul>
1604</div>
1605
1606<pre class="fcndec" id="XML_UseForeignDTD">
2094XML_SetParamEntityParsing(XML_Parser p,
2095 enum XML_ParamEntityParsing code);
2096</pre>
2097<div class="fcndef">
2098This enables parsing of parameter entities, including the external
2099parameter entity that is the external DTD subset, according to
2100<code>code</code>.
2101The choices for <code>code</code> are:
2102<ul>
2103<li><code>XML_PARAM_ENTITY_PARSING_NEVER</code></li>
2104<li><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></li>
2105<li><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></li>
2106</ul>
2107</div>
2108
2109<pre class="fcndec" id="XML_UseForeignDTD">
1607enum XML_Error
2110enum XML_Error XMLCALL
1608XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
1609</pre>
1610<div class="fcndef">
1611<p>This function allows an application to provide an external subset
1612for the document type declaration for documents which do not specify
1613an external subset of their own. For documents which specify an
1614external subset in their DOCTYPE declaration, the application-provided
1615subset will be ignored. If the document does not contain a DOCTYPE

--- 12 unchanged lines hidden (view full) ---

1628<code>publicId</code> and <code>systemId</code> set to NULL.</p>
1629
1630<p>If this function is called after parsing has begun, it returns
1631<code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores
1632<code>useDTD</code>. If called when Expat has been compiled without
1633DTD support, it returns
1634<code>XML_ERROR_FEATURE_REQUIRES_XML_DTD</code>. Otherwise, it
1635returns <code>XML_ERROR_NONE</code>.</p>
2111XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
2112</pre>
2113<div class="fcndef">
2114<p>This function allows an application to provide an external subset
2115for the document type declaration for documents which do not specify
2116an external subset of their own. For documents which specify an
2117external subset in their DOCTYPE declaration, the application-provided
2118subset will be ignored. If the document does not contain a DOCTYPE

--- 12 unchanged lines hidden (view full) ---

2131<code>publicId</code> and <code>systemId</code> set to NULL.</p>
2132
2133<p>If this function is called after parsing has begun, it returns
2134<code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores
2135<code>useDTD</code>. If called when Expat has been compiled without
2136DTD support, it returns
2137<code>XML_ERROR_FEATURE_REQUIRES_XML_DTD</code>. Otherwise, it
2138returns <code>XML_ERROR_NONE</code>.</p>
2139
2140<p><b>Note:</b> For the purpose of checking WFC: Entity Declared, passing
2141<code>useDTD == XML_TRUE</code> will make the parser behave as if
2142the document had a DTD with an external subset. This holds true even if
2143the external entity reference handler returns without action.</p>
1636</div>
1637
1638<pre class="fcndec" id="XML_SetReturnNSTriplet">
2144</div>
2145
2146<pre class="fcndec" id="XML_SetReturnNSTriplet">
1639void
2147void XMLCALL
1640XML_SetReturnNSTriplet(XML_Parser parser,
1641 int do_nst);
1642</pre>
1643<div class="fcndef">
1644<p>
1645This function only has an effect when using a parser created with
1646<code><a href= "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>,
1647i.e. when namespace processing is in effect. The <code>do_nst</code>

--- 5 unchanged lines hidden (view full) ---

1653separator specified when the parser was created. The order of
1654returned parts is URI, local name, and prefix.</p> <p>If
1655<code>do_nst</code> is zero, then namespaces are reported in the
1656default manner, URI then local_name separated by the namespace
1657separator.</p>
1658</div>
1659
1660<pre class="fcndec" id="XML_DefaultCurrent">
2148XML_SetReturnNSTriplet(XML_Parser parser,
2149 int do_nst);
2150</pre>
2151<div class="fcndef">
2152<p>
2153This function only has an effect when using a parser created with
2154<code><a href= "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>,
2155i.e. when namespace processing is in effect. The <code>do_nst</code>

--- 5 unchanged lines hidden (view full) ---

2161separator specified when the parser was created. The order of
2162returned parts is URI, local name, and prefix.</p> <p>If
2163<code>do_nst</code> is zero, then namespaces are reported in the
2164default manner, URI then local_name separated by the namespace
2165separator.</p>
2166</div>
2167
2168<pre class="fcndec" id="XML_DefaultCurrent">
1661void
2169void XMLCALL
1662XML_DefaultCurrent(XML_Parser parser);
1663</pre>
1664<div class="fcndef">
1665This can be called within a handler for a start element, end element,
1666processing instruction or character data. It causes the corresponding
1667markup to be passed to the default handler set by <code><a
1668href="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or
1669<code><a href="#XML_SetDefaultHandlerExpand"
1670>XML_SetDefaultHandlerExpand</a></code>. It does nothing if there is
1671not a default handler.
1672</div>
1673
1674<pre class="fcndec" id="XML_ExpatVersion">
2170XML_DefaultCurrent(XML_Parser parser);
2171</pre>
2172<div class="fcndef">
2173This can be called within a handler for a start element, end element,
2174processing instruction or character data. It causes the corresponding
2175markup to be passed to the default handler set by <code><a
2176href="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or
2177<code><a href="#XML_SetDefaultHandlerExpand"
2178>XML_SetDefaultHandlerExpand</a></code>. It does nothing if there is
2179not a default handler.
2180</div>
2181
2182<pre class="fcndec" id="XML_ExpatVersion">
1675XML_LChar *
2183XML_LChar * XMLCALL
1676XML_ExpatVersion();
1677</pre>
1678<div class="fcndef">
1679Return the library version as a string (e.g. <code>"expat_1.95.1"</code>).
1680</div>
1681
1682<pre class="fcndec" id="XML_ExpatVersionInfo">
2184XML_ExpatVersion();
2185</pre>
2186<div class="fcndef">
2187Return the library version as a string (e.g. <code>"expat_1.95.1"</code>).
2188</div>
2189
2190<pre class="fcndec" id="XML_ExpatVersionInfo">
1683struct XML_Expat_Version
2191struct XML_Expat_Version XMLCALL
1684XML_ExpatVersionInfo();
1685</pre>
1686<pre class="signature">
1687typedef struct {
1688 int major;
1689 int minor;
1690 int micro;
1691} XML_Expat_Version;

--- 7 unchanged lines hidden (view full) ---

1699<li><code>XML_MINOR_VERSION</code></li>
1700<li><code>XML_MICRO_VERSION</code></li>
1701</ul>
1702Testing these constants is currently the best way to determine if
1703particular parts of the Expat API are available.
1704</div>
1705
1706<pre class="fcndec" id="XML_GetFeatureList">
2192XML_ExpatVersionInfo();
2193</pre>
2194<pre class="signature">
2195typedef struct {
2196 int major;
2197 int minor;
2198 int micro;
2199} XML_Expat_Version;

--- 7 unchanged lines hidden (view full) ---

2207<li><code>XML_MINOR_VERSION</code></li>
2208<li><code>XML_MICRO_VERSION</code></li>
2209</ul>
2210Testing these constants is currently the best way to determine if
2211particular parts of the Expat API are available.
2212</div>
2213
2214<pre class="fcndec" id="XML_GetFeatureList">
1707const XML_Feature *
2215const XML_Feature * XMLCALL
1708XML_GetFeatureList();
1709</pre>
1710<pre class="signature">
1711enum XML_FeatureEnum {
1712 XML_FEATURE_END = 0,
1713 XML_FEATURE_UNICODE,
1714 XML_FEATURE_UNICODE_WCHAR_T,
1715 XML_FEATURE_DTD,
1716 XML_FEATURE_CONTEXT_BYTES,
1717 XML_FEATURE_MIN_SIZE,
1718 XML_FEATURE_SIZEOF_XML_CHAR,
2216XML_GetFeatureList();
2217</pre>
2218<pre class="signature">
2219enum XML_FeatureEnum {
2220 XML_FEATURE_END = 0,
2221 XML_FEATURE_UNICODE,
2222 XML_FEATURE_UNICODE_WCHAR_T,
2223 XML_FEATURE_DTD,
2224 XML_FEATURE_CONTEXT_BYTES,
2225 XML_FEATURE_MIN_SIZE,
2226 XML_FEATURE_SIZEOF_XML_CHAR,
1719 XML_FEATURE_SIZEOF_XML_LCHAR
2227 XML_FEATURE_SIZEOF_XML_LCHAR,
2228 XML_FEATURE_NS,
2229 XML_FEATURE_LARGE_SIZE
1720};
1721
1722typedef struct {
1723 enum XML_FeatureEnum feature;
1724 XML_LChar *name;
1725 long int value;
1726} XML_Feature;
1727</pre>

--- 29 unchanged lines hidden (view full) ---

1757 character.</dd>
1758 <dt><code>XML_FEATURE_CONTEXT_BYTES</code></dt>
1759 <dd>The maximum number of characters of context which can be
1760 reported by <code><a href= "#XML_GetInputContext"
1761 >XML_GetInputContext</a></code>.</dd>
1762</dl>
1763</div>
1764
2230};
2231
2232typedef struct {
2233 enum XML_FeatureEnum feature;
2234 XML_LChar *name;
2235 long int value;
2236} XML_Feature;
2237</pre>

--- 29 unchanged lines hidden (view full) ---

2267 character.</dd>
2268 <dt><code>XML_FEATURE_CONTEXT_BYTES</code></dt>
2269 <dd>The maximum number of characters of context which can be
2270 reported by <code><a href= "#XML_GetInputContext"
2271 >XML_GetInputContext</a></code>.</dd>
2272</dl>
2273</div>
2274
2275<pre class="fcndec" id="XML_FreeContentModel">
2276void XMLCALL
2277XML_FreeContentModel(XML_Parser parser, XML_Content *model);
2278</pre>
2279<div class="fcndef">
2280Function to deallocate the <code>model</code> argument passed to the
2281<code>XML_ElementDeclHandler</code> callback set using <code><a
2282href="#XML_SetElementDeclHandler" >XML_ElementDeclHandler</a></code>.
2283This function should not be used for any other purpose.
2284</div>
2285
2286<p>The following functions allow external code to share the memory
2287allocator an <code>XML_Parser</code> has been configured to use. This
2288is especially useful for third-party libraries that interact with a
2289parser object created by application code, or heavily layered
2290applications. This can be essential when using dynamically loaded
2291libraries which use different C standard libraries (this can happen on
2292Windows, at least).</p>
2293
2294<pre class="fcndec" id="XML_MemMalloc">
2295void * XMLCALL
2296XML_MemMalloc(XML_Parser parser, size_t size);
2297</pre>
2298<div class="fcndef">
2299Allocate <code>size</code> bytes of memory using the allocator the
2300<code>parser</code> object has been configured to use. Returns a
2301pointer to the memory or NULL on failure. Memory allocated in this
2302way must be freed using <code><a href="#XML_MemFree"
2303>XML_MemFree</a></code>.
2304</div>
2305
2306<pre class="fcndec" id="XML_MemRealloc">
2307void * XMLCALL
2308XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
2309</pre>
2310<div class="fcndef">
2311Allocate <code>size</code> bytes of memory using the allocator the
2312<code>parser</code> object has been configured to use.
2313<code>ptr</code> must point to a block of memory allocated by <code><a
2314href="#XML_MemMalloc" >XML_MemMalloc</a></code> or
2315<code>XML_MemRealloc</code>, or be NULL. This function tries to
2316expand the block pointed to by <code>ptr</code> if possible. Returns
2317a pointer to the memory or NULL on failure. On success, the original
2318block has either been expanded or freed. On failure, the original
2319block has not been freed; the caller is responsible for freeing the
2320original block. Memory allocated in this way must be freed using
2321<code><a href="#XML_MemFree"
2322>XML_MemFree</a></code>.
2323</div>
2324
2325<pre class="fcndec" id="XML_MemFree">
2326void XMLCALL
2327XML_MemFree(XML_Parser parser, void *ptr);
2328</pre>
2329<div class="fcndef">
2330Free a block of memory pointed to by <code>ptr</code>. The block must
2331have been allocated by <code><a href="#XML_MemMalloc"
2332>XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be NULL.
2333</div>
2334
1765<hr />
1766<p><a href="http://validator.w3.org/check/referer"><img
1767 src="valid-xhtml10.png" alt="Valid XHTML 1.0!"
1768 height="31" width="88" class="noborder" /></a></p>
2335<hr />
2336<p><a href="http://validator.w3.org/check/referer"><img
2337 src="valid-xhtml10.png" alt="Valid XHTML 1.0!"
2338 height="31" width="88" class="noborder" /></a></p>
2339</div>
1769</body>
1770</html>
2340</body>
2341</html>