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