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