xref: /freebsd/contrib/expat/doc/reference.html (revision 8d485a8490fe1cd60e7b6a00d3c8a8cc116a56fb)
15bb6a25fSPoul-Henning Kamp<?xml version="1.0" encoding="iso-8859-1"?>
25bb6a25fSPoul-Henning Kamp<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
35bb6a25fSPoul-Henning Kamp                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
45bb6a25fSPoul-Henning Kamp<html>
55bb6a25fSPoul-Henning Kamp<head>
6cc68614dSXin LI<!--
7cc68614dSXin LI                            __  __            _
8cc68614dSXin LI                         ___\ \/ /_ __   __ _| |_
9cc68614dSXin LI                        / _ \\  /| '_ \ / _` | __|
10cc68614dSXin LI                       |  __//  \| |_) | (_| | |_
11cc68614dSXin LI                        \___/_/\_\ .__/ \__,_|\__|
12cc68614dSXin LI                                 |_| XML parser
13cc68614dSXin LI
14cc68614dSXin LI   Copyright (c) 2000      Clark Cooper <coopercc@users.sourceforge.net>
15cc68614dSXin LI   Copyright (c) 2000-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
16cc68614dSXin LI   Copyright (c) 2002-2012 Karl Waclawek <karl@waclawek.net>
17fe927888SPhilip Paeps   Copyright (c) 2017-2025 Sebastian Pipping <sebastian@pipping.org>
18cc68614dSXin LI   Copyright (c) 2017      Jakub Wilk <jwilk@jwilk.net>
19cc68614dSXin LI   Copyright (c) 2021      Tomas Korbar <tkorbar@redhat.com>
20cc68614dSXin LI   Copyright (c) 2021      Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
217ed8e142SXin LI   Copyright (c) 2022      Thijs Schreijer <thijs@thijsschreijer.nl>
224543ef51SXin LI   Copyright (c) 2023      Hanno Böck <hanno@gentoo.org>
234543ef51SXin LI   Copyright (c) 2023      Sony Corporation / Snild Dolkow <snild@sony.com>
24cc68614dSXin LI   Licensed under the MIT license:
25cc68614dSXin LI
26cc68614dSXin LI   Permission is  hereby granted,  free of charge,  to any  person obtaining
27cc68614dSXin LI   a  copy  of  this  software   and  associated  documentation  files  (the
28cc68614dSXin LI   "Software"),  to  deal in  the  Software  without restriction,  including
29cc68614dSXin LI   without  limitation the  rights  to use,  copy,  modify, merge,  publish,
30cc68614dSXin LI   distribute, sublicense, and/or sell copies of the Software, and to permit
31cc68614dSXin LI   persons  to whom  the Software  is  furnished to  do so,  subject to  the
32cc68614dSXin LI   following conditions:
33cc68614dSXin LI
34cc68614dSXin LI   The above copyright  notice and this permission notice  shall be included
35cc68614dSXin LI   in all copies or substantial portions of the Software.
36cc68614dSXin LI
37cc68614dSXin LI   THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
38cc68614dSXin LI   EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
39cc68614dSXin LI   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
40cc68614dSXin LI   NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
41cc68614dSXin LI   DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
42cc68614dSXin LI   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
43cc68614dSXin LI   USE OR OTHER DEALINGS IN THE SOFTWARE.
44cc68614dSXin LI-->
455bb6a25fSPoul-Henning Kamp  <title>Expat XML Parser</title>
465bb6a25fSPoul-Henning Kamp  <meta name="author" content="Clark Cooper, coopercc@netheaven.com" />
475bb6a25fSPoul-Henning Kamp  <meta http-equiv="Content-Style-Type" content="text/css" />
48cc68614dSXin LI  <link href="ok.min.css" rel="stylesheet" type="text/css" />
495bb6a25fSPoul-Henning Kamp  <link href="style.css" rel="stylesheet" type="text/css" />
505bb6a25fSPoul-Henning Kamp</head>
515bb6a25fSPoul-Henning Kamp<body>
52cc68614dSXin LI  <div>
53cc68614dSXin LI    <h1>
54cc68614dSXin LI      The Expat XML Parser
55*8d485a84SXin LI      <small>Release 2.7.3</small>
56cc68614dSXin LI    </h1>
57cc68614dSXin LI  </div>
58220ed979SColeman Kane<div class="content">
595bb6a25fSPoul-Henning Kamp
605bb6a25fSPoul-Henning Kamp<p>Expat is a library, written in C, for parsing XML documents. It's
615bb6a25fSPoul-Henning Kampthe underlying XML parser for the open source Mozilla project, Perl's
625bb6a25fSPoul-Henning Kamp<code>XML::Parser</code>, Python's <code>xml.parsers.expat</code>, and
635bb6a25fSPoul-Henning Kampother open-source XML parsers.</p>
645bb6a25fSPoul-Henning Kamp
655bb6a25fSPoul-Henning Kamp<p>This library is the creation of James Clark, who's also given us
660a48773fSEric van Gyzengroff (an nroff look-alike), Jade (an implementation of ISO's DSSSL
675bb6a25fSPoul-Henning Kampstylesheet language for SGML), XP (a Java XML parser package), XT (a
685bb6a25fSPoul-Henning KampJava XSL engine).  James was also the technical lead on the XML
695bb6a25fSPoul-Henning KampWorking Group at W3C that produced the XML specification.</p>
705bb6a25fSPoul-Henning Kamp
715bb6a25fSPoul-Henning Kamp<p>This is free software, licensed under the <a
725bb6a25fSPoul-Henning Kamphref="../COPYING">MIT/X Consortium license</a>. You may download it
734543ef51SXin LIfrom <a href="https://libexpat.github.io/">the Expat home page</a>.
745bb6a25fSPoul-Henning Kamp</p>
755bb6a25fSPoul-Henning Kamp
76220ed979SColeman Kane<p>The bulk of this document was originally commissioned as an article
774543ef51SXin LIby <a href="https://www.xml.com/">XML.com</a>. They graciously allowed
78220ed979SColeman KaneClark Cooper to retain copyright and to distribute it with Expat.
79220ed979SColeman KaneThis version has been substantially extended to include documentation
80220ed979SColeman Kaneon features which have been added since the original article was
81220ed979SColeman Kanepublished, and additional information on using the original
82220ed979SColeman Kaneinterface.</p>
835bb6a25fSPoul-Henning Kamp
845bb6a25fSPoul-Henning Kamp<hr />
855bb6a25fSPoul-Henning Kamp<h2>Table of Contents</h2>
865bb6a25fSPoul-Henning Kamp<ul>
875bb6a25fSPoul-Henning Kamp  <li><a href="#overview">Overview</a></li>
885bb6a25fSPoul-Henning Kamp  <li><a href="#building">Building and Installing</a></li>
895bb6a25fSPoul-Henning Kamp  <li><a href="#using">Using Expat</a></li>
905bb6a25fSPoul-Henning Kamp  <li><a href="#reference">Reference</a>
915bb6a25fSPoul-Henning Kamp  <ul>
925bb6a25fSPoul-Henning Kamp    <li><a href="#creation">Parser Creation Functions</a>
935bb6a25fSPoul-Henning Kamp    <ul>
945bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ParserCreate">XML_ParserCreate</a></li>
955bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ParserCreateNS">XML_ParserCreateNS</a></li>
965bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ParserCreate_MM">XML_ParserCreate_MM</a></li>
975bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</a></li>
985bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ParserFree">XML_ParserFree</a></li>
995bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ParserReset">XML_ParserReset</a></li>
1005bb6a25fSPoul-Henning Kamp    </ul>
1015bb6a25fSPoul-Henning Kamp    </li>
1025bb6a25fSPoul-Henning Kamp    <li><a href="#parsing">Parsing Functions</a>
1035bb6a25fSPoul-Henning Kamp    <ul>
1045bb6a25fSPoul-Henning Kamp      <li><a href="#XML_Parse">XML_Parse</a></li>
1055bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ParseBuffer">XML_ParseBuffer</a></li>
1065bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetBuffer">XML_GetBuffer</a></li>
107220ed979SColeman Kane      <li><a href="#XML_StopParser">XML_StopParser</a></li>
108220ed979SColeman Kane      <li><a href="#XML_ResumeParser">XML_ResumeParser</a></li>
109220ed979SColeman Kane      <li><a href="#XML_GetParsingStatus">XML_GetParsingStatus</a></li>
1105bb6a25fSPoul-Henning Kamp    </ul>
1115bb6a25fSPoul-Henning Kamp    </li>
1125bb6a25fSPoul-Henning Kamp    <li><a href="#setting">Handler Setting Functions</a>
1135bb6a25fSPoul-Henning Kamp    <ul>
1145bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetStartElementHandler">XML_SetStartElementHandler</a></li>
1155bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetEndElementHandler">XML_SetEndElementHandler</a></li>
1165bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetElementHandler">XML_SetElementHandler</a></li>
1175bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</a></li>
1185bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</a></li>
1195bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetCommentHandler">XML_SetCommentHandler</a></li>
1205bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</a></li>
1215bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</a></li>
1225bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</a></li>
1235bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetDefaultHandler">XML_SetDefaultHandler</a></li>
1245bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</a></li>
1255bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></li>
126220ed979SColeman Kane      <li><a href="#XML_SetExternalEntityRefHandlerArg">XML_SetExternalEntityRefHandlerArg</a></li>
1275bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</a></li>
1285bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</a></li>
1295bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</a></li>
1305bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</a></li>
1315bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</a></li>
1325bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</a></li>
1335bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</a></li>
1345bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</a></li>
1355bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetDoctypeDeclHandler">XML_SetDoctypeDeclHandler</a></li>
1365bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetElementDeclHandler">XML_SetElementDeclHandler</a></li>
1375bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetAttlistDeclHandler">XML_SetAttlistDeclHandler</a></li>
1385bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetEntityDeclHandler">XML_SetEntityDeclHandler</a></li>
1395bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetUnparsedEntityDeclHandler">XML_SetUnparsedEntityDeclHandler</a></li>
1405bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetNotationDeclHandler">XML_SetNotationDeclHandler</a></li>
1415bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetNotStandaloneHandler">XML_SetNotStandaloneHandler</a></li>
1425bb6a25fSPoul-Henning Kamp    </ul>
1435bb6a25fSPoul-Henning Kamp    </li>
1445bb6a25fSPoul-Henning Kamp    <li><a href="#position">Parse Position and Error Reporting Functions</a>
1455bb6a25fSPoul-Henning Kamp    <ul>
1465bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetErrorCode">XML_GetErrorCode</a></li>
1475bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ErrorString">XML_ErrorString</a></li>
1485bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetCurrentByteIndex">XML_GetCurrentByteIndex</a></li>
1495bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetCurrentLineNumber">XML_GetCurrentLineNumber</a></li>
1505bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetCurrentColumnNumber">XML_GetCurrentColumnNumber</a></li>
1515bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetCurrentByteCount">XML_GetCurrentByteCount</a></li>
1525bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetInputContext">XML_GetInputContext</a></li>
1535bb6a25fSPoul-Henning Kamp    </ul>
1545bb6a25fSPoul-Henning Kamp    </li>
155cc68614dSXin LI    <li>
1564543ef51SXin LI      <a href="#attack-protection">Attack Protection</a>
157cc68614dSXin LI      <ul>
158cc68614dSXin LI        <li><a href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></li>
159cc68614dSXin LI        <li><a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">XML_SetBillionLaughsAttackProtectionActivationThreshold</a></li>
160627b778dSXin LI        <li><a href="#XML_SetAllocTrackerMaximumAmplification">XML_SetAllocTrackerMaximumAmplification</a></li>
161627b778dSXin LI        <li><a href="#XML_SetAllocTrackerActivationThreshold">XML_SetAllocTrackerActivationThreshold</a></li>
1624543ef51SXin LI        <li><a href="#XML_SetReparseDeferralEnabled">XML_SetReparseDeferralEnabled</a></li>
163cc68614dSXin LI      </ul>
164cc68614dSXin LI    </li>
1655bb6a25fSPoul-Henning Kamp    <li><a href="#miscellaneous">Miscellaneous Functions</a>
1665bb6a25fSPoul-Henning Kamp    <ul>
1675bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetUserData">XML_SetUserData</a></li>
1685bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetUserData">XML_GetUserData</a></li>
1695bb6a25fSPoul-Henning Kamp      <li><a href="#XML_UseParserAsHandlerArg">XML_UseParserAsHandlerArg</a></li>
1705bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetBase">XML_SetBase</a></li>
1715bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetBase">XML_GetBase</a></li>
1725bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetSpecifiedAttributeCount">XML_GetSpecifiedAttributeCount</a></li>
1735bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetIdAttributeIndex">XML_GetIdAttributeIndex</a></li>
174e3466a89SXin LI      <li><a href="#XML_GetAttributeInfo">XML_GetAttributeInfo</a></li>
1755bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetEncoding">XML_SetEncoding</a></li>
1765bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetParamEntityParsing">XML_SetParamEntityParsing</a></li>
177e3466a89SXin LI      <li><a href="#XML_SetHashSalt">XML_SetHashSalt</a></li>
1785bb6a25fSPoul-Henning Kamp      <li><a href="#XML_UseForeignDTD">XML_UseForeignDTD</a></li>
1795bb6a25fSPoul-Henning Kamp      <li><a href="#XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a></li>
1805bb6a25fSPoul-Henning Kamp      <li><a href="#XML_DefaultCurrent">XML_DefaultCurrent</a></li>
1815bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ExpatVersion">XML_ExpatVersion</a></li>
1825bb6a25fSPoul-Henning Kamp      <li><a href="#XML_ExpatVersionInfo">XML_ExpatVersionInfo</a></li>
1835bb6a25fSPoul-Henning Kamp      <li><a href="#XML_GetFeatureList">XML_GetFeatureList</a></li>
184220ed979SColeman Kane      <li><a href="#XML_FreeContentModel">XML_FreeContentModel</a></li>
185220ed979SColeman Kane      <li><a href="#XML_MemMalloc">XML_MemMalloc</a></li>
186220ed979SColeman Kane      <li><a href="#XML_MemRealloc">XML_MemRealloc</a></li>
187220ed979SColeman Kane      <li><a href="#XML_MemFree">XML_MemFree</a></li>
1885bb6a25fSPoul-Henning Kamp    </ul>
1895bb6a25fSPoul-Henning Kamp    </li>
1905bb6a25fSPoul-Henning Kamp  </ul>
1915bb6a25fSPoul-Henning Kamp  </li>
1925bb6a25fSPoul-Henning Kamp</ul>
1935bb6a25fSPoul-Henning Kamp
1945bb6a25fSPoul-Henning Kamp<hr />
1955bb6a25fSPoul-Henning Kamp<h2><a name="overview">Overview</a></h2>
1965bb6a25fSPoul-Henning Kamp
1975bb6a25fSPoul-Henning Kamp<p>Expat is a stream-oriented parser. You register callback (or
1985bb6a25fSPoul-Henning Kamphandler) functions with the parser and then start feeding it the
1995bb6a25fSPoul-Henning Kampdocument.  As the parser recognizes parts of the document, it will
2005bb6a25fSPoul-Henning Kampcall the appropriate handler for that part (if you've registered one.)
2015bb6a25fSPoul-Henning KampThe document is fed to the parser in pieces, so you can start parsing
2025bb6a25fSPoul-Henning Kampbefore you have all the document. This also allows you to parse really
2035bb6a25fSPoul-Henning Kamphuge documents that won't fit into memory.</p>
2045bb6a25fSPoul-Henning Kamp
2055bb6a25fSPoul-Henning Kamp<p>Expat can be intimidating due to the many kinds of handlers and
2065bb6a25fSPoul-Henning Kampoptions you can set. But you only need to learn four functions in
2075bb6a25fSPoul-Henning Kamporder to do 90% of what you'll want to do with it:</p>
2085bb6a25fSPoul-Henning Kamp
2095bb6a25fSPoul-Henning Kamp<dl>
2105bb6a25fSPoul-Henning Kamp
2115bb6a25fSPoul-Henning Kamp<dt><code><a href= "#XML_ParserCreate"
2125bb6a25fSPoul-Henning Kamp             >XML_ParserCreate</a></code></dt>
2135bb6a25fSPoul-Henning Kamp  <dd>Create a new parser object.</dd>
2145bb6a25fSPoul-Henning Kamp
2155bb6a25fSPoul-Henning Kamp<dt><code><a href= "#XML_SetElementHandler"
2165bb6a25fSPoul-Henning Kamp             >XML_SetElementHandler</a></code></dt>
2175bb6a25fSPoul-Henning Kamp  <dd>Set handlers for start and end tags.</dd>
2185bb6a25fSPoul-Henning Kamp
2195bb6a25fSPoul-Henning Kamp<dt><code><a href= "#XML_SetCharacterDataHandler"
2205bb6a25fSPoul-Henning Kamp             >XML_SetCharacterDataHandler</a></code></dt>
2215bb6a25fSPoul-Henning Kamp  <dd>Set handler for text.</dd>
2225bb6a25fSPoul-Henning Kamp
2235bb6a25fSPoul-Henning Kamp<dt><code><a href= "#XML_Parse"
2245bb6a25fSPoul-Henning Kamp             >XML_Parse</a></code></dt>
2255bb6a25fSPoul-Henning Kamp  <dd>Pass a buffer full of document to the parser</dd>
2265bb6a25fSPoul-Henning Kamp</dl>
2275bb6a25fSPoul-Henning Kamp
2285bb6a25fSPoul-Henning Kamp<p>These functions and others are described in the <a
2295bb6a25fSPoul-Henning Kamphref="#reference">reference</a> part of this document. The reference
2305bb6a25fSPoul-Henning Kampsection also describes in detail the parameters passed to the
2315bb6a25fSPoul-Henning Kampdifferent types of handlers.</p>
2325bb6a25fSPoul-Henning Kamp
2335bb6a25fSPoul-Henning Kamp<p>Let's look at a very simple example program that only uses 3 of the
2345bb6a25fSPoul-Henning Kampabove functions (it doesn't need to set a character handler.) The
2355bb6a25fSPoul-Henning Kampprogram <a href="../examples/outline.c">outline.c</a> prints an
2365bb6a25fSPoul-Henning Kampelement outline, indenting child elements to distinguish them from the
2375bb6a25fSPoul-Henning Kampparent element that contains them. The start handler does all the
2385bb6a25fSPoul-Henning Kampwork.  It prints two indenting spaces for every level of ancestor
2395bb6a25fSPoul-Henning Kampelements, then it prints the element and attribute
2405bb6a25fSPoul-Henning Kampinformation. Finally it increments the global <code>Depth</code>
2415bb6a25fSPoul-Henning Kampvariable.</p>
2425bb6a25fSPoul-Henning Kamp
2435bb6a25fSPoul-Henning Kamp<pre class="eg">
2445bb6a25fSPoul-Henning Kampint Depth;
2455bb6a25fSPoul-Henning Kamp
246220ed979SColeman Kanevoid XMLCALL
2475bb6a25fSPoul-Henning Kampstart(void *data, const char *el, const char **attr) {
2485bb6a25fSPoul-Henning Kamp  int i;
2495bb6a25fSPoul-Henning Kamp
2505bb6a25fSPoul-Henning Kamp  for (i = 0; i &lt; Depth; i++)
2515bb6a25fSPoul-Henning Kamp    printf("  ");
2525bb6a25fSPoul-Henning Kamp
2535bb6a25fSPoul-Henning Kamp  printf("%s", el);
2545bb6a25fSPoul-Henning Kamp
2555bb6a25fSPoul-Henning Kamp  for (i = 0; attr[i]; i += 2) {
2565bb6a25fSPoul-Henning Kamp    printf(" %s='%s'", attr[i], attr[i + 1]);
2575bb6a25fSPoul-Henning Kamp  }
2585bb6a25fSPoul-Henning Kamp
2595bb6a25fSPoul-Henning Kamp  printf("\n");
2605bb6a25fSPoul-Henning Kamp  Depth++;
2615bb6a25fSPoul-Henning Kamp}  /* End of start handler */
2625bb6a25fSPoul-Henning Kamp</pre>
2635bb6a25fSPoul-Henning Kamp
2645bb6a25fSPoul-Henning Kamp<p>The end tag simply does the bookkeeping work of decrementing
2655bb6a25fSPoul-Henning Kamp<code>Depth</code>.</p>
2665bb6a25fSPoul-Henning Kamp<pre class="eg">
267220ed979SColeman Kanevoid XMLCALL
2685bb6a25fSPoul-Henning Kampend(void *data, const char *el) {
2695bb6a25fSPoul-Henning Kamp  Depth--;
2705bb6a25fSPoul-Henning Kamp}  /* End of end handler */
2715bb6a25fSPoul-Henning Kamp</pre>
2725bb6a25fSPoul-Henning Kamp
273220ed979SColeman Kane<p>Note the <code>XMLCALL</code> annotation used for the callbacks.
274220ed979SColeman KaneThis is used to ensure that the Expat and the callbacks are using the
275220ed979SColeman Kanesame calling convention in case the compiler options used for Expat
276220ed979SColeman Kaneitself and the client code are different.  Expat tries not to care
277220ed979SColeman Kanewhat the default calling convention is, though it may require that it
278220ed979SColeman Kanebe compiled with a default convention of "cdecl" on some platforms.
279220ed979SColeman KaneFor code which uses Expat, however, the calling convention is
280220ed979SColeman Kanespecified by the <code>XMLCALL</code> annotation on most platforms;
281220ed979SColeman Kanecallbacks should be defined using this annotation.</p>
282220ed979SColeman Kane
283220ed979SColeman Kane<p>The <code>XMLCALL</code> annotation was added in Expat 1.95.7, but
284220ed979SColeman Kaneexisting working Expat applications don't need to add it (since they
285220ed979SColeman Kaneare already using the "cdecl" calling convention, or they wouldn't be
286220ed979SColeman Kaneworking).  The annotation is only needed if the default calling
287220ed979SColeman Kaneconvention may be something other than "cdecl".  To use the annotation
288220ed979SColeman Kanesafely with older versions of Expat, you can conditionally define it
289220ed979SColeman Kane<em>after</em> including Expat's header file:</p>
290220ed979SColeman Kane
291220ed979SColeman Kane<pre class="eg">
292220ed979SColeman Kane#include &lt;expat.h&gt;
293220ed979SColeman Kane
294220ed979SColeman Kane#ifndef XMLCALL
295220ed979SColeman Kane#if defined(_MSC_EXTENSIONS) &amp;&amp; !defined(__BEOS__) &amp;&amp; !defined(__CYGWIN__)
296220ed979SColeman Kane#define XMLCALL __cdecl
297220ed979SColeman Kane#elif defined(__GNUC__)
298220ed979SColeman Kane#define XMLCALL __attribute__((cdecl))
299220ed979SColeman Kane#else
300220ed979SColeman Kane#define XMLCALL
301220ed979SColeman Kane#endif
302220ed979SColeman Kane#endif
303220ed979SColeman Kane</pre>
304220ed979SColeman Kane
3055bb6a25fSPoul-Henning Kamp<p>After creating the parser, the main program just has the job of
3065bb6a25fSPoul-Henning Kampshoveling the document to the parser so that it can do its work.</p>
3075bb6a25fSPoul-Henning Kamp
3085bb6a25fSPoul-Henning Kamp<hr />
3095bb6a25fSPoul-Henning Kamp<h2><a name="building">Building and Installing Expat</a></h2>
3105bb6a25fSPoul-Henning Kamp
3115bb6a25fSPoul-Henning Kamp<p>The Expat distribution comes as a compressed (with GNU gzip) tar
3125bb6a25fSPoul-Henning Kampfile.  You may download the latest version from <a href=
3134543ef51SXin LI"https://sourceforge.net/projects/expat/" >Source Forge</a>.  After
3145bb6a25fSPoul-Henning Kampunpacking this, cd into the directory. Then follow either the Win32
3155bb6a25fSPoul-Henning Kampdirections or Unix directions below.</p>
3165bb6a25fSPoul-Henning Kamp
3175bb6a25fSPoul-Henning Kamp<h3>Building under Win32</h3>
3185bb6a25fSPoul-Henning Kamp
3195bb6a25fSPoul-Henning Kamp<p>If you're using the GNU compiler under cygwin, follow the Unix
3205bb6a25fSPoul-Henning Kampdirections in the next section. Otherwise if you have Microsoft's
3216b2c1e49SXin LIDeveloper Studio installed,
3226b2c1e49SXin LIyou can use CMake to generate a <code>.sln</code> file, e.g.
3236b2c1e49SXin LI<code>
324627b778dSXin LIcmake -G"Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=RelWithDebInfo .
3256b2c1e49SXin LI</code>, and build Expat using <code>msbuild /m expat.sln</code> after.</p>
3265bb6a25fSPoul-Henning Kamp
3275bb6a25fSPoul-Henning Kamp<p>Alternatively, you may download the Win32 binary package that
3285bb6a25fSPoul-Henning Kampcontains the "expat.h" include file and a pre-built DLL.</p>
3295bb6a25fSPoul-Henning Kamp
3305bb6a25fSPoul-Henning Kamp<h3>Building under Unix (or GNU)</h3>
3315bb6a25fSPoul-Henning Kamp
3325bb6a25fSPoul-Henning Kamp<p>First you'll need to run the configure shell script in order to
3335bb6a25fSPoul-Henning Kampconfigure the Makefiles and headers for your system.</p>
3345bb6a25fSPoul-Henning Kamp
3355bb6a25fSPoul-Henning Kamp<p>If you're happy with all the defaults that configure picks for you,
3365bb6a25fSPoul-Henning Kampand you have permission on your system to install into /usr/local, you
3375bb6a25fSPoul-Henning Kampcan install Expat with this sequence of commands:</p>
3385bb6a25fSPoul-Henning Kamp
3395bb6a25fSPoul-Henning Kamp<pre class="eg">
3405bb6a25fSPoul-Henning Kamp./configure
3415bb6a25fSPoul-Henning Kampmake
3425bb6a25fSPoul-Henning Kampmake install
3435bb6a25fSPoul-Henning Kamp</pre>
3445bb6a25fSPoul-Henning Kamp
3455bb6a25fSPoul-Henning Kamp<p>There are some options that you can provide to this script, but the
3465bb6a25fSPoul-Henning Kamponly one we'll mention here is the <code>--prefix</code> option. You
3475bb6a25fSPoul-Henning Kampcan find out all the options available by running configure with just
3485bb6a25fSPoul-Henning Kampthe <code>--help</code> option.</p>
3495bb6a25fSPoul-Henning Kamp
3505bb6a25fSPoul-Henning Kamp<p>By default, the configure script sets things up so that the library
3515bb6a25fSPoul-Henning Kampgets installed in <code>/usr/local/lib</code> and the associated
3525bb6a25fSPoul-Henning Kampheader file in <code>/usr/local/include</code>.  But if you were to
3535bb6a25fSPoul-Henning Kampgive the option, <code>--prefix=/home/me/mystuff</code>, then the
3545bb6a25fSPoul-Henning Kamplibrary and header would get installed in
3555bb6a25fSPoul-Henning Kamp<code>/home/me/mystuff/lib</code> and
3565bb6a25fSPoul-Henning Kamp<code>/home/me/mystuff/include</code> respectively.</p>
3575bb6a25fSPoul-Henning Kamp
358220ed979SColeman Kane<h3>Configuring Expat Using the Pre-Processor</h3>
359220ed979SColeman Kane
360220ed979SColeman Kane<p>Expat's feature set can be configured using a small number of
361ffd294a1SEnji Cooperpre-processor definitions.  The symbols are:</p>
362220ed979SColeman Kane
363220ed979SColeman Kane<dl class="cpp-symbols">
3644543ef51SXin LI<dt><a name="XML_GE">XML_GE</a></dt>
3654543ef51SXin LI<dd>
3664543ef51SXin LIAdded in Expat 2.6.0.
3674543ef51SXin LIInclude support for
3684543ef51SXin LI<a href="https://www.w3.org/TR/2006/REC-xml-20060816/#sec-physical-struct">general entities</a>
3694543ef51SXin LI(syntax <code>&amp;e1;</code> to reference and
3704543ef51SXin LIsyntax <code>&lt;!ENTITY e1 'value1'&gt;</code> (an internal general entity) or
3714543ef51SXin LI<code>&lt;!ENTITY e2 SYSTEM 'file2'&gt;</code> (an external general entity) to declare).
3724543ef51SXin LIWith <code>XML_GE</code> enabled, general entities will be replaced by their declared replacement text;
3734543ef51SXin LIfor this to work for <em>external</em> general entities, in addition an
3744543ef51SXin LI<code><a href="#XML_SetExternalEntityRefHandler">XML_ExternalEntityRefHandler</a></code> must be set using
3754543ef51SXin LI<code><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></code>.
3764543ef51SXin LIAlso, enabling <code>XML_GE</code> makes
3774543ef51SXin LIthe functions <code><a href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">
3784543ef51SXin LIXML_SetBillionLaughsAttackProtectionMaximumAmplification</a></code> and <code>
3794543ef51SXin LI<a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">
3804543ef51SXin LIXML_SetBillionLaughsAttackProtectionActivationThreshold</a></code> available.
3814543ef51SXin LI<br/>
3824543ef51SXin LIWith <code>XML_GE</code> disabled, Expat has a smaller memory footprint and can be faster, but will
3834543ef51SXin LInot load external general entities and will replace all general entities
3844543ef51SXin LI(except the <a href="https://www.w3.org/TR/2006/REC-xml-20060816/#sec-predefined-ent">predefined five</a>:
3854543ef51SXin LI<code>amp</code>, <code>apos</code>, <code>gt</code>, <code>lt</code>, <code>quot</code>)
3864543ef51SXin LIwith a self-reference:
3874543ef51SXin LIfor example, referencing an entity <code>e1</code> via <code>&amp;e1;</code> will be replaced
3884543ef51SXin LIby text <code>&amp;e1;</code>.
3894543ef51SXin LI</dd>
3904543ef51SXin LI
3914543ef51SXin LI<dt><a name="XML_DTD">XML_DTD</a></dt>
392220ed979SColeman Kane<dd>Include support for using and reporting DTD-based content.  If
393220ed979SColeman Kanethis is defined, default attribute values from an external DTD subset
394220ed979SColeman Kaneare reported and attribute value normalization occurs based on the
395220ed979SColeman Kanetype of attributes defined in the external subset.  Without
396220ed979SColeman Kanethis, Expat has a smaller memory footprint and can be faster, but will
3974543ef51SXin LInot load external parameter entities or process conditional sections. If defined, makes
39871f0c44aSXin LIthe functions <code><a
39971f0c44aSXin LIhref="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">
40071f0c44aSXin LIXML_SetBillionLaughsAttackProtectionMaximumAmplification</a></code> and <code>
40171f0c44aSXin LI<a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">
40271f0c44aSXin LIXML_SetBillionLaughsAttackProtectionActivationThreshold</a></code> available.</dd>
403220ed979SColeman Kane
4044543ef51SXin LI<dt><a name="XML_NS">XML_NS</a></dt>
405220ed979SColeman Kane<dd>When defined, support for the <cite><a href=
4064543ef51SXin LI"https://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite>
407220ed979SColeman Kanespecification is included.</dd>
408220ed979SColeman Kane
4094543ef51SXin LI<dt><a name="XML_UNICODE">XML_UNICODE</a></dt>
410220ed979SColeman Kane<dd>When defined, character data reported to the application is
411220ed979SColeman Kaneencoded in UTF-16 using wide characters of the type
412220ed979SColeman Kane<code>XML_Char</code>.  This is implied if
413220ed979SColeman Kane<code>XML_UNICODE_WCHAR_T</code> is defined.</dd>
414220ed979SColeman Kane
4154543ef51SXin LI<dt><a name="XML_UNICODE_WCHAR_T">XML_UNICODE_WCHAR_T</a></dt>
416220ed979SColeman Kane<dd>If defined, causes the <code>XML_Char</code> character type to be
417220ed979SColeman Kanedefined using the <code>wchar_t</code> type; otherwise, <code>unsigned
418220ed979SColeman Kaneshort</code> is used.  Defining this implies
419220ed979SColeman Kane<code>XML_UNICODE</code>.</dd>
420220ed979SColeman Kane
4214543ef51SXin LI<dt><a name="XML_LARGE_SIZE">XML_LARGE_SIZE</a></dt>
422220ed979SColeman Kane<dd>If defined, causes the <code>XML_Size</code> and <code>XML_Index</code>
423220ed979SColeman Kaneinteger types to be at least 64 bits in size. This is intended to support
424220ed979SColeman Kaneprocessing of very large input streams, where the return values of
425220ed979SColeman Kane<code><a href="#XML_GetCurrentByteIndex" >XML_GetCurrentByteIndex</a></code>,
426220ed979SColeman Kane<code><a href="#XML_GetCurrentLineNumber" >XML_GetCurrentLineNumber</a></code> and
427220ed979SColeman Kane<code><a href="#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>
428220ed979SColeman Kanecould overflow. It may not be supported by all compilers, and is turned
429220ed979SColeman Kaneoff by default.</dd>
430220ed979SColeman Kane
4314543ef51SXin LI<dt><a name="XML_CONTEXT_BYTES">XML_CONTEXT_BYTES</a></dt>
432220ed979SColeman Kane<dd>The number of input bytes of markup context which the parser will
433220ed979SColeman Kaneensure are available for reporting via <code><a href=
434220ed979SColeman Kane"#XML_GetInputContext" >XML_GetInputContext</a></code>.  This is
4354543ef51SXin LInormally set to 1024, and must be set to a positive integer to enable.
4364543ef51SXin LIIf this is set to zero, the input context will not be available and <code><a
437220ed979SColeman Kanehref= "#XML_GetInputContext" >XML_GetInputContext</a></code> will
4384543ef51SXin LIalways report <code>NULL</code>.  Without this, Expat has a smaller memory
439220ed979SColeman Kanefootprint and can be faster.</dd>
440220ed979SColeman Kane
4414543ef51SXin LI<dt><a name="XML_STATIC">XML_STATIC</a></dt>
442220ed979SColeman Kane<dd>On Windows, this should be set if Expat is going to be linked
443220ed979SColeman Kanestatically with the code that calls it; this is required to get all
444220ed979SColeman Kanethe right MSVC magic annotations correct.  This is ignored on other
445220ed979SColeman Kaneplatforms.</dd>
446e3466a89SXin LI
4474543ef51SXin LI<dt><a name="XML_ATTR_INFO">XML_ATTR_INFO</a></dt>
4480a48773fSEric van Gyzen<dd>If defined, makes the additional function <code><a href=
449e3466a89SXin LI"#XML_GetAttributeInfo" >XML_GetAttributeInfo</a></code> available
450e3466a89SXin LIfor reporting attribute byte offsets.</dd>
451220ed979SColeman Kane</dl>
452220ed979SColeman Kane
4535bb6a25fSPoul-Henning Kamp<hr />
4545bb6a25fSPoul-Henning Kamp<h2><a name="using">Using Expat</a></h2>
4555bb6a25fSPoul-Henning Kamp
4565bb6a25fSPoul-Henning Kamp<h3>Compiling and Linking Against Expat</h3>
4575bb6a25fSPoul-Henning Kamp
4585bb6a25fSPoul-Henning Kamp<p>Unless you installed Expat in a location not expected by your
4595bb6a25fSPoul-Henning Kampcompiler and linker, all you have to do to use Expat in your programs
4605bb6a25fSPoul-Henning Kampis to include the Expat header (<code>#include &lt;expat.h&gt;</code>)
4615bb6a25fSPoul-Henning Kampin your files that make calls to it and to tell the linker that it
4625bb6a25fSPoul-Henning Kampneeds to link against the Expat library.  On Unix systems, this would
4635bb6a25fSPoul-Henning Kampusually be done with the <code>-lexpat</code> argument.  Otherwise,
4645bb6a25fSPoul-Henning Kampyou'll need to tell the compiler where to look for the Expat header
4655bb6a25fSPoul-Henning Kampand the linker where to find the Expat library.  You may also need to
466220ed979SColeman Kanetake steps to tell the operating system where to find this library at
4675bb6a25fSPoul-Henning Kamprun time.</p>
4685bb6a25fSPoul-Henning Kamp
4695bb6a25fSPoul-Henning Kamp<p>On a Unix-based system, here's what a Makefile might look like when
4705bb6a25fSPoul-Henning KampExpat is installed in a standard location:</p>
4715bb6a25fSPoul-Henning Kamp
4725bb6a25fSPoul-Henning Kamp<pre class="eg">
4735bb6a25fSPoul-Henning KampCC=cc
4745bb6a25fSPoul-Henning KampLDFLAGS=
4755bb6a25fSPoul-Henning KampLIBS= -lexpat
4765bb6a25fSPoul-Henning Kampxmlapp: xmlapp.o
4775bb6a25fSPoul-Henning Kamp        $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
4785bb6a25fSPoul-Henning Kamp</pre>
4795bb6a25fSPoul-Henning Kamp
4805bb6a25fSPoul-Henning Kamp<p>If you installed Expat in, say, <code>/home/me/mystuff</code>, then
4815bb6a25fSPoul-Henning Kampthe Makefile would look like this:</p>
4825bb6a25fSPoul-Henning Kamp
4835bb6a25fSPoul-Henning Kamp<pre class="eg">
4845bb6a25fSPoul-Henning KampCC=cc
4855bb6a25fSPoul-Henning KampCFLAGS= -I/home/me/mystuff/include
4865bb6a25fSPoul-Henning KampLDFLAGS=
4875bb6a25fSPoul-Henning KampLIBS= -L/home/me/mystuff/lib -lexpat
4885bb6a25fSPoul-Henning Kampxmlapp: xmlapp.o
4895bb6a25fSPoul-Henning Kamp        $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
4905bb6a25fSPoul-Henning Kamp</pre>
4915bb6a25fSPoul-Henning Kamp
4925bb6a25fSPoul-Henning Kamp<p>You'd also have to set the environment variable
4935bb6a25fSPoul-Henning Kamp<code>LD_LIBRARY_PATH</code> to <code>/home/me/mystuff/lib</code> (or
4945bb6a25fSPoul-Henning Kampto <code>${LD_LIBRARY_PATH}:/home/me/mystuff/lib</code> if
4955bb6a25fSPoul-Henning KampLD_LIBRARY_PATH already has some directories in it) in order to run
4965bb6a25fSPoul-Henning Kampyour application.</p>
4975bb6a25fSPoul-Henning Kamp
4985bb6a25fSPoul-Henning Kamp<h3>Expat Basics</h3>
4995bb6a25fSPoul-Henning Kamp
5005bb6a25fSPoul-Henning Kamp<p>As we saw in the example in the overview, the first step in parsing
5015bb6a25fSPoul-Henning Kampan XML document with Expat is to create a parser object. There are <a
5025bb6a25fSPoul-Henning Kamphref="#creation">three functions</a> in the Expat API for creating a
5035bb6a25fSPoul-Henning Kampparser object.  However, only two of these (<code><a href=
5045bb6a25fSPoul-Henning Kamp"#XML_ParserCreate" >XML_ParserCreate</a></code> and <code><a href=
5055bb6a25fSPoul-Henning Kamp"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>) can be used for
5065bb6a25fSPoul-Henning Kampconstructing a parser for a top-level document.  The object returned
5075bb6a25fSPoul-Henning Kampby these functions is an opaque pointer (i.e. "expat.h" declares it as
5085bb6a25fSPoul-Henning Kampvoid *) to data with further internal structure. In order to free the
5095bb6a25fSPoul-Henning Kampmemory associated with this object you must call <code><a href=
5105bb6a25fSPoul-Henning Kamp"#XML_ParserFree" >XML_ParserFree</a></code>. Note that if you have
511220ed979SColeman Kaneprovided any <a href="#userdata">user data</a> that gets stored in the
5125bb6a25fSPoul-Henning Kampparser, then your application is responsible for freeing it prior to
5135bb6a25fSPoul-Henning Kampcalling <code>XML_ParserFree</code>.</p>
5145bb6a25fSPoul-Henning Kamp
5155bb6a25fSPoul-Henning Kamp<p>The objects returned by the parser creation functions are good for
5165bb6a25fSPoul-Henning Kampparsing only one XML document or external parsed entity. If your
5175bb6a25fSPoul-Henning Kampapplication needs to parse many XML documents, then it needs to create
5185bb6a25fSPoul-Henning Kampa parser object for each one. The best way to deal with this is to
5195bb6a25fSPoul-Henning Kampcreate a higher level object that contains all the default
5205bb6a25fSPoul-Henning Kampinitialization you want for your parser objects.</p>
5215bb6a25fSPoul-Henning Kamp
5225bb6a25fSPoul-Henning Kamp<p>Walking through a document hierarchy with a stream oriented parser
5235bb6a25fSPoul-Henning Kampwill require a good stack mechanism in order to keep track of current
5245bb6a25fSPoul-Henning Kampcontext.  For instance, to answer the simple question, "What element
5255bb6a25fSPoul-Henning Kampdoes this text belong to?" requires a stack, since the parser may have
5265bb6a25fSPoul-Henning Kampdescended into other elements that are children of the current one and
5275bb6a25fSPoul-Henning Kamphas encountered this text on the way out.</p>
5285bb6a25fSPoul-Henning Kamp
5295bb6a25fSPoul-Henning Kamp<p>The things you're likely to want to keep on a stack are the
5305bb6a25fSPoul-Henning Kampcurrently opened element and it's attributes. You push this
5315bb6a25fSPoul-Henning Kampinformation onto the stack in the start handler and you pop it off in
5325bb6a25fSPoul-Henning Kampthe end handler.</p>
5335bb6a25fSPoul-Henning Kamp
5345bb6a25fSPoul-Henning Kamp<p>For some tasks, it is sufficient to just keep information on what
5355bb6a25fSPoul-Henning Kampthe depth of the stack is (or would be if you had one.) The outline
5365bb6a25fSPoul-Henning Kampprogram shown above presents one example. Another such task would be
5375bb6a25fSPoul-Henning Kampskipping over a complete element. When you see the start tag for the
5385bb6a25fSPoul-Henning Kampelement you want to skip, you set a skip flag and record the depth at
5395bb6a25fSPoul-Henning Kampwhich the element started.  When the end tag handler encounters the
5405bb6a25fSPoul-Henning Kampsame depth, the skipped element has ended and the flag may be
5415bb6a25fSPoul-Henning Kampcleared. If you follow the convention that the root element starts at
5425bb6a25fSPoul-Henning Kamp1, then you can use the same variable for skip flag and skip
5435bb6a25fSPoul-Henning Kampdepth.</p>
5445bb6a25fSPoul-Henning Kamp
5455bb6a25fSPoul-Henning Kamp<pre class="eg">
5465bb6a25fSPoul-Henning Kampvoid
5475bb6a25fSPoul-Henning Kampinit_info(Parseinfo *info) {
5485bb6a25fSPoul-Henning Kamp  info->skip = 0;
5495bb6a25fSPoul-Henning Kamp  info->depth = 1;
5505bb6a25fSPoul-Henning Kamp  /* Other initializations here */
5515bb6a25fSPoul-Henning Kamp}  /* End of init_info */
5525bb6a25fSPoul-Henning Kamp
553220ed979SColeman Kanevoid XMLCALL
5545bb6a25fSPoul-Henning Kamprawstart(void *data, const char *el, const char **attr) {
5555bb6a25fSPoul-Henning Kamp  Parseinfo *inf = (Parseinfo *) data;
5565bb6a25fSPoul-Henning Kamp
5575bb6a25fSPoul-Henning Kamp  if (! inf->skip) {
5585bb6a25fSPoul-Henning Kamp    if (should_skip(inf, el, attr)) {
5595bb6a25fSPoul-Henning Kamp      inf->skip = inf->depth;
5605bb6a25fSPoul-Henning Kamp    }
5615bb6a25fSPoul-Henning Kamp    else
5625bb6a25fSPoul-Henning Kamp      start(inf, el, attr);     /* This does rest of start handling */
5635bb6a25fSPoul-Henning Kamp  }
5645bb6a25fSPoul-Henning Kamp
5655bb6a25fSPoul-Henning Kamp  inf->depth++;
5665bb6a25fSPoul-Henning Kamp}  /* End of rawstart */
5675bb6a25fSPoul-Henning Kamp
568220ed979SColeman Kanevoid XMLCALL
5695bb6a25fSPoul-Henning Kamprawend(void *data, const char *el) {
5705bb6a25fSPoul-Henning Kamp  Parseinfo *inf = (Parseinfo *) data;
5715bb6a25fSPoul-Henning Kamp
5725bb6a25fSPoul-Henning Kamp  inf->depth--;
5735bb6a25fSPoul-Henning Kamp
5745bb6a25fSPoul-Henning Kamp  if (! inf->skip)
5755bb6a25fSPoul-Henning Kamp    end(inf, el);              /* This does rest of end handling */
5765bb6a25fSPoul-Henning Kamp
5775bb6a25fSPoul-Henning Kamp  if (inf->skip == inf->depth)
5785bb6a25fSPoul-Henning Kamp    inf->skip = 0;
5795bb6a25fSPoul-Henning Kamp}  /* End rawend */
5805bb6a25fSPoul-Henning Kamp</pre>
5815bb6a25fSPoul-Henning Kamp
5825bb6a25fSPoul-Henning Kamp<p>Notice in the above example the difference in how depth is
5835bb6a25fSPoul-Henning Kampmanipulated in the start and end handlers. The end tag handler should
5845bb6a25fSPoul-Henning Kampbe the mirror image of the start tag handler. This is necessary to
5855bb6a25fSPoul-Henning Kampproperly model containment. Since, in the start tag handler, we
5865bb6a25fSPoul-Henning Kampincremented depth <em>after</em> the main body of start tag code, then
5875bb6a25fSPoul-Henning Kampin the end handler, we need to manipulate it <em>before</em> the main
5885bb6a25fSPoul-Henning Kampbody.  If we'd decided to increment it first thing in the start
5895bb6a25fSPoul-Henning Kamphandler, then we'd have had to decrement it last thing in the end
5905bb6a25fSPoul-Henning Kamphandler.</p>
5915bb6a25fSPoul-Henning Kamp
5925bb6a25fSPoul-Henning Kamp<h3 id="userdata">Communicating between handlers</h3>
5935bb6a25fSPoul-Henning Kamp
5945bb6a25fSPoul-Henning Kamp<p>In order to be able to pass information between different handlers
5955bb6a25fSPoul-Henning Kampwithout using globals, you'll need to define a data structure to hold
5965bb6a25fSPoul-Henning Kampthe shared variables. You can then tell Expat (with the <code><a href=
5975bb6a25fSPoul-Henning Kamp"#XML_SetUserData" >XML_SetUserData</a></code> function) to pass a
598220ed979SColeman Kanepointer to this structure to the handlers.  This is the first
599220ed979SColeman Kaneargument received by most handlers.  In the <a href="#reference"
600220ed979SColeman Kane>reference section</a>, an argument to a callback function is named
601220ed979SColeman Kane<code>userData</code> and have type <code>void *</code> if the user
602220ed979SColeman Kanedata is passed; it will have the type <code>XML_Parser</code> if the
603220ed979SColeman Kaneparser itself is passed.  When the parser is passed, the user data may
604220ed979SColeman Kanebe retrieved using <code><a href="#XML_GetUserData"
605220ed979SColeman Kane>XML_GetUserData</a></code>.</p>
606220ed979SColeman Kane
607220ed979SColeman Kane<p>One common case where multiple calls to a single handler may need
608220ed979SColeman Kaneto communicate using an application data structure is the case when
609220ed979SColeman Kanecontent passed to the character data handler (set by <code><a href=
610220ed979SColeman Kane"#XML_SetCharacterDataHandler"
611220ed979SColeman Kane>XML_SetCharacterDataHandler</a></code>) needs to be accumulated.  A
612220ed979SColeman Kanecommon first-time mistake with any of the event-oriented interfaces to
613220ed979SColeman Kanean XML parser is to expect all the text contained in an element to be
614220ed979SColeman Kanereported by a single call to the character data handler.  Expat, like
615220ed979SColeman Kanemany other XML parsers, reports such data as a sequence of calls;
616220ed979SColeman Kanethere's no way to know when the end of the sequence is reached until a
617220ed979SColeman Kanedifferent callback is made.  A buffer referenced by the user data
618220ed979SColeman Kanestructure proves both an effective and convenient place to accumulate
619220ed979SColeman Kanecharacter data.</p>
620220ed979SColeman Kane
621220ed979SColeman Kane<!-- XXX example needed here -->
622220ed979SColeman Kane
6235bb6a25fSPoul-Henning Kamp
6245bb6a25fSPoul-Henning Kamp<h3>XML Version</h3>
6255bb6a25fSPoul-Henning Kamp
6265bb6a25fSPoul-Henning Kamp<p>Expat is an XML 1.0 parser, and as such never complains based on
6275bb6a25fSPoul-Henning Kampthe value of the <code>version</code> pseudo-attribute in the XML
6285bb6a25fSPoul-Henning Kampdeclaration, if present.</p>
6295bb6a25fSPoul-Henning Kamp
6305bb6a25fSPoul-Henning Kamp<p>If an application needs to check the version number (to support
6315bb6a25fSPoul-Henning Kampalternate processing), it should use the <code><a href=
6325bb6a25fSPoul-Henning Kamp"#XML_SetXmlDeclHandler" >XML_SetXmlDeclHandler</a></code> function to
6335bb6a25fSPoul-Henning Kampset a handler that uses the information in the XML declaration to
6345bb6a25fSPoul-Henning Kampdetermine what to do.  This example shows how to check that only a
6355bb6a25fSPoul-Henning Kampversion number of <code>"1.0"</code> is accepted:</p>
6365bb6a25fSPoul-Henning Kamp
6375bb6a25fSPoul-Henning Kamp<pre class="eg">
6385bb6a25fSPoul-Henning Kampstatic int wrong_version;
6395bb6a25fSPoul-Henning Kampstatic XML_Parser parser;
6405bb6a25fSPoul-Henning Kamp
641220ed979SColeman Kanestatic void XMLCALL
6425bb6a25fSPoul-Henning Kampxmldecl_handler(void            *userData,
6435bb6a25fSPoul-Henning Kamp                const XML_Char  *version,
6445bb6a25fSPoul-Henning Kamp                const XML_Char  *encoding,
6455bb6a25fSPoul-Henning Kamp                int              standalone)
6465bb6a25fSPoul-Henning Kamp{
6475bb6a25fSPoul-Henning Kamp  static const XML_Char Version_1_0[] = {'1', '.', '0', 0};
6485bb6a25fSPoul-Henning Kamp
6495bb6a25fSPoul-Henning Kamp  int i;
6505bb6a25fSPoul-Henning Kamp
6515bb6a25fSPoul-Henning Kamp  for (i = 0; i &lt; (sizeof(Version_1_0) / sizeof(Version_1_0[0])); ++i) {
6525bb6a25fSPoul-Henning Kamp    if (version[i] != Version_1_0[i]) {
6535bb6a25fSPoul-Henning Kamp      wrong_version = 1;
6545bb6a25fSPoul-Henning Kamp      /* also clear all other handlers: */
6555bb6a25fSPoul-Henning Kamp      XML_SetCharacterDataHandler(parser, NULL);
6565bb6a25fSPoul-Henning Kamp      ...
6575bb6a25fSPoul-Henning Kamp      return;
6585bb6a25fSPoul-Henning Kamp    }
6595bb6a25fSPoul-Henning Kamp  }
6605bb6a25fSPoul-Henning Kamp  ...
6615bb6a25fSPoul-Henning Kamp}
6625bb6a25fSPoul-Henning Kamp</pre>
6635bb6a25fSPoul-Henning Kamp
6645bb6a25fSPoul-Henning Kamp<h3>Namespace Processing</h3>
6655bb6a25fSPoul-Henning Kamp
6665bb6a25fSPoul-Henning Kamp<p>When the parser is created using the <code><a href=
6675bb6a25fSPoul-Henning Kamp"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>, function, Expat
6685bb6a25fSPoul-Henning Kampperforms namespace processing. Under namespace processing, Expat
6695bb6a25fSPoul-Henning Kampconsumes <code>xmlns</code> and <code>xmlns:...</code> attributes,
6705bb6a25fSPoul-Henning Kampwhich declare namespaces for the scope of the element in which they
6715bb6a25fSPoul-Henning Kampoccur. This means that your start handler will not see these
6725bb6a25fSPoul-Henning Kampattributes.  Your application can still be informed of these
6735bb6a25fSPoul-Henning Kampdeclarations by setting namespace declaration handlers with <a href=
6745bb6a25fSPoul-Henning Kamp"#XML_SetNamespaceDeclHandler"
6755bb6a25fSPoul-Henning Kamp><code>XML_SetNamespaceDeclHandler</code></a>.</p>
6765bb6a25fSPoul-Henning Kamp
6775bb6a25fSPoul-Henning Kamp<p>Element type and attribute names that belong to a given namespace
6785bb6a25fSPoul-Henning Kampare passed to the appropriate handler in expanded form. By default
6795bb6a25fSPoul-Henning Kampthis expanded form is a concatenation of the namespace URI, the
6805bb6a25fSPoul-Henning Kampseparator character (which is the 2nd argument to <code><a href=
6815bb6a25fSPoul-Henning Kamp"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>), and the local
6825bb6a25fSPoul-Henning Kampname (i.e. the part after the colon). Names with undeclared prefixes
683220ed979SColeman Kaneare not well-formed when namespace processing is enabled, and will
684220ed979SColeman Kanetrigger an error. Unprefixed attribute names are never expanded,
6855bb6a25fSPoul-Henning Kampand unprefixed element names are only expanded when they are in the
6865bb6a25fSPoul-Henning Kampscope of a default namespace.</p>
6875bb6a25fSPoul-Henning Kamp
688220ed979SColeman Kane<p>However if <code><a href= "#XML_SetReturnNSTriplet"
6895bb6a25fSPoul-Henning Kamp>XML_SetReturnNSTriplet</a></code> has been called with a non-zero
6905bb6a25fSPoul-Henning Kamp<code>do_nst</code> parameter, then the expanded form for names with
6915bb6a25fSPoul-Henning Kampan explicit prefix is a concatenation of: URI, separator, local name,
6925bb6a25fSPoul-Henning Kampseparator, prefix.</p>
6935bb6a25fSPoul-Henning Kamp
6945bb6a25fSPoul-Henning Kamp<p>You can set handlers for the start of a namespace declaration and
6955bb6a25fSPoul-Henning Kampfor the end of a scope of a declaration with the <code><a href=
6965bb6a25fSPoul-Henning Kamp"#XML_SetNamespaceDeclHandler" >XML_SetNamespaceDeclHandler</a></code>
6975bb6a25fSPoul-Henning Kampfunction.  The StartNamespaceDeclHandler is called prior to the start
698220ed979SColeman Kanetag handler and the EndNamespaceDeclHandler is called after the
6995bb6a25fSPoul-Henning Kampcorresponding end tag that ends the namespace's scope.  The namespace
7005bb6a25fSPoul-Henning Kampstart handler gets passed the prefix and URI for the namespace.  For a
7014543ef51SXin LIdefault namespace declaration (xmlns='...'), the prefix will be
7024543ef51SXin LI<code>NULL</code>.
7034543ef51SXin LIThe URI will be <code>NULL</code> for the case where the default namespace is being
7045bb6a25fSPoul-Henning Kampunset.  The namespace end handler just gets the prefix for the closing
7055bb6a25fSPoul-Henning Kampscope.</p>
7065bb6a25fSPoul-Henning Kamp
7075bb6a25fSPoul-Henning Kamp<p>These handlers are called for each declaration. So if, for
7085bb6a25fSPoul-Henning Kampinstance, a start tag had three namespace declarations, then the
7095bb6a25fSPoul-Henning KampStartNamespaceDeclHandler would be called three times before the start
7105bb6a25fSPoul-Henning Kamptag handler is called, once for each declaration.</p>
7115bb6a25fSPoul-Henning Kamp
7125bb6a25fSPoul-Henning Kamp<h3>Character Encodings</h3>
7135bb6a25fSPoul-Henning Kamp
7145bb6a25fSPoul-Henning Kamp<p>While XML is based on Unicode, and every XML processor is required
7155bb6a25fSPoul-Henning Kampto recognized UTF-8 and UTF-16 (1 and 2 byte encodings of Unicode),
7165bb6a25fSPoul-Henning Kampother encodings may be declared in XML documents or entities. For the
7175bb6a25fSPoul-Henning Kampmain document, an XML declaration may contain an encoding
7185bb6a25fSPoul-Henning Kampdeclaration:</p>
7195bb6a25fSPoul-Henning Kamp<pre>
7205bb6a25fSPoul-Henning Kamp&lt;?xml version="1.0" encoding="ISO-8859-2"?&gt;
7215bb6a25fSPoul-Henning Kamp</pre>
7225bb6a25fSPoul-Henning Kamp
7235bb6a25fSPoul-Henning Kamp<p>External parsed entities may begin with a text declaration, which
7245bb6a25fSPoul-Henning Kamplooks like an XML declaration with just an encoding declaration:</p>
7255bb6a25fSPoul-Henning Kamp<pre>
7265bb6a25fSPoul-Henning Kamp&lt;?xml encoding="Big5"?&gt;
7275bb6a25fSPoul-Henning Kamp</pre>
7285bb6a25fSPoul-Henning Kamp
7295bb6a25fSPoul-Henning Kamp<p>With Expat, you may also specify an encoding at the time of
7305bb6a25fSPoul-Henning Kampcreating a parser. This is useful when the encoding information may
7315bb6a25fSPoul-Henning Kampcome from a source outside the document itself (like a higher level
7325bb6a25fSPoul-Henning Kampprotocol.)</p>
7335bb6a25fSPoul-Henning Kamp
7345bb6a25fSPoul-Henning Kamp<p><a name="builtin_encodings"></a>There are four built-in encodings
7355bb6a25fSPoul-Henning Kampin Expat:</p>
7365bb6a25fSPoul-Henning Kamp<ul>
7375bb6a25fSPoul-Henning Kamp<li>UTF-8</li>
7385bb6a25fSPoul-Henning Kamp<li>UTF-16</li>
7395bb6a25fSPoul-Henning Kamp<li>ISO-8859-1</li>
7405bb6a25fSPoul-Henning Kamp<li>US-ASCII</li>
7415bb6a25fSPoul-Henning Kamp</ul>
7425bb6a25fSPoul-Henning Kamp
7435bb6a25fSPoul-Henning Kamp<p>Anything else discovered in an encoding declaration or in the
7445bb6a25fSPoul-Henning Kampprotocol encoding specified in the parser constructor, triggers a call
7455bb6a25fSPoul-Henning Kampto the <code>UnknownEncodingHandler</code>. This handler gets passed
7465bb6a25fSPoul-Henning Kampthe encoding name and a pointer to an <code>XML_Encoding</code> data
747220ed979SColeman Kanestructure. Your handler must fill in this structure and return
748220ed979SColeman Kane<code>XML_STATUS_OK</code> if it knows how to deal with the
749220ed979SColeman Kaneencoding. Otherwise the handler should return
750220ed979SColeman Kane<code>XML_STATUS_ERROR</code>.  The handler also gets passed a pointer
751220ed979SColeman Kaneto an optional application data structure that you may indicate when
752220ed979SColeman Kaneyou set the handler.</p>
7535bb6a25fSPoul-Henning Kamp
7545bb6a25fSPoul-Henning Kamp<p>Expat places restrictions on character encodings that it can
7555bb6a25fSPoul-Henning Kampsupport by filling in the <code>XML_Encoding</code> structure.
7565bb6a25fSPoul-Henning Kampinclude file:</p>
7575bb6a25fSPoul-Henning Kamp<ol>
7585bb6a25fSPoul-Henning Kamp<li>Every ASCII character that can appear in a well-formed XML document
7595bb6a25fSPoul-Henning Kampmust be represented by a single byte, and that byte must correspond to
7605bb6a25fSPoul-Henning Kampit's ASCII encoding (except for the characters $@\^'{}~)</li>
7615bb6a25fSPoul-Henning Kamp<li>Characters must be encoded in 4 bytes or less.</li>
7625bb6a25fSPoul-Henning Kamp<li>All characters encoded must have Unicode scalar values less than or
7635bb6a25fSPoul-Henning Kampequal to 65535 (0xFFFF)<em>This does not apply to the built-in support
7645bb6a25fSPoul-Henning Kampfor UTF-16 and UTF-8</em></li>
7655bb6a25fSPoul-Henning Kamp<li>No character may be encoded by more that one distinct sequence of
7665bb6a25fSPoul-Henning Kampbytes</li>
7675bb6a25fSPoul-Henning Kamp</ol>
7685bb6a25fSPoul-Henning Kamp
7695bb6a25fSPoul-Henning Kamp<p><code>XML_Encoding</code> contains an array of integers that
7705bb6a25fSPoul-Henning Kampcorrespond to the 1st byte of an encoding sequence. If the value in
7715bb6a25fSPoul-Henning Kampthe array for a byte is zero or positive, then the byte is a single
7725bb6a25fSPoul-Henning Kampbyte encoding that encodes the Unicode scalar value contained in the
7735bb6a25fSPoul-Henning Kamparray. A -1 in this array indicates a malformed byte. If the value is
7745bb6a25fSPoul-Henning Kamp-2, -3, or -4, then the byte is the beginning of a 2, 3, or 4 byte
7755bb6a25fSPoul-Henning Kampsequence respectively. Multi-byte sequences are sent to the convert
7765bb6a25fSPoul-Henning Kampfunction pointed at in the <code>XML_Encoding</code> structure. This
7775bb6a25fSPoul-Henning Kampfunction should return the Unicode scalar value for the sequence or -1
7785bb6a25fSPoul-Henning Kampif the sequence is malformed.</p>
7795bb6a25fSPoul-Henning Kamp
7805bb6a25fSPoul-Henning Kamp<p>One pitfall that novice Expat users are likely to fall into is that
7815bb6a25fSPoul-Henning Kampalthough Expat may accept input in various encodings, the strings that
7825bb6a25fSPoul-Henning Kampit passes to the handlers are always encoded in UTF-8 or UTF-16
7835bb6a25fSPoul-Henning Kamp(depending on how Expat was compiled). Your application is responsible
7845bb6a25fSPoul-Henning Kampfor any translation of these strings into other encodings.</p>
7855bb6a25fSPoul-Henning Kamp
7865bb6a25fSPoul-Henning Kamp<h3>Handling External Entity References</h3>
7875bb6a25fSPoul-Henning Kamp
7885bb6a25fSPoul-Henning Kamp<p>Expat does not read or parse external entities directly. Note that
7895bb6a25fSPoul-Henning Kampany external DTD is a special case of an external entity.  If you've
7905bb6a25fSPoul-Henning Kampset no <code>ExternalEntityRefHandler</code>, then external entity
7915bb6a25fSPoul-Henning Kampreferences are silently ignored. Otherwise, it calls your handler with
7925bb6a25fSPoul-Henning Kampthe information needed to read and parse the external entity.</p>
7935bb6a25fSPoul-Henning Kamp
7945bb6a25fSPoul-Henning Kamp<p>Your handler isn't actually responsible for parsing the entity, but
7955bb6a25fSPoul-Henning Kampit is responsible for creating a subsidiary parser with <code><a href=
7965bb6a25fSPoul-Henning Kamp"#XML_ExternalEntityParserCreate"
7975bb6a25fSPoul-Henning Kamp>XML_ExternalEntityParserCreate</a></code> that will do the job. This
7985bb6a25fSPoul-Henning Kampreturns an instance of <code>XML_Parser</code> that has handlers and
7995bb6a25fSPoul-Henning Kampother data structures initialized from the parent parser. You may then
8005bb6a25fSPoul-Henning Kampuse <code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a
8015bb6a25fSPoul-Henning Kamphref= "#XML_ParseBuffer">XML_ParseBuffer</a></code> calls against this
8025bb6a25fSPoul-Henning Kampparser.  Since external entities my refer to other external entities,
8035bb6a25fSPoul-Henning Kampyour handler should be prepared to be called recursively.</p>
8045bb6a25fSPoul-Henning Kamp
8055bb6a25fSPoul-Henning Kamp<h3>Parsing DTDs</h3>
8065bb6a25fSPoul-Henning Kamp
8075bb6a25fSPoul-Henning Kamp<p>In order to parse parameter entities, before starting the parse,
8085bb6a25fSPoul-Henning Kampyou must call <code><a href= "#XML_SetParamEntityParsing"
8095bb6a25fSPoul-Henning Kamp>XML_SetParamEntityParsing</a></code> with one of the following
8105bb6a25fSPoul-Henning Kamparguments:</p>
8115bb6a25fSPoul-Henning Kamp<dl>
8125bb6a25fSPoul-Henning Kamp<dt><code>XML_PARAM_ENTITY_PARSING_NEVER</code></dt>
8135bb6a25fSPoul-Henning Kamp<dd>Don't parse parameter entities or the external subset</dd>
8145bb6a25fSPoul-Henning Kamp<dt><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></dt>
8150a48773fSEric van Gyzen<dd>Parse parameter entities and the external subset unless
8165bb6a25fSPoul-Henning Kamp<code>standalone</code> was set to "yes" in the XML declaration.</dd>
8175bb6a25fSPoul-Henning Kamp<dt><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></dt>
8185bb6a25fSPoul-Henning Kamp<dd>Always parse parameter entities and the external subset</dd>
8195bb6a25fSPoul-Henning Kamp</dl>
8205bb6a25fSPoul-Henning Kamp
8215bb6a25fSPoul-Henning Kamp<p>In order to read an external DTD, you also have to set an external
8225bb6a25fSPoul-Henning Kampentity reference handler as described above.</p>
8235bb6a25fSPoul-Henning Kamp
824220ed979SColeman Kane<h3 id="stop-resume">Temporarily Stopping Parsing</h3>
825220ed979SColeman Kane
826220ed979SColeman Kane<p>Expat 1.95.8 introduces a new feature: its now possible to stop
827220ed979SColeman Kaneparsing temporarily from within a handler function, even if more data
828220ed979SColeman Kanehas already been passed into the parser.  Applications for this
829220ed979SColeman Kaneinclude</p>
830220ed979SColeman Kane
831220ed979SColeman Kane<ul>
8324543ef51SXin LI  <li>Supporting the <a href= "https://www.w3.org/TR/xinclude/"
833220ed979SColeman Kane  >XInclude</a> specification.</li>
834220ed979SColeman Kane
835220ed979SColeman Kane  <li>Delaying further processing until additional information is
836220ed979SColeman Kane  available from some other source.</li>
837220ed979SColeman Kane
838220ed979SColeman Kane  <li>Adjusting processor load as task priorities shift within an
839220ed979SColeman Kane  application.</li>
840220ed979SColeman Kane
841220ed979SColeman Kane  <li>Stopping parsing completely (simply free or reset the parser
842220ed979SColeman Kane  instead of resuming in the outer parsing loop).  This can be useful
8430a48773fSEric van Gyzen  if an application-domain error is found in the XML being parsed or if
844220ed979SColeman Kane  the result of the parse is determined not to be useful after
845220ed979SColeman Kane  all.</li>
846220ed979SColeman Kane</ul>
847220ed979SColeman Kane
848220ed979SColeman Kane<p>To take advantage of this feature, the main parsing loop of an
849220ed979SColeman Kaneapplication needs to support this specifically.  It cannot be
850220ed979SColeman Kanesupported with a parsing loop compatible with Expat 1.95.7 or
851220ed979SColeman Kaneearlier (though existing loops will continue to work without
852220ed979SColeman Kanesupporting the stop/resume feature).</p>
853220ed979SColeman Kane
854220ed979SColeman Kane<p>An application that uses this feature for a single parser will have
855220ed979SColeman Kanethe rough structure (in pseudo-code):</p>
856220ed979SColeman Kane
857220ed979SColeman Kane<pre class="pseudocode">
858220ed979SColeman Kanefd = open_input()
859220ed979SColeman Kanep = create_parser()
860220ed979SColeman Kane
861220ed979SColeman Kaneif parse_xml(p, fd) {
862220ed979SColeman Kane  /* suspended */
863220ed979SColeman Kane
864220ed979SColeman Kane  int suspended = 1;
865220ed979SColeman Kane
866220ed979SColeman Kane  while (suspended) {
867220ed979SColeman Kane    do_something_else()
868220ed979SColeman Kane    if ready_to_resume() {
869220ed979SColeman Kane      suspended = continue_parsing(p, fd);
870220ed979SColeman Kane    }
871220ed979SColeman Kane  }
872220ed979SColeman Kane}
873220ed979SColeman Kane</pre>
874220ed979SColeman Kane
875220ed979SColeman Kane<p>An application that may resume any of several parsers based on
876220ed979SColeman Kaneinput (either from the XML being parsed or some other source) will
877220ed979SColeman Kanecertainly have more interesting control structures.</p>
878220ed979SColeman Kane
879220ed979SColeman Kane<p>This C function could be used for the <code>parse_xml</code>
880220ed979SColeman Kanefunction mentioned in the pseudo-code above:</p>
881220ed979SColeman Kane
882220ed979SColeman Kane<pre class="eg">
883220ed979SColeman Kane#define BUFF_SIZE 10240
884220ed979SColeman Kane
885220ed979SColeman Kane/* Parse a document from the open file descriptor 'fd' until the parse
886220ed979SColeman Kane   is complete (the document has been completely parsed, or there's
887220ed979SColeman Kane   been an error), or the parse is stopped.  Return non-zero when
888220ed979SColeman Kane   the parse is merely suspended.
889220ed979SColeman Kane*/
890220ed979SColeman Kaneint
891220ed979SColeman Kaneparse_xml(XML_Parser p, int fd)
892220ed979SColeman Kane{
893220ed979SColeman Kane  for (;;) {
894220ed979SColeman Kane    int last_chunk;
895220ed979SColeman Kane    int bytes_read;
896220ed979SColeman Kane    enum XML_Status status;
897220ed979SColeman Kane
898220ed979SColeman Kane    void *buff = XML_GetBuffer(p, BUFF_SIZE);
899220ed979SColeman Kane    if (buff == NULL) {
900220ed979SColeman Kane      /* handle error... */
901220ed979SColeman Kane      return 0;
902220ed979SColeman Kane    }
903220ed979SColeman Kane    bytes_read = read(fd, buff, BUFF_SIZE);
904220ed979SColeman Kane    if (bytes_read &lt; 0) {
905220ed979SColeman Kane      /* handle error... */
906220ed979SColeman Kane      return 0;
907220ed979SColeman Kane    }
908220ed979SColeman Kane    status = XML_ParseBuffer(p, bytes_read, bytes_read == 0);
909220ed979SColeman Kane    switch (status) {
910220ed979SColeman Kane      case XML_STATUS_ERROR:
911220ed979SColeman Kane        /* handle error... */
912220ed979SColeman Kane        return 0;
913220ed979SColeman Kane      case XML_STATUS_SUSPENDED:
914220ed979SColeman Kane        return 1;
915220ed979SColeman Kane    }
916220ed979SColeman Kane    if (bytes_read == 0)
917220ed979SColeman Kane      return 0;
918220ed979SColeman Kane  }
919220ed979SColeman Kane}
920220ed979SColeman Kane</pre>
921220ed979SColeman Kane
922220ed979SColeman Kane<p>The corresponding <code>continue_parsing</code> function is
923220ed979SColeman Kanesomewhat simpler, since it only need deal with the return code from
924220ed979SColeman Kane<code><a href= "#XML_ResumeParser">XML_ResumeParser</a></code>; it can
925220ed979SColeman Kanedelegate the input handling to the <code>parse_xml</code>
926220ed979SColeman Kanefunction:</p>
927220ed979SColeman Kane
928220ed979SColeman Kane<pre class="eg">
929220ed979SColeman Kane/* Continue parsing a document which had been suspended.  The 'p' and
930220ed979SColeman Kane   'fd' arguments are the same as passed to parse_xml().  Return
931220ed979SColeman Kane   non-zero when the parse is suspended.
932220ed979SColeman Kane*/
933220ed979SColeman Kaneint
934220ed979SColeman Kanecontinue_parsing(XML_Parser p, int fd)
935220ed979SColeman Kane{
936220ed979SColeman Kane  enum XML_Status status = XML_ResumeParser(p);
937220ed979SColeman Kane  switch (status) {
938220ed979SColeman Kane    case XML_STATUS_ERROR:
939220ed979SColeman Kane      /* handle error... */
940220ed979SColeman Kane      return 0;
941220ed979SColeman Kane    case XML_ERROR_NOT_SUSPENDED:
942220ed979SColeman Kane      /* handle error... */
943220ed979SColeman Kane      return 0;.
944220ed979SColeman Kane    case XML_STATUS_SUSPENDED:
945220ed979SColeman Kane      return 1;
946220ed979SColeman Kane  }
947220ed979SColeman Kane  return parse_xml(p, fd);
948220ed979SColeman Kane}
949220ed979SColeman Kane</pre>
950220ed979SColeman Kane
951220ed979SColeman Kane<p>Now that we've seen what a mess the top-level parsing loop can
952220ed979SColeman Kanebecome, what have we gained?  Very simply, we can now use the <code><a
953220ed979SColeman Kanehref= "#XML_StopParser" >XML_StopParser</a></code> function to stop
954220ed979SColeman Kaneparsing, without having to go to great lengths to avoid additional
955220ed979SColeman Kaneprocessing that we're expecting to ignore.  As a bonus, we get to stop
956220ed979SColeman Kaneparsing <em>temporarily</em>, and come back to it when we're
957220ed979SColeman Kaneready.</p>
958220ed979SColeman Kane
959220ed979SColeman Kane<p>To stop parsing from a handler function, use the <code><a href=
960220ed979SColeman Kane"#XML_StopParser" >XML_StopParser</a></code> function.  This function
961220ed979SColeman Kanetakes two arguments; the parser being stopped and a flag indicating
962220ed979SColeman Kanewhether the parse can be resumed in the future.</p>
963220ed979SColeman Kane
964220ed979SColeman Kane<!-- XXX really need more here -->
965220ed979SColeman Kane
966220ed979SColeman Kane
9675bb6a25fSPoul-Henning Kamp<hr />
9685bb6a25fSPoul-Henning Kamp<!-- ================================================================ -->
9695bb6a25fSPoul-Henning Kamp
9705bb6a25fSPoul-Henning Kamp<h2><a name="reference">Expat Reference</a></h2>
9715bb6a25fSPoul-Henning Kamp
9725bb6a25fSPoul-Henning Kamp<h3><a name="creation">Parser Creation</a></h3>
9735bb6a25fSPoul-Henning Kamp
974cc68614dSXin LI<h4 id="XML_ParserCreate">XML_ParserCreate</h4>
975cc68614dSXin LI<pre class="fcndec">
976220ed979SColeman KaneXML_Parser XMLCALL
9775bb6a25fSPoul-Henning KampXML_ParserCreate(const XML_Char *encoding);
9785bb6a25fSPoul-Henning Kamp</pre>
9795bb6a25fSPoul-Henning Kamp<div class="fcndef">
9804543ef51SXin LI<p>
9814543ef51SXin LIConstruct a new parser. If encoding is non-<code>NULL</code>, it specifies a
9825bb6a25fSPoul-Henning Kampcharacter encoding to use for the document. This overrides the document
9835bb6a25fSPoul-Henning Kampencoding declaration. There are four built-in encodings:
9844543ef51SXin LI</p>
9855bb6a25fSPoul-Henning Kamp<ul>
9865bb6a25fSPoul-Henning Kamp<li>US-ASCII</li>
9875bb6a25fSPoul-Henning Kamp<li>UTF-8</li>
9885bb6a25fSPoul-Henning Kamp<li>UTF-16</li>
9895bb6a25fSPoul-Henning Kamp<li>ISO-8859-1</li>
9905bb6a25fSPoul-Henning Kamp</ul>
9914543ef51SXin LI<p>
9925bb6a25fSPoul-Henning KampAny other value will invoke a call to the UnknownEncodingHandler.
9934543ef51SXin LI</p>
9945bb6a25fSPoul-Henning Kamp</div>
9955bb6a25fSPoul-Henning Kamp
996cc68614dSXin LI<h4 id="XML_ParserCreateNS">XML_ParserCreateNS</h4>
997cc68614dSXin LI<pre class="fcndec">
998220ed979SColeman KaneXML_Parser XMLCALL
9995bb6a25fSPoul-Henning KampXML_ParserCreateNS(const XML_Char *encoding,
10005bb6a25fSPoul-Henning Kamp                   XML_Char sep);
10015bb6a25fSPoul-Henning Kamp</pre>
10025bb6a25fSPoul-Henning Kamp<div class="fcndef">
10035bb6a25fSPoul-Henning KampConstructs a new parser that has namespace processing in effect. Namespace
10045bb6a25fSPoul-Henning Kampexpanded element names and attribute names are returned as a concatenation
10055bb6a25fSPoul-Henning Kampof the namespace URI, <em>sep</em>, and the local part of the name. This
1006e3466a89SXin LImeans that you should pick a character for <em>sep</em> that can't be part
1007e3466a89SXin LIof an URI. Since Expat does not check namespace URIs for conformance, the
1008e3466a89SXin LIonly safe choice for a namespace separator is a character that is illegal
1009e3466a89SXin LIin XML. For instance, <code>'\xFF'</code> is not legal in UTF-8, and
1010e3466a89SXin LI<code>'\xFFFF'</code> is not legal in UTF-16. There is a special case when
1011e3466a89SXin LI<em>sep</em> is the null character <code>'\0'</code>: the namespace URI and
1012e3466a89SXin LIthe local part will be concatenated without any separator - this is intended
1013e3466a89SXin LIto support RDF processors. It is a programming error to use the null separator
1014e3466a89SXin LIwith <a href= "#XML_SetReturnNSTriplet">namespace triplets</a>.</div>
10155bb6a25fSPoul-Henning Kamp
10167ed8e142SXin LI<p><strong>Note:</strong>
10177ed8e142SXin LIExpat does not validate namespace URIs (beyond encoding)
10187ed8e142SXin LIagainst RFC 3986 today (and is not required to do so with regard to
10197ed8e142SXin LIthe XML 1.0 namespaces specification) but it may start doing that
10207ed8e142SXin LIin future releases.  Before that, an application using Expat must
10217ed8e142SXin LIbe ready to receive namespace URIs containing non-URI characters.
10227ed8e142SXin LI</p>
10237ed8e142SXin LI
1024cc68614dSXin LI<h4 id="XML_ParserCreate_MM">XML_ParserCreate_MM</h4>
1025cc68614dSXin LI<pre class="fcndec">
1026220ed979SColeman KaneXML_Parser XMLCALL
10275bb6a25fSPoul-Henning KampXML_ParserCreate_MM(const XML_Char *encoding,
10285bb6a25fSPoul-Henning Kamp                    const XML_Memory_Handling_Suite *ms,
10295bb6a25fSPoul-Henning Kamp		    const XML_Char *sep);
10305bb6a25fSPoul-Henning Kamp</pre>
10315bb6a25fSPoul-Henning Kamp<pre class="signature">
10325bb6a25fSPoul-Henning Kamptypedef struct {
1033220ed979SColeman Kane  void *(XMLCALL *malloc_fcn)(size_t size);
1034220ed979SColeman Kane  void *(XMLCALL *realloc_fcn)(void *ptr, size_t size);
1035220ed979SColeman Kane  void (XMLCALL *free_fcn)(void *ptr);
10365bb6a25fSPoul-Henning Kamp} XML_Memory_Handling_Suite;
10375bb6a25fSPoul-Henning Kamp</pre>
10385bb6a25fSPoul-Henning Kamp<div class="fcndef">
10395bb6a25fSPoul-Henning Kamp<p>Construct a new parser using the suite of memory handling functions
10404543ef51SXin LIspecified in <code>ms</code>. If <code>ms</code> is <code>NULL</code>, then use the
10415bb6a25fSPoul-Henning Kampstandard set of memory management functions. If <code>sep</code> is
10424543ef51SXin LInon-<code>NULL</code>, then namespace processing is enabled in the created parser
10435bb6a25fSPoul-Henning Kampand the character pointed at by sep is used as the separator between
10445bb6a25fSPoul-Henning Kampthe namespace URI and the local part of the name.</p>
10455bb6a25fSPoul-Henning Kamp</div>
10465bb6a25fSPoul-Henning Kamp
1047cc68614dSXin LI<h4 id="XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</h4>
1048cc68614dSXin LI<pre class="fcndec">
1049220ed979SColeman KaneXML_Parser XMLCALL
10505bb6a25fSPoul-Henning KampXML_ExternalEntityParserCreate(XML_Parser p,
10515bb6a25fSPoul-Henning Kamp                               const XML_Char *context,
10525bb6a25fSPoul-Henning Kamp                               const XML_Char *encoding);
10535bb6a25fSPoul-Henning Kamp</pre>
10545bb6a25fSPoul-Henning Kamp<div class="fcndef">
10555bb6a25fSPoul-Henning KampConstruct a new <code>XML_Parser</code> object for parsing an external
10565bb6a25fSPoul-Henning Kampgeneral entity. Context is the context argument passed in a call to a
10575bb6a25fSPoul-Henning KampExternalEntityRefHandler. Other state information such as handlers,
10585bb6a25fSPoul-Henning Kampuser data, namespace processing is inherited from the parser passed as
10595bb6a25fSPoul-Henning Kampthe 1st argument. So you shouldn't need to call any of the behavior
10605bb6a25fSPoul-Henning Kampchanging functions on this parser (unless you want it to act
10615bb6a25fSPoul-Henning Kampdifferently than the parent parser).
10625bb6a25fSPoul-Henning Kamp</div>
10635bb6a25fSPoul-Henning Kamp
1064cc68614dSXin LI<h4 id="XML_ParserFree">XML_ParserFree</h4>
1065cc68614dSXin LI<pre class="fcndec">
1066220ed979SColeman Kanevoid XMLCALL
10675bb6a25fSPoul-Henning KampXML_ParserFree(XML_Parser p);
10685bb6a25fSPoul-Henning Kamp</pre>
10695bb6a25fSPoul-Henning Kamp<div class="fcndef">
10705bb6a25fSPoul-Henning KampFree memory used by the parser. Your application is responsible for
10715bb6a25fSPoul-Henning Kampfreeing any memory associated with <a href="#userdata">user data</a>.
10725bb6a25fSPoul-Henning Kamp</div>
10735bb6a25fSPoul-Henning Kamp
1074cc68614dSXin LI<h4 id="XML_ParserReset">XML_ParserReset</h4>
1075cc68614dSXin LI<pre class="fcndec">
1076220ed979SColeman KaneXML_Bool XMLCALL
1077220ed979SColeman KaneXML_ParserReset(XML_Parser p,
1078220ed979SColeman Kane                const XML_Char *encoding);
10795bb6a25fSPoul-Henning Kamp</pre>
10805bb6a25fSPoul-Henning Kamp<div class="fcndef">
10815bb6a25fSPoul-Henning KampClean up the memory structures maintained by the parser so that it may
10825bb6a25fSPoul-Henning Kampbe used again.  After this has been called, <code>parser</code> is
1083220ed979SColeman Kaneready to start parsing a new document.  All handlers are cleared from
1084220ed979SColeman Kanethe parser, except for the unknownEncodingHandler.  The parser's external
1085220ed979SColeman Kanestate is re-initialized except for the values of ns and ns_triplets.
1086220ed979SColeman KaneThis function may not be used on a parser created using <code><a href=
10875bb6a25fSPoul-Henning Kamp"#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a
10885bb6a25fSPoul-Henning Kamp></code>; it will return <code>XML_FALSE</code> in that case.  Returns
10895bb6a25fSPoul-Henning Kamp<code>XML_TRUE</code> on success.  Your application is responsible for
10905bb6a25fSPoul-Henning Kampdealing with any memory associated with <a href="#userdata">user data</a>.
10915bb6a25fSPoul-Henning Kamp</div>
10925bb6a25fSPoul-Henning Kamp
10935bb6a25fSPoul-Henning Kamp<h3><a name="parsing">Parsing</a></h3>
10945bb6a25fSPoul-Henning Kamp
10955bb6a25fSPoul-Henning Kamp<p>To state the obvious: the three parsing functions <code><a href=
1096220ed979SColeman Kane"#XML_Parse" >XML_Parse</a></code>, <code><a href= "#XML_ParseBuffer">
1097220ed979SColeman KaneXML_ParseBuffer</a></code> and <code><a href= "#XML_GetBuffer">
1098220ed979SColeman KaneXML_GetBuffer</a></code> must not be called from within a handler
1099220ed979SColeman Kaneunless they operate on a separate parser instance, that is, one that
1100220ed979SColeman Kanedid not call the handler. For example, it is OK to call the parsing
1101220ed979SColeman Kanefunctions from within an <code>XML_ExternalEntityRefHandler</code>,
1102220ed979SColeman Kaneif they apply to the parser created by
1103220ed979SColeman Kane<code><a href= "#XML_ExternalEntityParserCreate"
11045bb6a25fSPoul-Henning Kamp>XML_ExternalEntityParserCreate</a></code>.</p>
11055bb6a25fSPoul-Henning Kamp
1106cc68614dSXin LI<p>Note: The <code>len</code> argument passed to these functions
1107220ed979SColeman Kaneshould be considerably less than the maximum value for an integer,
1108220ed979SColeman Kaneas it could create an integer overflow situation if the added
1109220ed979SColeman Kanelengths of a buffer and the unprocessed portion of the previous buffer
1110220ed979SColeman Kaneexceed the maximum integer value. Input data at the end of a buffer
1111220ed979SColeman Kanewill remain unprocessed if it is part of an XML token for which the
1112220ed979SColeman Kaneend is not part of that buffer.</p>
1113220ed979SColeman Kane
11144543ef51SXin LI<p><a name="isFinal"></a>The application <em>must</em> make a concluding
11154543ef51SXin LI<code><a href="#XML_Parse">XML_Parse</a></code> or
11164543ef51SXin LI<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> call
11174543ef51SXin LIwith <code>isFinal</code> set to <code>XML_TRUE</code>.</p>
11184543ef51SXin LI
1119cc68614dSXin LI<h4 id="XML_Parse">XML_Parse</h4>
1120cc68614dSXin LI<pre class="fcndec">
1121220ed979SColeman Kaneenum XML_Status XMLCALL
11225bb6a25fSPoul-Henning KampXML_Parse(XML_Parser p,
11235bb6a25fSPoul-Henning Kamp          const char *s,
11245bb6a25fSPoul-Henning Kamp          int len,
11255bb6a25fSPoul-Henning Kamp          int isFinal);
11265bb6a25fSPoul-Henning Kamp</pre>
11275bb6a25fSPoul-Henning Kamp<pre class="signature">
11285bb6a25fSPoul-Henning Kampenum XML_Status {
11295bb6a25fSPoul-Henning Kamp  XML_STATUS_ERROR = 0,
11305bb6a25fSPoul-Henning Kamp  XML_STATUS_OK = 1
11315bb6a25fSPoul-Henning Kamp};
11325bb6a25fSPoul-Henning Kamp</pre>
11335bb6a25fSPoul-Henning Kamp<div class="fcndef">
11344543ef51SXin LI<p>
11355bb6a25fSPoul-Henning KampParse some more of the document. The string <code>s</code> is a buffer
11365bb6a25fSPoul-Henning Kampcontaining part (or perhaps all) of the document. The number of bytes of s
11375bb6a25fSPoul-Henning Kampthat are part of the document is indicated by <code>len</code>. This means
11384543ef51SXin LIthat <code>s</code> doesn't have to be null-terminated. It also means that
11395bb6a25fSPoul-Henning Kampif <code>len</code> is larger than the number of bytes in the block of
1140ffd294a1SEnji Coopermemory that <code>s</code> points at, then a memory fault is likely.
1141ffd294a1SEnji CooperNegative values for <code>len</code> are rejected since Expat 2.2.1.
1142ffd294a1SEnji CooperThe
11435bb6a25fSPoul-Henning Kamp<code>isFinal</code> parameter informs the parser that this is the last
11445bb6a25fSPoul-Henning Kamppiece of the document. Frequently, the last piece is empty (i.e.
11455bb6a25fSPoul-Henning Kamp<code>len</code> is zero.)
11464543ef51SXin LI</p>
11474543ef51SXin LI
11484543ef51SXin LI<p>
11495bb6a25fSPoul-Henning KampIf a parse error occurred, it returns <code>XML_STATUS_ERROR</code>.
11505bb6a25fSPoul-Henning KampOtherwise it returns <code>XML_STATUS_OK</code> value.
11514543ef51SXin LINote that regardless of the return value, there is no guarantee that all
11524543ef51SXin LIprovided input has been parsed; only after <a href="#isFinal">the
11534543ef51SXin LIconcluding call</a> will all handler callbacks and parsing errors have
11544543ef51SXin LIhappened.
11554543ef51SXin LI</p>
11564543ef51SXin LI
11574543ef51SXin LI<p>
11584543ef51SXin LISimplified, <code>XML_Parse</code> can be considered a convenience wrapper
11594543ef51SXin LIthat is pairing calls
11604543ef51SXin LIto <code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>
11614543ef51SXin LIand <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>
11624543ef51SXin LI(when Expat is built with macro <code>XML_CONTEXT_BYTES</code>
11634543ef51SXin LIdefined to a positive value, which is both common and default).
11644543ef51SXin LI<code>XML_Parse</code> is then functionally equivalent to calling
11654543ef51SXin LI<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>,
11664543ef51SXin LI<code>memcpy</code>, and
11674543ef51SXin LI<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>.
11684543ef51SXin LI</p>
11694543ef51SXin LI
11704543ef51SXin LI<p>
11714543ef51SXin LITo avoid double copying of the input, direct use of functions
11724543ef51SXin LI<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code> and
11734543ef51SXin LI<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> is advised
11744543ef51SXin LIfor most production use, e.g.
11754543ef51SXin LIif you're using <code>read</code> or similar functionality to fill your
11764543ef51SXin LIbuffers, fill directly into the buffer from
11774543ef51SXin LI<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>,
11784543ef51SXin LIthen parse with <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>.
11794543ef51SXin LI</p>
11805bb6a25fSPoul-Henning Kamp</div>
11815bb6a25fSPoul-Henning Kamp
1182cc68614dSXin LI<h4 id="XML_ParseBuffer">XML_ParseBuffer</h4>
1183cc68614dSXin LI<pre class="fcndec">
1184220ed979SColeman Kaneenum XML_Status XMLCALL
11855bb6a25fSPoul-Henning KampXML_ParseBuffer(XML_Parser p,
11865bb6a25fSPoul-Henning Kamp                int len,
11875bb6a25fSPoul-Henning Kamp                int isFinal);
11885bb6a25fSPoul-Henning Kamp</pre>
11895bb6a25fSPoul-Henning Kamp<div class="fcndef">
1190ffd294a1SEnji Cooper<p>
11915bb6a25fSPoul-Henning KampThis is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>,
11925bb6a25fSPoul-Henning Kampexcept in this case Expat provides the buffer.  By obtaining the
11935bb6a25fSPoul-Henning Kampbuffer from Expat with the <code><a href= "#XML_GetBuffer"
11945bb6a25fSPoul-Henning Kamp>XML_GetBuffer</a></code> function, the application can avoid double
11955bb6a25fSPoul-Henning Kampcopying of the input.
1196ffd294a1SEnji Cooper</p>
1197ffd294a1SEnji Cooper
1198ffd294a1SEnji Cooper<p>
1199ffd294a1SEnji CooperNegative values for <code>len</code> are rejected since Expat 2.6.3.
1200ffd294a1SEnji Cooper</p>
12015bb6a25fSPoul-Henning Kamp</div>
12025bb6a25fSPoul-Henning Kamp
1203cc68614dSXin LI<h4 id="XML_GetBuffer">XML_GetBuffer</h4>
1204cc68614dSXin LI<pre class="fcndec">
1205220ed979SColeman Kanevoid * XMLCALL
12065bb6a25fSPoul-Henning KampXML_GetBuffer(XML_Parser p,
12075bb6a25fSPoul-Henning Kamp              int len);
12085bb6a25fSPoul-Henning Kamp</pre>
12095bb6a25fSPoul-Henning Kamp<div class="fcndef">
12105bb6a25fSPoul-Henning KampObtain a buffer of size <code>len</code> to read a piece of the document
12114543ef51SXin LIinto. A <code>NULL</code> value is returned if Expat can't allocate enough memory for
12124543ef51SXin LIthis buffer. A <code>NULL</code> value may also be returned if <code>len</code> is zero.
1213cc68614dSXin LIThis has to be called prior to every call to
12145bb6a25fSPoul-Henning Kamp<code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A
12155bb6a25fSPoul-Henning Kamptypical use would look like this:
12165bb6a25fSPoul-Henning Kamp
12175bb6a25fSPoul-Henning Kamp<pre class="eg">
12185bb6a25fSPoul-Henning Kampfor (;;) {
12195bb6a25fSPoul-Henning Kamp  int bytes_read;
12205bb6a25fSPoul-Henning Kamp  void *buff = XML_GetBuffer(p, BUFF_SIZE);
12215bb6a25fSPoul-Henning Kamp  if (buff == NULL) {
12225bb6a25fSPoul-Henning Kamp    /* handle error */
12235bb6a25fSPoul-Henning Kamp  }
12245bb6a25fSPoul-Henning Kamp
12255bb6a25fSPoul-Henning Kamp  bytes_read = read(docfd, buff, BUFF_SIZE);
12265bb6a25fSPoul-Henning Kamp  if (bytes_read &lt; 0) {
12275bb6a25fSPoul-Henning Kamp    /* handle error */
12285bb6a25fSPoul-Henning Kamp  }
12295bb6a25fSPoul-Henning Kamp
12305bb6a25fSPoul-Henning Kamp  if (! XML_ParseBuffer(p, bytes_read, bytes_read == 0)) {
12315bb6a25fSPoul-Henning Kamp    /* handle parse error */
12325bb6a25fSPoul-Henning Kamp  }
12335bb6a25fSPoul-Henning Kamp
12345bb6a25fSPoul-Henning Kamp  if (bytes_read == 0)
12355bb6a25fSPoul-Henning Kamp    break;
12365bb6a25fSPoul-Henning Kamp}
12375bb6a25fSPoul-Henning Kamp</pre>
12385bb6a25fSPoul-Henning Kamp</div>
12395bb6a25fSPoul-Henning Kamp
1240cc68614dSXin LI<h4 id="XML_StopParser">XML_StopParser</h4>
1241cc68614dSXin LI<pre class="fcndec">
1242220ed979SColeman Kaneenum XML_Status XMLCALL
1243220ed979SColeman KaneXML_StopParser(XML_Parser p,
1244220ed979SColeman Kane               XML_Bool resumable);
1245220ed979SColeman Kane</pre>
1246220ed979SColeman Kane<div class="fcndef">
1247220ed979SColeman Kane
1248220ed979SColeman Kane<p>Stops parsing, causing <code><a href= "#XML_Parse"
1249220ed979SColeman Kane>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
1250220ed979SColeman Kane>XML_ParseBuffer</a></code> to return.  Must be called from within a
1251220ed979SColeman Kanecall-back handler, except when aborting (when <code>resumable</code>
1252220ed979SColeman Kaneis <code>XML_FALSE</code>) an already suspended parser.  Some
1253220ed979SColeman Kanecall-backs may still follow because they would otherwise get
1254cc68614dSXin LIlost, including</p>
1255220ed979SColeman Kane<ul>
1256220ed979SColeman Kane  <li> the end element handler for empty elements when stopped in the
1257220ed979SColeman Kane       start element handler,</li>
1258220ed979SColeman Kane  <li> the end namespace declaration handler when stopped in the end
1259220ed979SColeman Kane       element handler,</li>
1260220ed979SColeman Kane  <li> the character data handler when stopped in the character data handler
1261220ed979SColeman Kane       while making multiple call-backs on a contiguous chunk of characters,</li>
1262220ed979SColeman Kane</ul>
1263cc68614dSXin LI<p>and possibly others.</p>
1264220ed979SColeman Kane
1265220ed979SColeman Kane<p>This can be called from most handlers, including DTD related
1266220ed979SColeman Kanecall-backs, except when parsing an external parameter entity and
1267220ed979SColeman Kane<code>resumable</code> is <code>XML_TRUE</code>.  Returns
1268220ed979SColeman Kane<code>XML_STATUS_OK</code> when successful,
1269220ed979SColeman Kane<code>XML_STATUS_ERROR</code> otherwise.  The possible error codes
1270220ed979SColeman Kaneare:</p>
1271220ed979SColeman Kane<dl>
1272fe927888SPhilip Paeps  <dt><code>XML_ERROR_NOT_STARTED</code></dt>
1273fe927888SPhilip Paeps  <dd>
1274fe927888SPhilip Paeps    when stopping or suspending a parser before it has started,
1275fe927888SPhilip Paeps    added in Expat 2.6.4.
1276fe927888SPhilip Paeps  </dd>
1277220ed979SColeman Kane  <dt><code>XML_ERROR_SUSPENDED</code></dt>
1278220ed979SColeman Kane  <dd>when suspending an already suspended parser.</dd>
1279220ed979SColeman Kane  <dt><code>XML_ERROR_FINISHED</code></dt>
1280220ed979SColeman Kane  <dd>when the parser has already finished.</dd>
1281220ed979SColeman Kane  <dt><code>XML_ERROR_SUSPEND_PE</code></dt>
1282220ed979SColeman Kane  <dd>when suspending while parsing an external PE.</dd>
1283220ed979SColeman Kane</dl>
1284220ed979SColeman Kane
1285220ed979SColeman Kane<p>Since the stop/resume feature requires application support in the
1286220ed979SColeman Kaneouter parsing loop, it is an error to call this function for a parser
1287220ed979SColeman Kanenot being handled appropriately; see <a href= "#stop-resume"
1288220ed979SColeman Kane>Temporarily Stopping Parsing</a> for more information.</p>
1289220ed979SColeman Kane
1290220ed979SColeman Kane<p>When <code>resumable</code> is <code>XML_TRUE</code> then parsing
1291220ed979SColeman Kaneis <em>suspended</em>, that is, <code><a href= "#XML_Parse"
1292220ed979SColeman Kane>XML_Parse</a></code> and <code><a href= "#XML_ParseBuffer"
1293220ed979SColeman Kane>XML_ParseBuffer</a></code> return <code>XML_STATUS_SUSPENDED</code>.
1294220ed979SColeman KaneOtherwise, parsing is <em>aborted</em>, that is, <code><a href=
1295220ed979SColeman Kane"#XML_Parse" >XML_Parse</a></code> and <code><a href=
1296220ed979SColeman Kane"#XML_ParseBuffer" >XML_ParseBuffer</a></code> return
1297220ed979SColeman Kane<code>XML_STATUS_ERROR</code> with error code
1298220ed979SColeman Kane<code>XML_ERROR_ABORTED</code>.</p>
1299220ed979SColeman Kane
1300220ed979SColeman Kane<p><strong>Note:</strong>
1301220ed979SColeman KaneThis will be applied to the current parser instance only, that is, if
1302220ed979SColeman Kanethere is a parent parser then it will continue parsing when the
1303220ed979SColeman Kaneexternal entity reference handler returns.  It is up to the
1304220ed979SColeman Kaneimplementation of that handler to call <code><a href=
1305220ed979SColeman Kane"#XML_StopParser" >XML_StopParser</a></code> on the parent parser
1306220ed979SColeman Kane(recursively), if one wants to stop parsing altogether.</p>
1307220ed979SColeman Kane
1308220ed979SColeman Kane<p>When suspended, parsing can be resumed by calling <code><a href=
1309220ed979SColeman Kane"#XML_ResumeParser" >XML_ResumeParser</a></code>.</p>
1310220ed979SColeman Kane
1311220ed979SColeman Kane<p>New in Expat 1.95.8.</p>
1312220ed979SColeman Kane</div>
1313220ed979SColeman Kane
1314cc68614dSXin LI<h4 id="XML_ResumeParser">XML_ResumeParser</h4>
1315cc68614dSXin LI<pre class="fcndec">
1316220ed979SColeman Kaneenum XML_Status XMLCALL
1317220ed979SColeman KaneXML_ResumeParser(XML_Parser p);
1318220ed979SColeman Kane</pre>
1319220ed979SColeman Kane<div class="fcndef">
1320220ed979SColeman Kane<p>Resumes parsing after it has been suspended with <code><a href=
1321220ed979SColeman Kane"#XML_StopParser" >XML_StopParser</a></code>.  Must not be called from
1322220ed979SColeman Kanewithin a handler call-back.  Returns same status codes as <code><a
1323220ed979SColeman Kanehref= "#XML_Parse">XML_Parse</a></code> or <code><a href=
1324220ed979SColeman Kane"#XML_ParseBuffer" >XML_ParseBuffer</a></code>.  An additional error
1325220ed979SColeman Kanecode, <code>XML_ERROR_NOT_SUSPENDED</code>, will be returned if the
1326220ed979SColeman Kaneparser was not currently suspended.</p>
1327220ed979SColeman Kane
1328220ed979SColeman Kane<p><strong>Note:</strong>
1329220ed979SColeman KaneThis must be called on the most deeply nested child parser instance
1330220ed979SColeman Kanefirst, and on its parent parser only after the child parser has
1331220ed979SColeman Kanefinished, to be applied recursively until the document entity's parser
1332220ed979SColeman Kaneis restarted.  That is, the parent parser will not resume by itself
1333220ed979SColeman Kaneand it is up to the application to call <code><a href=
1334220ed979SColeman Kane"#XML_ResumeParser" >XML_ResumeParser</a></code> on it at the
1335220ed979SColeman Kaneappropriate moment.</p>
1336220ed979SColeman Kane
1337220ed979SColeman Kane<p>New in Expat 1.95.8.</p>
1338220ed979SColeman Kane</div>
1339220ed979SColeman Kane
1340cc68614dSXin LI<h4 id="XML_GetParsingStatus">XML_GetParsingStatus</h4>
1341cc68614dSXin LI<pre class="fcndec">
1342220ed979SColeman Kanevoid XMLCALL
1343220ed979SColeman KaneXML_GetParsingStatus(XML_Parser p,
1344220ed979SColeman Kane                     XML_ParsingStatus *status);
1345220ed979SColeman Kane</pre>
1346220ed979SColeman Kane<pre class="signature">
1347220ed979SColeman Kaneenum XML_Parsing {
1348220ed979SColeman Kane  XML_INITIALIZED,
1349220ed979SColeman Kane  XML_PARSING,
1350220ed979SColeman Kane  XML_FINISHED,
1351220ed979SColeman Kane  XML_SUSPENDED
1352220ed979SColeman Kane};
1353220ed979SColeman Kane
1354220ed979SColeman Kanetypedef struct {
1355220ed979SColeman Kane  enum XML_Parsing parsing;
1356220ed979SColeman Kane  XML_Bool finalBuffer;
1357220ed979SColeman Kane} XML_ParsingStatus;
1358220ed979SColeman Kane</pre>
1359220ed979SColeman Kane<div class="fcndef">
1360220ed979SColeman Kane<p>Returns status of parser with respect to being initialized,
1361220ed979SColeman Kaneparsing, finished, or suspended, and whether the final buffer is being
1362220ed979SColeman Kaneprocessed.  The <code>status</code> parameter <em>must not</em> be
13634543ef51SXin LI<code>NULL</code>.</p>
1364220ed979SColeman Kane
1365220ed979SColeman Kane<p>New in Expat 1.95.8.</p>
1366220ed979SColeman Kane</div>
1367220ed979SColeman Kane
1368220ed979SColeman Kane
13695bb6a25fSPoul-Henning Kamp<h3><a name="setting">Handler Setting</a></h3>
13705bb6a25fSPoul-Henning Kamp
13715bb6a25fSPoul-Henning Kamp<p>Although handlers are typically set prior to parsing and left alone, an
13725bb6a25fSPoul-Henning Kampapplication may choose to set or change the handler for a parsing event
13735bb6a25fSPoul-Henning Kampwhile the parse is in progress. For instance, your application may choose
13745bb6a25fSPoul-Henning Kampto ignore all text not descended from a <code>para</code> element. One
13755bb6a25fSPoul-Henning Kampway it could do this is to set the character handler when a para start tag
13765bb6a25fSPoul-Henning Kampis seen, and unset it for the corresponding end tag.</p>
13775bb6a25fSPoul-Henning Kamp
13784543ef51SXin LI<p>A handler may be <em>unset</em> by providing a <code>NULL</code> pointer to the
13795bb6a25fSPoul-Henning Kampappropriate handler setter. None of the handler setting functions have
13805bb6a25fSPoul-Henning Kampa return value.</p>
13815bb6a25fSPoul-Henning Kamp
13825bb6a25fSPoul-Henning Kamp<p>Your handlers will be receiving strings in arrays of type
1383220ed979SColeman Kane<code>XML_Char</code>. This type is conditionally defined in expat.h as
1384220ed979SColeman Kaneeither <code>char</code>, <code>wchar_t</code> or <code>unsigned short</code>.
1385220ed979SColeman KaneThe former implies UTF-8 encoding, the latter two imply UTF-16 encoding.
1386220ed979SColeman KaneNote that you'll receive them in this form independent of the original
1387220ed979SColeman Kaneencoding of the document.</p>
13885bb6a25fSPoul-Henning Kamp
13895bb6a25fSPoul-Henning Kamp<div class="handler">
1390cc68614dSXin LI<h4 id="XML_SetStartElementHandler">XML_SetStartElementHandler</h4>
1391cc68614dSXin LI<pre class="setter">
1392220ed979SColeman Kanevoid XMLCALL
13935bb6a25fSPoul-Henning KampXML_SetStartElementHandler(XML_Parser p,
13945bb6a25fSPoul-Henning Kamp                           XML_StartElementHandler start);
13955bb6a25fSPoul-Henning Kamp</pre>
13965bb6a25fSPoul-Henning Kamp<pre class="signature">
13975bb6a25fSPoul-Henning Kamptypedef void
1398220ed979SColeman Kane(XMLCALL *XML_StartElementHandler)(void *userData,
13995bb6a25fSPoul-Henning Kamp                                   const XML_Char *name,
14005bb6a25fSPoul-Henning Kamp                                   const XML_Char **atts);
14015bb6a25fSPoul-Henning Kamp</pre>
14025bb6a25fSPoul-Henning Kamp<p>Set handler for start (and empty) tags. Attributes are passed to the start
14035bb6a25fSPoul-Henning Kamphandler as a pointer to a vector of char pointers. Each attribute seen in
14045bb6a25fSPoul-Henning Kampa start (or empty) tag occupies 2 consecutive places in this vector: the
14055bb6a25fSPoul-Henning Kampattribute name followed by the attribute value. These pairs are terminated
14064543ef51SXin LIby a <code>NULL</code> pointer.</p>
14075bb6a25fSPoul-Henning Kamp<p>Note that an empty tag generates a call to both start and end handlers
14085bb6a25fSPoul-Henning Kamp(in that order).</p>
14095bb6a25fSPoul-Henning Kamp</div>
14105bb6a25fSPoul-Henning Kamp
14115bb6a25fSPoul-Henning Kamp<div class="handler">
1412cc68614dSXin LI<h4 id="XML_SetEndElementHandler">XML_SetEndElementHandler</h4>
1413cc68614dSXin LI<pre class="setter">
1414220ed979SColeman Kanevoid XMLCALL
14155bb6a25fSPoul-Henning KampXML_SetEndElementHandler(XML_Parser p,
14165bb6a25fSPoul-Henning Kamp                         XML_EndElementHandler);
14175bb6a25fSPoul-Henning Kamp</pre>
14185bb6a25fSPoul-Henning Kamp<pre class="signature">
14195bb6a25fSPoul-Henning Kamptypedef void
1420220ed979SColeman Kane(XMLCALL *XML_EndElementHandler)(void *userData,
14215bb6a25fSPoul-Henning Kamp                                 const XML_Char *name);
14225bb6a25fSPoul-Henning Kamp</pre>
14235bb6a25fSPoul-Henning Kamp<p>Set handler for end (and empty) tags. As noted above, an empty tag
14245bb6a25fSPoul-Henning Kampgenerates a call to both start and end handlers.</p>
14255bb6a25fSPoul-Henning Kamp</div>
14265bb6a25fSPoul-Henning Kamp
14275bb6a25fSPoul-Henning Kamp<div class="handler">
1428cc68614dSXin LI<h4 id="XML_SetElementHandler">XML_SetElementHandler</h4>
1429cc68614dSXin LI<pre class="setter">
1430220ed979SColeman Kanevoid XMLCALL
14315bb6a25fSPoul-Henning KampXML_SetElementHandler(XML_Parser p,
14325bb6a25fSPoul-Henning Kamp                      XML_StartElementHandler start,
14335bb6a25fSPoul-Henning Kamp                      XML_EndElementHandler end);
14345bb6a25fSPoul-Henning Kamp</pre>
14355bb6a25fSPoul-Henning Kamp<p>Set handlers for start and end tags with one call.</p>
14365bb6a25fSPoul-Henning Kamp</div>
14375bb6a25fSPoul-Henning Kamp
14385bb6a25fSPoul-Henning Kamp<div class="handler">
1439cc68614dSXin LI<h4 id="XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</h4>
1440cc68614dSXin LI<pre class="setter">
1441220ed979SColeman Kanevoid XMLCALL
14425bb6a25fSPoul-Henning KampXML_SetCharacterDataHandler(XML_Parser p,
14435bb6a25fSPoul-Henning Kamp                            XML_CharacterDataHandler charhndl)
14445bb6a25fSPoul-Henning Kamp</pre>
14455bb6a25fSPoul-Henning Kamp<pre class="signature">
14465bb6a25fSPoul-Henning Kamptypedef void
1447220ed979SColeman Kane(XMLCALL *XML_CharacterDataHandler)(void *userData,
14485bb6a25fSPoul-Henning Kamp                                    const XML_Char *s,
14495bb6a25fSPoul-Henning Kamp                                    int len);
14505bb6a25fSPoul-Henning Kamp</pre>
14515bb6a25fSPoul-Henning Kamp<p>Set a text handler. The string your handler receives
1452cc68614dSXin LIis <em>NOT null-terminated</em>. You have to use the length argument
14535bb6a25fSPoul-Henning Kampto deal with the end of the string. A single block of contiguous text
14545bb6a25fSPoul-Henning Kampfree of markup may still result in a sequence of calls to this handler.
14555bb6a25fSPoul-Henning KampIn other words, if you're searching for a pattern in the text, it may
14564543ef51SXin LIbe split across calls to this handler. Note: Setting this handler to <code>NULL</code>
1457220ed979SColeman Kanemay <em>NOT immediately</em> terminate call-backs if the parser is currently
1458220ed979SColeman Kaneprocessing such a single block of contiguous markup-free text, as the parser
1459220ed979SColeman Kanewill continue calling back until the end of the block is reached.</p>
14605bb6a25fSPoul-Henning Kamp</div>
14615bb6a25fSPoul-Henning Kamp
14625bb6a25fSPoul-Henning Kamp<div class="handler">
1463cc68614dSXin LI<h4 id="XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</h4>
1464cc68614dSXin LI<pre class="setter">
1465220ed979SColeman Kanevoid XMLCALL
14665bb6a25fSPoul-Henning KampXML_SetProcessingInstructionHandler(XML_Parser p,
14675bb6a25fSPoul-Henning Kamp                                    XML_ProcessingInstructionHandler proc)
14685bb6a25fSPoul-Henning Kamp</pre>
14695bb6a25fSPoul-Henning Kamp<pre class="signature">
14705bb6a25fSPoul-Henning Kamptypedef void
1471220ed979SColeman Kane(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,
14725bb6a25fSPoul-Henning Kamp                                            const XML_Char *target,
14735bb6a25fSPoul-Henning Kamp                                            const XML_Char *data);
14745bb6a25fSPoul-Henning Kamp
14755bb6a25fSPoul-Henning Kamp</pre>
14765bb6a25fSPoul-Henning Kamp<p>Set a handler for processing instructions. The target is the first word
14775bb6a25fSPoul-Henning Kampin the processing instruction. The data is the rest of the characters in
14785bb6a25fSPoul-Henning Kampit after skipping all whitespace after the initial word.</p>
14795bb6a25fSPoul-Henning Kamp</div>
14805bb6a25fSPoul-Henning Kamp
14815bb6a25fSPoul-Henning Kamp<div class="handler">
1482cc68614dSXin LI<h4 id="XML_SetCommentHandler">XML_SetCommentHandler</h4>
1483cc68614dSXin LI<pre class="setter">
1484220ed979SColeman Kanevoid XMLCALL
14855bb6a25fSPoul-Henning KampXML_SetCommentHandler(XML_Parser p,
14865bb6a25fSPoul-Henning Kamp                      XML_CommentHandler cmnt)
14875bb6a25fSPoul-Henning Kamp</pre>
14885bb6a25fSPoul-Henning Kamp<pre class="signature">
14895bb6a25fSPoul-Henning Kamptypedef void
1490220ed979SColeman Kane(XMLCALL *XML_CommentHandler)(void *userData,
14915bb6a25fSPoul-Henning Kamp                              const XML_Char *data);
14925bb6a25fSPoul-Henning Kamp</pre>
14935bb6a25fSPoul-Henning Kamp<p>Set a handler for comments. The data is all text inside the comment
14945bb6a25fSPoul-Henning Kampdelimiters.</p>
14955bb6a25fSPoul-Henning Kamp</div>
14965bb6a25fSPoul-Henning Kamp
14975bb6a25fSPoul-Henning Kamp<div class="handler">
1498cc68614dSXin LI<h4 id="XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</h4>
1499cc68614dSXin LI<pre class="setter">
1500220ed979SColeman Kanevoid XMLCALL
15015bb6a25fSPoul-Henning KampXML_SetStartCdataSectionHandler(XML_Parser p,
15025bb6a25fSPoul-Henning Kamp                                XML_StartCdataSectionHandler start);
15035bb6a25fSPoul-Henning Kamp</pre>
15045bb6a25fSPoul-Henning Kamp<pre class="signature">
15055bb6a25fSPoul-Henning Kamptypedef void
1506220ed979SColeman Kane(XMLCALL *XML_StartCdataSectionHandler)(void *userData);
15075bb6a25fSPoul-Henning Kamp</pre>
15085bb6a25fSPoul-Henning Kamp<p>Set a handler that gets called at the beginning of a CDATA section.</p>
15095bb6a25fSPoul-Henning Kamp</div>
15105bb6a25fSPoul-Henning Kamp
15115bb6a25fSPoul-Henning Kamp<div class="handler">
1512cc68614dSXin LI<h4 id="XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</h4>
1513cc68614dSXin LI<pre class="setter">
1514220ed979SColeman Kanevoid XMLCALL
15155bb6a25fSPoul-Henning KampXML_SetEndCdataSectionHandler(XML_Parser p,
15165bb6a25fSPoul-Henning Kamp                              XML_EndCdataSectionHandler end);
15175bb6a25fSPoul-Henning Kamp</pre>
15185bb6a25fSPoul-Henning Kamp<pre class="signature">
15195bb6a25fSPoul-Henning Kamptypedef void
1520220ed979SColeman Kane(XMLCALL *XML_EndCdataSectionHandler)(void *userData);
15215bb6a25fSPoul-Henning Kamp</pre>
15225bb6a25fSPoul-Henning Kamp<p>Set a handler that gets called at the end of a CDATA section.</p>
15235bb6a25fSPoul-Henning Kamp</div>
15245bb6a25fSPoul-Henning Kamp
15255bb6a25fSPoul-Henning Kamp<div class="handler">
1526cc68614dSXin LI<h4 id="XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</h4>
1527cc68614dSXin LI<pre class="setter">
1528220ed979SColeman Kanevoid XMLCALL
15295bb6a25fSPoul-Henning KampXML_SetCdataSectionHandler(XML_Parser p,
15305bb6a25fSPoul-Henning Kamp                           XML_StartCdataSectionHandler start,
15315bb6a25fSPoul-Henning Kamp                           XML_EndCdataSectionHandler end)
15325bb6a25fSPoul-Henning Kamp</pre>
15335bb6a25fSPoul-Henning Kamp<p>Sets both CDATA section handlers with one call.</p>
15345bb6a25fSPoul-Henning Kamp</div>
15355bb6a25fSPoul-Henning Kamp
15365bb6a25fSPoul-Henning Kamp<div class="handler">
1537cc68614dSXin LI<h4 id="XML_SetDefaultHandler">XML_SetDefaultHandler</h4>
1538cc68614dSXin LI<pre class="setter">
1539220ed979SColeman Kanevoid XMLCALL
15405bb6a25fSPoul-Henning KampXML_SetDefaultHandler(XML_Parser p,
15415bb6a25fSPoul-Henning Kamp                      XML_DefaultHandler hndl)
15425bb6a25fSPoul-Henning Kamp</pre>
15435bb6a25fSPoul-Henning Kamp<pre class="signature">
15445bb6a25fSPoul-Henning Kamptypedef void
1545220ed979SColeman Kane(XMLCALL *XML_DefaultHandler)(void *userData,
15465bb6a25fSPoul-Henning Kamp                              const XML_Char *s,
15475bb6a25fSPoul-Henning Kamp                              int len);
15485bb6a25fSPoul-Henning Kamp</pre>
15495bb6a25fSPoul-Henning Kamp
15505bb6a25fSPoul-Henning Kamp<p>Sets a handler for any characters in the document which wouldn't
15515bb6a25fSPoul-Henning Kampotherwise be handled. This includes both data for which no handlers
15525bb6a25fSPoul-Henning Kampcan be set (like some kinds of DTD declarations) and data which could
15535bb6a25fSPoul-Henning Kampbe reported but which currently has no handler set.  The characters
15545bb6a25fSPoul-Henning Kampare passed exactly as they were present in the XML document except
15555bb6a25fSPoul-Henning Kampthat they will be encoded in UTF-8 or UTF-16. Line boundaries are not
15565bb6a25fSPoul-Henning Kampnormalized. Note that a byte order mark character is not passed to the
15575bb6a25fSPoul-Henning Kampdefault handler. There are no guarantees about how characters are
15585bb6a25fSPoul-Henning Kampdivided between calls to the default handler: for example, a comment
15595bb6a25fSPoul-Henning Kampmight be split between multiple calls.  Setting the handler with
15605bb6a25fSPoul-Henning Kampthis call has the side effect of turning off expansion of references
15615bb6a25fSPoul-Henning Kampto internally defined general entities. Instead these references are
15625bb6a25fSPoul-Henning Kamppassed to the default handler.</p>
15635bb6a25fSPoul-Henning Kamp
15645bb6a25fSPoul-Henning Kamp<p>See also <code><a
15655bb6a25fSPoul-Henning Kamphref="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
15665bb6a25fSPoul-Henning Kamp</div>
15675bb6a25fSPoul-Henning Kamp
15685bb6a25fSPoul-Henning Kamp<div class="handler">
1569cc68614dSXin LI<h4 id="XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</h4>
1570cc68614dSXin LI<pre class="setter">
1571220ed979SColeman Kanevoid XMLCALL
15725bb6a25fSPoul-Henning KampXML_SetDefaultHandlerExpand(XML_Parser p,
15735bb6a25fSPoul-Henning Kamp                            XML_DefaultHandler hndl)
15745bb6a25fSPoul-Henning Kamp</pre>
15755bb6a25fSPoul-Henning Kamp<pre class="signature">
15765bb6a25fSPoul-Henning Kamptypedef void
1577220ed979SColeman Kane(XMLCALL *XML_DefaultHandler)(void *userData,
15785bb6a25fSPoul-Henning Kamp                              const XML_Char *s,
15795bb6a25fSPoul-Henning Kamp                              int len);
15805bb6a25fSPoul-Henning Kamp</pre>
15815bb6a25fSPoul-Henning Kamp<p>This sets a default handler, but doesn't inhibit the expansion of
15825bb6a25fSPoul-Henning Kampinternal entity references.  The entity reference will not be passed
15835bb6a25fSPoul-Henning Kampto the default handler.</p>
15845bb6a25fSPoul-Henning Kamp
15855bb6a25fSPoul-Henning Kamp<p>See also <code><a
15865bb6a25fSPoul-Henning Kamphref="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p>
15875bb6a25fSPoul-Henning Kamp</div>
15885bb6a25fSPoul-Henning Kamp
15895bb6a25fSPoul-Henning Kamp<div class="handler">
1590cc68614dSXin LI<h4 id="XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</h4>
1591cc68614dSXin LI<pre class="setter">
1592220ed979SColeman Kanevoid XMLCALL
15935bb6a25fSPoul-Henning KampXML_SetExternalEntityRefHandler(XML_Parser p,
15945bb6a25fSPoul-Henning Kamp                                XML_ExternalEntityRefHandler hndl)
15955bb6a25fSPoul-Henning Kamp</pre>
15965bb6a25fSPoul-Henning Kamp<pre class="signature">
15975bb6a25fSPoul-Henning Kamptypedef int
1598220ed979SColeman Kane(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser p,
15995bb6a25fSPoul-Henning Kamp                                        const XML_Char *context,
16005bb6a25fSPoul-Henning Kamp                                        const XML_Char *base,
16015bb6a25fSPoul-Henning Kamp                                        const XML_Char *systemId,
16025bb6a25fSPoul-Henning Kamp                                        const XML_Char *publicId);
16035bb6a25fSPoul-Henning Kamp</pre>
16045bb6a25fSPoul-Henning Kamp<p>Set an external entity reference handler. This handler is also
16055bb6a25fSPoul-Henning Kampcalled for processing an external DTD subset if parameter entity parsing
16065bb6a25fSPoul-Henning Kampis in effect. (See <a href="#XML_SetParamEntityParsing">
16075bb6a25fSPoul-Henning Kamp<code>XML_SetParamEntityParsing</code></a>.)</p>
16085bb6a25fSPoul-Henning Kamp
1609220ed979SColeman Kane<p>The <code>context</code> parameter specifies the parsing context in
1610220ed979SColeman Kanethe format expected by the <code>context</code> argument to <code><a
1611220ed979SColeman Kanehref="#XML_ExternalEntityParserCreate"
1612220ed979SColeman Kane>XML_ExternalEntityParserCreate</a></code>.  <code>code</code> is
1613220ed979SColeman Kanevalid only until the handler returns, so if the referenced entity is
16144543ef51SXin LIto be parsed later, it must be copied.  <code>context</code> is <code>NULL</code>
1615220ed979SColeman Kaneonly when the entity is a parameter entity, which is how one can
1616220ed979SColeman Kanedifferentiate between general and parameter entities.</p>
16175bb6a25fSPoul-Henning Kamp
1618220ed979SColeman Kane<p>The <code>base</code> parameter is the base to use for relative
1619220ed979SColeman Kanesystem identifiers.  It is set by <code><a
16204543ef51SXin LIhref="#XML_SetBase">XML_SetBase</a></code> and may be <code>NULL</code>. The
1621220ed979SColeman Kane<code>publicId</code> parameter is the public id given in the entity
16224543ef51SXin LIdeclaration and may be <code>NULL</code>.  <code>systemId</code> is the system
16234543ef51SXin LIidentifier specified in the entity declaration and is never <code>NULL</code>.</p>
16245bb6a25fSPoul-Henning Kamp
1625220ed979SColeman Kane<p>There are a couple of ways in which this handler differs from
1626220ed979SColeman Kaneothers.  First, this handler returns a status indicator (an
1627220ed979SColeman Kaneinteger). <code>XML_STATUS_OK</code> should be returned for successful
1628220ed979SColeman Kanehandling of the external entity reference.  Returning
1629220ed979SColeman Kane<code>XML_STATUS_ERROR</code> indicates failure, and causes the
1630220ed979SColeman Kanecalling parser to return an
1631220ed979SColeman Kane<code>XML_ERROR_EXTERNAL_ENTITY_HANDLING</code> error.</p>
16325bb6a25fSPoul-Henning Kamp
1633220ed979SColeman Kane<p>Second, instead of having the user data as its first argument, it
1634220ed979SColeman Kanereceives the parser that encountered the entity reference. This, along
1635220ed979SColeman Kanewith the context parameter, may be used as arguments to a call to
1636220ed979SColeman Kane<code><a href= "#XML_ExternalEntityParserCreate"
1637220ed979SColeman Kane>XML_ExternalEntityParserCreate</a></code>.  Using the returned
1638220ed979SColeman Kaneparser, the body of the external entity can be recursively parsed.</p>
16395bb6a25fSPoul-Henning Kamp
16405bb6a25fSPoul-Henning Kamp<p>Since this handler may be called recursively, it should not be saving
16415bb6a25fSPoul-Henning Kampinformation into global or static variables.</p>
16425bb6a25fSPoul-Henning Kamp</div>
16435bb6a25fSPoul-Henning Kamp
1644cc68614dSXin LI<h4 id="XML_SetExternalEntityRefHandlerArg">XML_SetExternalEntityRefHandlerArg</h4>
1645cc68614dSXin LI<pre class="fcndec">
1646220ed979SColeman Kanevoid XMLCALL
1647220ed979SColeman KaneXML_SetExternalEntityRefHandlerArg(XML_Parser p,
1648220ed979SColeman Kane                                   void *arg)
1649220ed979SColeman Kane</pre>
1650220ed979SColeman Kane<div class="fcndef">
1651220ed979SColeman Kane<p>Set the argument passed to the ExternalEntityRefHandler.  If
16524543ef51SXin LI<code>arg</code> is not <code>NULL</code>, it is the new value passed to the
1653220ed979SColeman Kanehandler set using <code><a href="#XML_SetExternalEntityRefHandler"
1654220ed979SColeman Kane>XML_SetExternalEntityRefHandler</a></code>; if <code>arg</code> is
16554543ef51SXin LI<code>NULL</code>, the argument passed to the handler function will be the parser
1656220ed979SColeman Kaneobject itself.</p>
1657220ed979SColeman Kane
1658220ed979SColeman Kane<p><strong>Note:</strong>
1659220ed979SColeman KaneThe type of <code>arg</code> and the type of the first argument to the
1660220ed979SColeman KaneExternalEntityRefHandler do not match.  This function takes a
1661220ed979SColeman Kane<code>void *</code> to be passed to the handler, while the handler
1662220ed979SColeman Kaneaccepts an <code>XML_Parser</code>.  This is a historical accident,
1663220ed979SColeman Kanebut will not be corrected before Expat 2.0 (at the earliest) to avoid
1664220ed979SColeman Kanecausing compiler warnings for code that's known to work with this
1665220ed979SColeman KaneAPI.  It is the responsibility of the application code to know the
1666220ed979SColeman Kaneactual type of the argument passed to the handler and to manage it
1667220ed979SColeman Kaneproperly.</p>
1668220ed979SColeman Kane</div>
1669220ed979SColeman Kane
16705bb6a25fSPoul-Henning Kamp<div class="handler">
1671cc68614dSXin LI<h4 id="XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</h4>
1672cc68614dSXin LI<pre class="setter">
1673220ed979SColeman Kanevoid XMLCALL
16745bb6a25fSPoul-Henning KampXML_SetSkippedEntityHandler(XML_Parser p,
16755bb6a25fSPoul-Henning Kamp                            XML_SkippedEntityHandler handler)
16765bb6a25fSPoul-Henning Kamp</pre>
16775bb6a25fSPoul-Henning Kamp<pre class="signature">
16785bb6a25fSPoul-Henning Kamptypedef void
1679220ed979SColeman Kane(XMLCALL *XML_SkippedEntityHandler)(void *userData,
16805bb6a25fSPoul-Henning Kamp                                    const XML_Char *entityName,
16815bb6a25fSPoul-Henning Kamp                                    int is_parameter_entity);
16825bb6a25fSPoul-Henning Kamp</pre>
16835bb6a25fSPoul-Henning Kamp<p>Set a skipped entity handler. This is called in two situations:</p>
16845bb6a25fSPoul-Henning Kamp<ol>
16855bb6a25fSPoul-Henning Kamp   <li>An entity reference is encountered for which no declaration
16865bb6a25fSPoul-Henning Kamp       has been read <em>and</em> this is not an error.</li>
16875bb6a25fSPoul-Henning Kamp   <li>An internal entity reference is read, but not expanded, because
16885bb6a25fSPoul-Henning Kamp       <a href="#XML_SetDefaultHandler"><code>XML_SetDefaultHandler</code></a>
16895bb6a25fSPoul-Henning Kamp	   has been called.</li>
16905bb6a25fSPoul-Henning Kamp</ol>
16915bb6a25fSPoul-Henning Kamp<p>The <code>is_parameter_entity</code> argument will be non-zero for
1692cc68614dSXin LIa parameter entity and zero for a general entity.</p> <p>Note: Skipped
16935bb6a25fSPoul-Henning Kampparameter entities in declarations and skipped general entities in
16945bb6a25fSPoul-Henning Kampattribute values cannot be reported, because the event would be out of
16955bb6a25fSPoul-Henning Kampsync with the reporting of the declarations or attribute values</p>
16965bb6a25fSPoul-Henning Kamp</div>
16975bb6a25fSPoul-Henning Kamp
16985bb6a25fSPoul-Henning Kamp<div class="handler">
1699cc68614dSXin LI<h4 id="XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</h4>
1700cc68614dSXin LI<pre class="setter">
1701220ed979SColeman Kanevoid XMLCALL
17025bb6a25fSPoul-Henning KampXML_SetUnknownEncodingHandler(XML_Parser p,
17035bb6a25fSPoul-Henning Kamp                              XML_UnknownEncodingHandler enchandler,
17045bb6a25fSPoul-Henning Kamp			      void *encodingHandlerData)
17055bb6a25fSPoul-Henning Kamp</pre>
17065bb6a25fSPoul-Henning Kamp<pre class="signature">
17075bb6a25fSPoul-Henning Kamptypedef int
1708220ed979SColeman Kane(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
17095bb6a25fSPoul-Henning Kamp                                      const XML_Char *name,
17105bb6a25fSPoul-Henning Kamp                                      XML_Encoding *info);
17115bb6a25fSPoul-Henning Kamp
17125bb6a25fSPoul-Henning Kamptypedef struct {
17135bb6a25fSPoul-Henning Kamp  int map[256];
17145bb6a25fSPoul-Henning Kamp  void *data;
1715220ed979SColeman Kane  int (XMLCALL *convert)(void *data, const char *s);
1716220ed979SColeman Kane  void (XMLCALL *release)(void *data);
17175bb6a25fSPoul-Henning Kamp} XML_Encoding;
17185bb6a25fSPoul-Henning Kamp</pre>
1719220ed979SColeman Kane<p>Set a handler to deal with encodings other than the <a
1720220ed979SColeman Kanehref="#builtin_encodings">built in set</a>. This should be done before
17215bb6a25fSPoul-Henning Kamp<code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href=
17225bb6a25fSPoul-Henning Kamp"#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the
1723220ed979SColeman Kanegiven parser.</p> <p>If the handler knows how to deal with an encoding
1724220ed979SColeman Kanewith the given name, it should fill in the <code>info</code> data
1725220ed979SColeman Kanestructure and return <code>XML_STATUS_OK</code>. Otherwise it
1726220ed979SColeman Kaneshould return <code>XML_STATUS_ERROR</code>. The handler will be called
1727220ed979SColeman Kaneat most once per parsed (external) entity. The optional application
1728220ed979SColeman Kanedata pointer <code>encodingHandlerData</code> will be passed back to
1729220ed979SColeman Kanethe handler.</p>
17305bb6a25fSPoul-Henning Kamp
17310a48773fSEric van Gyzen<p>The map array contains information for every possible leading
17325bb6a25fSPoul-Henning Kampbyte in a byte sequence. If the corresponding value is &gt;= 0, then it's
17335bb6a25fSPoul-Henning Kampa single byte sequence and the byte encodes that Unicode value. If the
17345bb6a25fSPoul-Henning Kampvalue is -1, then that byte is invalid as the initial byte in a sequence.
17355bb6a25fSPoul-Henning KampIf the value is -n, where n is an integer &gt; 1, then n is the number of
17365bb6a25fSPoul-Henning Kampbytes in the sequence and the actual conversion is accomplished by a
17375bb6a25fSPoul-Henning Kampcall to the function pointed at by convert. This function may return -1
17384543ef51SXin LIif the sequence itself is invalid. The convert pointer may be <code>NULL</code> if
17395bb6a25fSPoul-Henning Kampthere are only single byte codes. The data parameter passed to the convert
17405bb6a25fSPoul-Henning Kampfunction is the data pointer from <code>XML_Encoding</code>. The
1741cc68614dSXin LIstring s is <em>NOT</em> null-terminated and points at the sequence of
17425bb6a25fSPoul-Henning Kampbytes to be converted.</p>
17435bb6a25fSPoul-Henning Kamp
17445bb6a25fSPoul-Henning Kamp<p>The function pointed at by <code>release</code> is called by the
17454543ef51SXin LIparser when it is finished with the encoding. It may be <code>NULL</code>.</p>
17465bb6a25fSPoul-Henning Kamp</div>
17475bb6a25fSPoul-Henning Kamp
17485bb6a25fSPoul-Henning Kamp<div class="handler">
1749cc68614dSXin LI<h4 id="XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</h4>
1750cc68614dSXin LI<pre class="setter">
1751220ed979SColeman Kanevoid XMLCALL
17525bb6a25fSPoul-Henning KampXML_SetStartNamespaceDeclHandler(XML_Parser p,
17535bb6a25fSPoul-Henning Kamp			         XML_StartNamespaceDeclHandler start);
17545bb6a25fSPoul-Henning Kamp</pre>
17555bb6a25fSPoul-Henning Kamp<pre class="signature">
17565bb6a25fSPoul-Henning Kamptypedef void
1757220ed979SColeman Kane(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,
17585bb6a25fSPoul-Henning Kamp                                         const XML_Char *prefix,
17595bb6a25fSPoul-Henning Kamp                                         const XML_Char *uri);
17605bb6a25fSPoul-Henning Kamp</pre>
17615bb6a25fSPoul-Henning Kamp<p>Set a handler to be called when a namespace is declared. Namespace
17625bb6a25fSPoul-Henning Kampdeclarations occur inside start tags. But the namespace declaration start
17635bb6a25fSPoul-Henning Kamphandler is called before the start tag handler for each namespace declared
17645bb6a25fSPoul-Henning Kampin that start tag.</p>
17655bb6a25fSPoul-Henning Kamp</div>
17665bb6a25fSPoul-Henning Kamp
17675bb6a25fSPoul-Henning Kamp<div class="handler">
1768cc68614dSXin LI<h4 id="XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</h4>
1769cc68614dSXin LI<pre class="setter">
1770220ed979SColeman Kanevoid XMLCALL
17715bb6a25fSPoul-Henning KampXML_SetEndNamespaceDeclHandler(XML_Parser p,
17725bb6a25fSPoul-Henning Kamp			       XML_EndNamespaceDeclHandler end);
17735bb6a25fSPoul-Henning Kamp</pre>
17745bb6a25fSPoul-Henning Kamp<pre class="signature">
17755bb6a25fSPoul-Henning Kamptypedef void
1776220ed979SColeman Kane(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,
17775bb6a25fSPoul-Henning Kamp                                       const XML_Char *prefix);
17785bb6a25fSPoul-Henning Kamp</pre>
17795bb6a25fSPoul-Henning Kamp<p>Set a handler to be called when leaving the scope of a namespace
17805bb6a25fSPoul-Henning Kampdeclaration. This will be called, for each namespace declaration,
17815bb6a25fSPoul-Henning Kampafter the handler for the end tag of the element in which the
17825bb6a25fSPoul-Henning Kampnamespace was declared.</p>
17835bb6a25fSPoul-Henning Kamp</div>
17845bb6a25fSPoul-Henning Kamp
17855bb6a25fSPoul-Henning Kamp<div class="handler">
1786cc68614dSXin LI<h4 id="XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</h4>
1787cc68614dSXin LI<pre class="setter">
1788220ed979SColeman Kanevoid XMLCALL
17895bb6a25fSPoul-Henning KampXML_SetNamespaceDeclHandler(XML_Parser p,
17905bb6a25fSPoul-Henning Kamp                            XML_StartNamespaceDeclHandler start,
17915bb6a25fSPoul-Henning Kamp                            XML_EndNamespaceDeclHandler end)
17925bb6a25fSPoul-Henning Kamp</pre>
1793220ed979SColeman Kane<p>Sets both namespace declaration handlers with a single call.</p>
17945bb6a25fSPoul-Henning Kamp</div>
17955bb6a25fSPoul-Henning Kamp
17965bb6a25fSPoul-Henning Kamp<div class="handler">
1797cc68614dSXin LI<h4 id="XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</h4>
1798cc68614dSXin LI<pre class="setter">
1799220ed979SColeman Kanevoid XMLCALL
18005bb6a25fSPoul-Henning KampXML_SetXmlDeclHandler(XML_Parser p,
18015bb6a25fSPoul-Henning Kamp		      XML_XmlDeclHandler xmldecl);
18025bb6a25fSPoul-Henning Kamp</pre>
18035bb6a25fSPoul-Henning Kamp<pre class="signature">
18045bb6a25fSPoul-Henning Kamptypedef void
1805220ed979SColeman Kane(XMLCALL *XML_XmlDeclHandler)(void            *userData,
18065bb6a25fSPoul-Henning Kamp                              const XML_Char  *version,
18075bb6a25fSPoul-Henning Kamp                              const XML_Char  *encoding,
18085bb6a25fSPoul-Henning Kamp                              int             standalone);
18095bb6a25fSPoul-Henning Kamp</pre>
18105bb6a25fSPoul-Henning Kamp<p>Sets a handler that is called for XML declarations and also for
18115bb6a25fSPoul-Henning Kamptext declarations discovered in external entities. The way to
18124543ef51SXin LIdistinguish is that the <code>version</code> parameter will be <code>NULL</code>
18134543ef51SXin LIfor text declarations. The <code>encoding</code> parameter may be <code>NULL</code>
18145bb6a25fSPoul-Henning Kampfor an XML declaration. The <code>standalone</code> argument will
18155bb6a25fSPoul-Henning Kampcontain -1, 0, or 1 indicating respectively that there was no
18165bb6a25fSPoul-Henning Kampstandalone parameter in the declaration, that it was given as no, or
18175bb6a25fSPoul-Henning Kampthat it was given as yes.</p>
18185bb6a25fSPoul-Henning Kamp</div>
18195bb6a25fSPoul-Henning Kamp
18205bb6a25fSPoul-Henning Kamp<div class="handler">
1821cc68614dSXin LI<h4 id="XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</h4>
1822cc68614dSXin LI<pre class="setter">
1823220ed979SColeman Kanevoid XMLCALL
18245bb6a25fSPoul-Henning KampXML_SetStartDoctypeDeclHandler(XML_Parser p,
18255bb6a25fSPoul-Henning Kamp			       XML_StartDoctypeDeclHandler start);
18265bb6a25fSPoul-Henning Kamp</pre>
18275bb6a25fSPoul-Henning Kamp<pre class="signature">
18285bb6a25fSPoul-Henning Kamptypedef void
1829220ed979SColeman Kane(XMLCALL *XML_StartDoctypeDeclHandler)(void           *userData,
18305bb6a25fSPoul-Henning Kamp                                       const XML_Char *doctypeName,
18315bb6a25fSPoul-Henning Kamp                                       const XML_Char *sysid,
18325bb6a25fSPoul-Henning Kamp                                       const XML_Char *pubid,
18335bb6a25fSPoul-Henning Kamp                                       int            has_internal_subset);
18345bb6a25fSPoul-Henning Kamp</pre>
18355bb6a25fSPoul-Henning Kamp<p>Set a handler that is called at the start of a DOCTYPE declaration,
18365bb6a25fSPoul-Henning Kampbefore any external or internal subset is parsed. Both <code>sysid</code>
18374543ef51SXin LIand <code>pubid</code> may be <code>NULL</code>. The <code>has_internal_subset</code>
18385bb6a25fSPoul-Henning Kampwill be non-zero if the DOCTYPE declaration has an internal subset.</p>
18395bb6a25fSPoul-Henning Kamp</div>
18405bb6a25fSPoul-Henning Kamp
18415bb6a25fSPoul-Henning Kamp<div class="handler">
1842cc68614dSXin LI<h4 id="XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</h4>
1843cc68614dSXin LI<pre class="setter">
1844220ed979SColeman Kanevoid XMLCALL
18455bb6a25fSPoul-Henning KampXML_SetEndDoctypeDeclHandler(XML_Parser p,
18465bb6a25fSPoul-Henning Kamp			     XML_EndDoctypeDeclHandler end);
18475bb6a25fSPoul-Henning Kamp</pre>
18485bb6a25fSPoul-Henning Kamp<pre class="signature">
18495bb6a25fSPoul-Henning Kamptypedef void
1850220ed979SColeman Kane(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
18515bb6a25fSPoul-Henning Kamp</pre>
18525bb6a25fSPoul-Henning Kamp<p>Set a handler that is called at the end of a DOCTYPE declaration,
18535bb6a25fSPoul-Henning Kampafter parsing any external subset.</p>
18545bb6a25fSPoul-Henning Kamp</div>
18555bb6a25fSPoul-Henning Kamp
18565bb6a25fSPoul-Henning Kamp<div class="handler">
1857cc68614dSXin LI<h4 id="XML_SetDoctypeDeclHandler">XML_SetDoctypeDeclHandler</h4>
1858cc68614dSXin LI<pre class="setter">
1859220ed979SColeman Kanevoid XMLCALL
18605bb6a25fSPoul-Henning KampXML_SetDoctypeDeclHandler(XML_Parser p,
18615bb6a25fSPoul-Henning Kamp			  XML_StartDoctypeDeclHandler start,
18625bb6a25fSPoul-Henning Kamp			  XML_EndDoctypeDeclHandler end);
18635bb6a25fSPoul-Henning Kamp</pre>
18645bb6a25fSPoul-Henning Kamp<p>Set both doctype handlers with one call.</p>
18655bb6a25fSPoul-Henning Kamp</div>
18665bb6a25fSPoul-Henning Kamp
18675bb6a25fSPoul-Henning Kamp<div class="handler">
1868cc68614dSXin LI<h4 id="XML_SetElementDeclHandler">XML_SetElementDeclHandler</h4>
1869cc68614dSXin LI<pre class="setter">
1870220ed979SColeman Kanevoid XMLCALL
18715bb6a25fSPoul-Henning KampXML_SetElementDeclHandler(XML_Parser p,
18725bb6a25fSPoul-Henning Kamp			  XML_ElementDeclHandler eldecl);
18735bb6a25fSPoul-Henning Kamp</pre>
18745bb6a25fSPoul-Henning Kamp<pre class="signature">
18755bb6a25fSPoul-Henning Kamptypedef void
1876220ed979SColeman Kane(XMLCALL *XML_ElementDeclHandler)(void *userData,
18775bb6a25fSPoul-Henning Kamp                                  const XML_Char *name,
18785bb6a25fSPoul-Henning Kamp                                  XML_Content *model);
18795bb6a25fSPoul-Henning Kamp</pre>
18805bb6a25fSPoul-Henning Kamp<pre class="signature">
18815bb6a25fSPoul-Henning Kampenum XML_Content_Type {
18825bb6a25fSPoul-Henning Kamp  XML_CTYPE_EMPTY = 1,
18835bb6a25fSPoul-Henning Kamp  XML_CTYPE_ANY,
18845bb6a25fSPoul-Henning Kamp  XML_CTYPE_MIXED,
18855bb6a25fSPoul-Henning Kamp  XML_CTYPE_NAME,
18865bb6a25fSPoul-Henning Kamp  XML_CTYPE_CHOICE,
18875bb6a25fSPoul-Henning Kamp  XML_CTYPE_SEQ
18885bb6a25fSPoul-Henning Kamp};
18895bb6a25fSPoul-Henning Kamp
18905bb6a25fSPoul-Henning Kampenum XML_Content_Quant {
18915bb6a25fSPoul-Henning Kamp  XML_CQUANT_NONE,
18925bb6a25fSPoul-Henning Kamp  XML_CQUANT_OPT,
18935bb6a25fSPoul-Henning Kamp  XML_CQUANT_REP,
18945bb6a25fSPoul-Henning Kamp  XML_CQUANT_PLUS
18955bb6a25fSPoul-Henning Kamp};
18965bb6a25fSPoul-Henning Kamp
18975bb6a25fSPoul-Henning Kamptypedef struct XML_cp XML_Content;
18985bb6a25fSPoul-Henning Kamp
18995bb6a25fSPoul-Henning Kampstruct XML_cp {
19005bb6a25fSPoul-Henning Kamp  enum XML_Content_Type		type;
19015bb6a25fSPoul-Henning Kamp  enum XML_Content_Quant	quant;
19025bb6a25fSPoul-Henning Kamp  const XML_Char *		name;
19035bb6a25fSPoul-Henning Kamp  unsigned int			numchildren;
19045bb6a25fSPoul-Henning Kamp  XML_Content *			children;
19055bb6a25fSPoul-Henning Kamp};
19065bb6a25fSPoul-Henning Kamp</pre>
19075bb6a25fSPoul-Henning Kamp<p>Sets a handler for element declarations in a DTD. The handler gets
19085bb6a25fSPoul-Henning Kampcalled with the name of the element in the declaration and a pointer
19097ed8e142SXin LIto a structure that contains the element model. It's the user code's
1910627b778dSXin LIresponsibility to free model when finished with via a call to <code>
19117ed8e142SXin LI<a href="#XML_FreeContentModel">XML_FreeContentModel</a></code>.
19127ed8e142SXin LIThere is no need to free the model from the handler, it can be kept
19137ed8e142SXin LIaround and freed at a later stage.</p>
19145bb6a25fSPoul-Henning Kamp
19155bb6a25fSPoul-Henning Kamp<p>The <code>model</code> argument is the root of a tree of
19165bb6a25fSPoul-Henning Kamp<code>XML_Content</code> nodes. If <code>type</code> equals
19175bb6a25fSPoul-Henning Kamp<code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then
19185bb6a25fSPoul-Henning Kamp<code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other
19194543ef51SXin LIfields will be zero or <code>NULL</code>.  If <code>type</code> is
19205bb6a25fSPoul-Henning Kamp<code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be
19215bb6a25fSPoul-Henning Kamp<code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and
19225bb6a25fSPoul-Henning Kamp<code>numchildren</code> will contain the number of elements that are
19235bb6a25fSPoul-Henning Kampallowed to be mixed in and <code>children</code> points to an array of
19245bb6a25fSPoul-Henning Kamp<code>XML_Content</code> structures that will all have type
19255bb6a25fSPoul-Henning KampXML_CTYPE_NAME with no quantification.  Only the root node can be type
19265bb6a25fSPoul-Henning Kamp<code>XML_CTYPE_EMPTY</code>, <code>XML_CTYPE_ANY</code>, or
19275bb6a25fSPoul-Henning Kamp<code>XML_CTYPE_MIXED</code>.</p>
19285bb6a25fSPoul-Henning Kamp
19295bb6a25fSPoul-Henning Kamp<p>For type <code>XML_CTYPE_NAME</code>, the <code>name</code> field
19305bb6a25fSPoul-Henning Kamppoints to the name and the <code>numchildren</code> and
19314543ef51SXin LI<code>children</code> fields will be zero and <code>NULL</code>. The
19325bb6a25fSPoul-Henning Kamp<code>quant</code> field will indicate any quantifiers placed on the
19335bb6a25fSPoul-Henning Kampname.</p>
19345bb6a25fSPoul-Henning Kamp
19355bb6a25fSPoul-Henning Kamp<p>Types <code>XML_CTYPE_CHOICE</code> and <code>XML_CTYPE_SEQ</code>
19365bb6a25fSPoul-Henning Kampindicate a choice or sequence respectively. The
19375bb6a25fSPoul-Henning Kamp<code>numchildren</code> field indicates how many nodes in the choice
19385bb6a25fSPoul-Henning Kampor sequence and <code>children</code> points to the nodes.</p>
19395bb6a25fSPoul-Henning Kamp</div>
19405bb6a25fSPoul-Henning Kamp
19415bb6a25fSPoul-Henning Kamp<div class="handler">
1942cc68614dSXin LI<h4 id="XML_SetAttlistDeclHandler">XML_SetAttlistDeclHandler</h4>
1943cc68614dSXin LI<pre class="setter">
1944220ed979SColeman Kanevoid XMLCALL
19455bb6a25fSPoul-Henning KampXML_SetAttlistDeclHandler(XML_Parser p,
19465bb6a25fSPoul-Henning Kamp                          XML_AttlistDeclHandler attdecl);
19475bb6a25fSPoul-Henning Kamp</pre>
19485bb6a25fSPoul-Henning Kamp<pre class="signature">
19495bb6a25fSPoul-Henning Kamptypedef void
1950220ed979SColeman Kane(XMLCALL *XML_AttlistDeclHandler)(void           *userData,
19515bb6a25fSPoul-Henning Kamp                                  const XML_Char *elname,
19525bb6a25fSPoul-Henning Kamp                                  const XML_Char *attname,
19535bb6a25fSPoul-Henning Kamp                                  const XML_Char *att_type,
19545bb6a25fSPoul-Henning Kamp                                  const XML_Char *dflt,
19555bb6a25fSPoul-Henning Kamp                                  int            isrequired);
19565bb6a25fSPoul-Henning Kamp</pre>
19575bb6a25fSPoul-Henning Kamp<p>Set a handler for attlist declarations in the DTD. This handler is
19585bb6a25fSPoul-Henning Kampcalled for <em>each</em> attribute. So a single attlist declaration
19595bb6a25fSPoul-Henning Kampwith multiple attributes declared will generate multiple calls to this
19605bb6a25fSPoul-Henning Kamphandler. The <code>elname</code> parameter returns the name of the
19615bb6a25fSPoul-Henning Kampelement for which the attribute is being declared. The attribute name
19625bb6a25fSPoul-Henning Kampis in the <code>attname</code> parameter. The attribute type is in the
19635bb6a25fSPoul-Henning Kamp<code>att_type</code> parameter.  It is the string representing the
19645bb6a25fSPoul-Henning Kamptype in the declaration with whitespace removed.</p>
19655bb6a25fSPoul-Henning Kamp
19665bb6a25fSPoul-Henning Kamp<p>The <code>dflt</code> parameter holds the default value. It will be
19674543ef51SXin LI<code>NULL</code> in the case of "#IMPLIED" or "#REQUIRED" attributes. You can
19685bb6a25fSPoul-Henning Kampdistinguish these two cases by checking the <code>isrequired</code>
19695bb6a25fSPoul-Henning Kampparameter, which will be true in the case of "#REQUIRED" attributes.
19705bb6a25fSPoul-Henning KampAttributes which are "#FIXED" will have also have a true
19714543ef51SXin LI<code>isrequired</code>, but they will have the non-<code>NULL</code> fixed value
19725bb6a25fSPoul-Henning Kampin the <code>dflt</code> parameter.</p>
19735bb6a25fSPoul-Henning Kamp</div>
19745bb6a25fSPoul-Henning Kamp
19755bb6a25fSPoul-Henning Kamp<div class="handler">
1976cc68614dSXin LI<h4 id="XML_SetEntityDeclHandler">XML_SetEntityDeclHandler</h4>
1977cc68614dSXin LI<pre class="setter">
1978220ed979SColeman Kanevoid XMLCALL
19795bb6a25fSPoul-Henning KampXML_SetEntityDeclHandler(XML_Parser p,
19805bb6a25fSPoul-Henning Kamp			 XML_EntityDeclHandler handler);
19815bb6a25fSPoul-Henning Kamp</pre>
19825bb6a25fSPoul-Henning Kamp<pre class="signature">
19835bb6a25fSPoul-Henning Kamptypedef void
1984220ed979SColeman Kane(XMLCALL *XML_EntityDeclHandler)(void           *userData,
19855bb6a25fSPoul-Henning Kamp                                 const XML_Char *entityName,
19865bb6a25fSPoul-Henning Kamp                                 int            is_parameter_entity,
19875bb6a25fSPoul-Henning Kamp                                 const XML_Char *value,
19885bb6a25fSPoul-Henning Kamp                                 int            value_length,
19895bb6a25fSPoul-Henning Kamp                                 const XML_Char *base,
19905bb6a25fSPoul-Henning Kamp                                 const XML_Char *systemId,
19915bb6a25fSPoul-Henning Kamp                                 const XML_Char *publicId,
19925bb6a25fSPoul-Henning Kamp                                 const XML_Char *notationName);
19935bb6a25fSPoul-Henning Kamp</pre>
19945bb6a25fSPoul-Henning Kamp<p>Sets a handler that will be called for all entity declarations.
19955bb6a25fSPoul-Henning KampThe <code>is_parameter_entity</code> argument will be non-zero in the
19965bb6a25fSPoul-Henning Kampcase of parameter entities and zero otherwise.</p>
19975bb6a25fSPoul-Henning Kamp
19985bb6a25fSPoul-Henning Kamp<p>For internal entities (<code>&lt;!ENTITY foo "bar"&gt;</code>),
19994543ef51SXin LI<code>value</code> will be non-<code>NULL</code> and <code>systemId</code>,
20004543ef51SXin LI<code>publicId</code>, and <code>notationName</code> will all be <code>NULL</code>.
20014543ef51SXin LIThe value string is <em>not</em> null-terminated; the length is
20025bb6a25fSPoul-Henning Kampprovided in the <code>value_length</code> parameter. Do not use
20035bb6a25fSPoul-Henning Kamp<code>value_length</code> to test for internal entities, since it is
20045bb6a25fSPoul-Henning Kamplegal to have zero-length values. Instead check for whether or not
20054543ef51SXin LI<code>value</code> is <code>NULL</code>.</p> <p>The <code>notationName</code>
20064543ef51SXin LIargument will have a non-<code>NULL</code> value only for unparsed entity
20075bb6a25fSPoul-Henning Kampdeclarations.</p>
20085bb6a25fSPoul-Henning Kamp</div>
20095bb6a25fSPoul-Henning Kamp
20105bb6a25fSPoul-Henning Kamp<div class="handler">
2011cc68614dSXin LI<h4 id="XML_SetUnparsedEntityDeclHandler">XML_SetUnparsedEntityDeclHandler</h4>
2012cc68614dSXin LI<pre class="setter">
2013220ed979SColeman Kanevoid XMLCALL
20145bb6a25fSPoul-Henning KampXML_SetUnparsedEntityDeclHandler(XML_Parser p,
20155bb6a25fSPoul-Henning Kamp                                 XML_UnparsedEntityDeclHandler h)
20165bb6a25fSPoul-Henning Kamp</pre>
20175bb6a25fSPoul-Henning Kamp<pre class="signature">
20185bb6a25fSPoul-Henning Kamptypedef void
2019220ed979SColeman Kane(XMLCALL *XML_UnparsedEntityDeclHandler)(void *userData,
20205bb6a25fSPoul-Henning Kamp                                         const XML_Char *entityName,
20215bb6a25fSPoul-Henning Kamp                                         const XML_Char *base,
20225bb6a25fSPoul-Henning Kamp                                         const XML_Char *systemId,
20235bb6a25fSPoul-Henning Kamp                                         const XML_Char *publicId,
20245bb6a25fSPoul-Henning Kamp                                         const XML_Char *notationName);
20255bb6a25fSPoul-Henning Kamp</pre>
20265bb6a25fSPoul-Henning Kamp<p>Set a handler that receives declarations of unparsed entities. These
20275bb6a25fSPoul-Henning Kampare entity declarations that have a notation (NDATA) field:</p>
20285bb6a25fSPoul-Henning Kamp
20295bb6a25fSPoul-Henning Kamp<div id="eg"><pre>
20305bb6a25fSPoul-Henning Kamp&lt;!ENTITY logo SYSTEM "images/logo.gif" NDATA gif&gt;
20315bb6a25fSPoul-Henning Kamp</pre></div>
20325bb6a25fSPoul-Henning Kamp<p>This handler is obsolete and is provided for backwards
20335bb6a25fSPoul-Henning Kampcompatibility.  Use instead <a href= "#XML_SetEntityDeclHandler"
20345bb6a25fSPoul-Henning Kamp>XML_SetEntityDeclHandler</a>.</p>
20355bb6a25fSPoul-Henning Kamp</div>
20365bb6a25fSPoul-Henning Kamp
20375bb6a25fSPoul-Henning Kamp<div class="handler">
2038cc68614dSXin LI<h4 id="XML_SetNotationDeclHandler">XML_SetNotationDeclHandler</h4>
2039cc68614dSXin LI<pre class="setter">
2040220ed979SColeman Kanevoid XMLCALL
20415bb6a25fSPoul-Henning KampXML_SetNotationDeclHandler(XML_Parser p,
20425bb6a25fSPoul-Henning Kamp                           XML_NotationDeclHandler h)
20435bb6a25fSPoul-Henning Kamp</pre>
20445bb6a25fSPoul-Henning Kamp<pre class="signature">
20455bb6a25fSPoul-Henning Kamptypedef void
2046220ed979SColeman Kane(XMLCALL *XML_NotationDeclHandler)(void *userData,
20475bb6a25fSPoul-Henning Kamp                                   const XML_Char *notationName,
20485bb6a25fSPoul-Henning Kamp                                   const XML_Char *base,
20495bb6a25fSPoul-Henning Kamp                                   const XML_Char *systemId,
20505bb6a25fSPoul-Henning Kamp                                   const XML_Char *publicId);
20515bb6a25fSPoul-Henning Kamp</pre>
20525bb6a25fSPoul-Henning Kamp<p>Set a handler that receives notation declarations.</p>
20535bb6a25fSPoul-Henning Kamp</div>
20545bb6a25fSPoul-Henning Kamp
20555bb6a25fSPoul-Henning Kamp<div class="handler">
2056cc68614dSXin LI<h4 id="XML_SetNotStandaloneHandler">XML_SetNotStandaloneHandler</h4>
2057cc68614dSXin LI<pre class="setter">
2058220ed979SColeman Kanevoid XMLCALL
20595bb6a25fSPoul-Henning KampXML_SetNotStandaloneHandler(XML_Parser p,
20605bb6a25fSPoul-Henning Kamp                            XML_NotStandaloneHandler h)
20615bb6a25fSPoul-Henning Kamp</pre>
20625bb6a25fSPoul-Henning Kamp<pre class="signature">
20635bb6a25fSPoul-Henning Kamptypedef int
2064220ed979SColeman Kane(XMLCALL *XML_NotStandaloneHandler)(void *userData);
20655bb6a25fSPoul-Henning Kamp</pre>
20665bb6a25fSPoul-Henning Kamp<p>Set a handler that is called if the document is not "standalone".
20675bb6a25fSPoul-Henning KampThis happens when there is an external subset or a reference to a
20685bb6a25fSPoul-Henning Kampparameter entity, but does not have standalone set to "yes" in an XML
2069220ed979SColeman Kanedeclaration.  If this handler returns <code>XML_STATUS_ERROR</code>,
2070220ed979SColeman Kanethen the parser will throw an <code>XML_ERROR_NOT_STANDALONE</code>
2071220ed979SColeman Kaneerror.</p>
20725bb6a25fSPoul-Henning Kamp</div>
20735bb6a25fSPoul-Henning Kamp
20745bb6a25fSPoul-Henning Kamp<h3><a name="position">Parse position and error reporting functions</a></h3>
20755bb6a25fSPoul-Henning Kamp
20765bb6a25fSPoul-Henning Kamp<p>These are the functions you'll want to call when the parse
2077220ed979SColeman Kanefunctions return <code>XML_STATUS_ERROR</code> (a parse error has
2078220ed979SColeman Kaneoccurred), although the position reporting functions are useful outside
2079220ed979SColeman Kaneof errors. The position reported is the byte position (in the original
2080220ed979SColeman Kanedocument or entity encoding) of the first of the sequence of
2081220ed979SColeman Kanecharacters that generated the current event (or the error that caused
2082220ed979SColeman Kanethe parse functions to return <code>XML_STATUS_ERROR</code>.)  The
2083cc68614dSXin LIexceptions are callbacks triggered by declarations in the document
2084220ed979SColeman Kaneprologue, in which case they exact position reported is somewhere in the
2085220ed979SColeman Kanerelevant markup, but not necessarily as meaningful as for other
2086220ed979SColeman Kaneevents.</p>
20875bb6a25fSPoul-Henning Kamp
20885bb6a25fSPoul-Henning Kamp<p>The position reporting functions are accurate only outside of the
20895bb6a25fSPoul-Henning KampDTD.  In other words, they usually return bogus information when
20905bb6a25fSPoul-Henning Kampcalled from within a DTD declaration handler.</p>
20915bb6a25fSPoul-Henning Kamp
2092cc68614dSXin LI<h4 id="XML_GetErrorCode">XML_GetErrorCode</h4>
2093cc68614dSXin LI<pre class="fcndec">
2094220ed979SColeman Kaneenum XML_Error XMLCALL
20955bb6a25fSPoul-Henning KampXML_GetErrorCode(XML_Parser p);
20965bb6a25fSPoul-Henning Kamp</pre>
20975bb6a25fSPoul-Henning Kamp<div class="fcndef">
20985bb6a25fSPoul-Henning KampReturn what type of error has occurred.
20995bb6a25fSPoul-Henning Kamp</div>
21005bb6a25fSPoul-Henning Kamp
2101cc68614dSXin LI<h4 id="XML_ErrorString">XML_ErrorString</h4>
2102cc68614dSXin LI<pre class="fcndec">
2103220ed979SColeman Kaneconst XML_LChar * XMLCALL
2104220ed979SColeman KaneXML_ErrorString(enum XML_Error code);
21055bb6a25fSPoul-Henning Kamp</pre>
21065bb6a25fSPoul-Henning Kamp<div class="fcndef">
21075bb6a25fSPoul-Henning KampReturn a string describing the error corresponding to code.
21085bb6a25fSPoul-Henning KampThe code should be one of the enums that can be returned from
21095bb6a25fSPoul-Henning Kamp<code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>.
21105bb6a25fSPoul-Henning Kamp</div>
21115bb6a25fSPoul-Henning Kamp
2112cc68614dSXin LI<h4 id="XML_GetCurrentByteIndex">XML_GetCurrentByteIndex</h4>
2113cc68614dSXin LI<pre class="fcndec">
2114220ed979SColeman KaneXML_Index XMLCALL
21155bb6a25fSPoul-Henning KampXML_GetCurrentByteIndex(XML_Parser p);
21165bb6a25fSPoul-Henning Kamp</pre>
21175bb6a25fSPoul-Henning Kamp<div class="fcndef">
2118220ed979SColeman KaneReturn the byte offset of the position.  This always corresponds to
2119220ed979SColeman Kanethe values returned by <code><a href= "#XML_GetCurrentLineNumber"
2120220ed979SColeman Kane>XML_GetCurrentLineNumber</a></code> and <code><a href=
2121220ed979SColeman Kane"#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>.
21225bb6a25fSPoul-Henning Kamp</div>
21235bb6a25fSPoul-Henning Kamp
2124cc68614dSXin LI<h4 id="XML_GetCurrentLineNumber">XML_GetCurrentLineNumber</h4>
2125cc68614dSXin LI<pre class="fcndec">
2126220ed979SColeman KaneXML_Size XMLCALL
21275bb6a25fSPoul-Henning KampXML_GetCurrentLineNumber(XML_Parser p);
21285bb6a25fSPoul-Henning Kamp</pre>
21295bb6a25fSPoul-Henning Kamp<div class="fcndef">
2130220ed979SColeman KaneReturn the line number of the position.  The first line is reported as
2131220ed979SColeman Kane<code>1</code>.
21325bb6a25fSPoul-Henning Kamp</div>
21335bb6a25fSPoul-Henning Kamp
2134cc68614dSXin LI<h4 id="XML_GetCurrentColumnNumber">XML_GetCurrentColumnNumber</h4>
2135cc68614dSXin LI<pre class="fcndec">
2136220ed979SColeman KaneXML_Size XMLCALL
21375bb6a25fSPoul-Henning KampXML_GetCurrentColumnNumber(XML_Parser p);
21385bb6a25fSPoul-Henning Kamp</pre>
21395bb6a25fSPoul-Henning Kamp<div class="fcndef">
2140*8d485a84SXin LIReturn the <em>offset</em>, from the beginning of the current line, of
2141*8d485a84SXin LIthe position.  The first column is reported as <code>0</code>.
21425bb6a25fSPoul-Henning Kamp</div>
21435bb6a25fSPoul-Henning Kamp
2144cc68614dSXin LI<h4 id="XML_GetCurrentByteCount">XML_GetCurrentByteCount</h4>
2145cc68614dSXin LI<pre class="fcndec">
2146220ed979SColeman Kaneint XMLCALL
21475bb6a25fSPoul-Henning KampXML_GetCurrentByteCount(XML_Parser p);
21485bb6a25fSPoul-Henning Kamp</pre>
21495bb6a25fSPoul-Henning Kamp<div class="fcndef">
21505bb6a25fSPoul-Henning KampReturn the number of bytes in the current event. Returns
21515bb6a25fSPoul-Henning Kamp<code>0</code> if the event is inside a reference to an internal
21525bb6a25fSPoul-Henning Kampentity and for the end-tag event for empty element tags (the later can
21535bb6a25fSPoul-Henning Kampbe used to distinguish empty-element tags from empty elements using
21545bb6a25fSPoul-Henning Kampseparate start and end tags).
21555bb6a25fSPoul-Henning Kamp</div>
21565bb6a25fSPoul-Henning Kamp
2157cc68614dSXin LI<h4 id="XML_GetInputContext">XML_GetInputContext</h4>
2158cc68614dSXin LI<pre class="fcndec">
2159220ed979SColeman Kaneconst char * XMLCALL
21605bb6a25fSPoul-Henning KampXML_GetInputContext(XML_Parser p,
21615bb6a25fSPoul-Henning Kamp                    int *offset,
21625bb6a25fSPoul-Henning Kamp                    int *size);
21635bb6a25fSPoul-Henning Kamp</pre>
21645bb6a25fSPoul-Henning Kamp<div class="fcndef">
21655bb6a25fSPoul-Henning Kamp
21665bb6a25fSPoul-Henning Kamp<p>Returns the parser's input buffer, sets the integer pointed at by
21675bb6a25fSPoul-Henning Kamp<code>offset</code> to the offset within this buffer of the current
21685bb6a25fSPoul-Henning Kampparse position, and set the integer pointed at by <code>size</code> to
21695bb6a25fSPoul-Henning Kampthe size of the returned buffer.</p>
21705bb6a25fSPoul-Henning Kamp
21715bb6a25fSPoul-Henning Kamp<p>This should only be called from within a handler during an active
21725bb6a25fSPoul-Henning Kampparse and the returned buffer should only be referred to from within
21735bb6a25fSPoul-Henning Kampthe handler that made the call. This input buffer contains the
21745bb6a25fSPoul-Henning Kampuntranslated bytes of the input.</p>
21755bb6a25fSPoul-Henning Kamp
21765bb6a25fSPoul-Henning Kamp<p>Only a limited amount of context is kept, so if the event
21775bb6a25fSPoul-Henning Kamptriggering a call spans over a very large amount of input, the actual
21785bb6a25fSPoul-Henning Kampparse position may be before the beginning of the buffer.</p>
2179220ed979SColeman Kane
21804543ef51SXin LI<p>If <code>XML_CONTEXT_BYTES</code> is zero, this will always
21814543ef51SXin LIreturn <code>NULL</code>.</p>
21825bb6a25fSPoul-Henning Kamp</div>
21835bb6a25fSPoul-Henning Kamp
21844543ef51SXin LI<h3><a name="attack-protection">Attack Protection</a><a name="billion-laughs"></a></h3>
2185cc68614dSXin LI
2186cc68614dSXin LI<h4 id="XML_SetBillionLaughsAttackProtectionMaximumAmplification">XML_SetBillionLaughsAttackProtectionMaximumAmplification</h4>
2187cc68614dSXin LI<pre class="fcndec">
2188cc68614dSXin LI/* Added in Expat 2.4.0. */
2189cc68614dSXin LIXML_Bool XMLCALL
2190cc68614dSXin LIXML_SetBillionLaughsAttackProtectionMaximumAmplification(XML_Parser p,
2191cc68614dSXin LI                                                         float maximumAmplificationFactor);
2192cc68614dSXin LI</pre>
2193cc68614dSXin LI<div class="fcndef">
2194cc68614dSXin LI  <p>
2195cc68614dSXin LI    Sets the maximum tolerated amplification factor
2196cc68614dSXin LI    for protection against
2197cc68614dSXin LI    <a href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs attacks</a>
2198cc68614dSXin LI    (default: <code>100.0</code>)
2199cc68614dSXin LI    of parser <code>p</code> to <code>maximumAmplificationFactor</code>, and
2200cc68614dSXin LI    returns <code>XML_TRUE</code> upon success and <code>XML_FALSE</code> upon error.
2201cc68614dSXin LI  </p>
2202cc68614dSXin LI
2203*8d485a84SXin LI  <p>
2204*8d485a84SXin LI    Once the <a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">threshold for activation</a> is reached,
2205*8d485a84SXin LI    the amplification factor is calculated as ..
2206*8d485a84SXin LI  </p>
2207627b778dSXin LI  <pre>amplification := (direct + indirect) / direct</pre>
2208627b778dSXin LI  <p>
2209cc68614dSXin LI    .. while parsing, whereas
2210cc68614dSXin LI    <code>direct</code> is the number of bytes read from the primary document in parsing and
2211cc68614dSXin LI    <code>indirect</code> is the number of bytes added by expanding entities and reading of external DTD files, combined.
2212627b778dSXin LI  </p>
2213cc68614dSXin LI
2214cc68614dSXin LI  <p>For a call to <code>XML_SetBillionLaughsAttackProtectionMaximumAmplification</code> to succeed:</p>
2215cc68614dSXin LI  <ul>
2216cc68614dSXin LI    <li>parser <code>p</code> must be a non-<code>NULL</code> root parser (without any parent parsers) and</li>
2217cc68614dSXin LI    <li><code>maximumAmplificationFactor</code> must be non-<code>NaN</code> and greater than or equal to <code>1.0</code>.</li>
2218cc68614dSXin LI  </ul>
2219cc68614dSXin LI
2220cc68614dSXin LI  <p>
2221cc68614dSXin LI    <strong>Note:</strong>
2222cc68614dSXin LI    If you ever need to increase this value for non-attack payload,
2223cc68614dSXin LI    please <a href="https://github.com/libexpat/libexpat/issues">file a bug report</a>.
2224cc68614dSXin LI  </p>
2225cc68614dSXin LI
2226cc68614dSXin LI  <p>
2227cc68614dSXin LI    <strong>Note:</strong>
2228cc68614dSXin LI    Peak amplifications
2229cc68614dSXin LI    of factor 15,000 for the entire payload and
2230cc68614dSXin LI    of factor 30,000 in the middle of parsing
2231cc68614dSXin LI    have been observed with small benign files in practice.
2232cc68614dSXin LI
2233cc68614dSXin LI    So if you do reduce the maximum allowed amplification,
2234cc68614dSXin LI    please make sure that the activation threshold is still big enough
2235cc68614dSXin LI    to not end up with undesired false positives (i.e. benign files being rejected).
2236cc68614dSXin LI  </p>
2237cc68614dSXin LI</div>
2238cc68614dSXin LI
2239cc68614dSXin LI<h4 id="XML_SetBillionLaughsAttackProtectionActivationThreshold">XML_SetBillionLaughsAttackProtectionActivationThreshold</h4>
2240cc68614dSXin LI<pre class="fcndec">
2241cc68614dSXin LI/* Added in Expat 2.4.0. */
2242cc68614dSXin LIXML_Bool XMLCALL
2243cc68614dSXin LIXML_SetBillionLaughsAttackProtectionActivationThreshold(XML_Parser p,
2244cc68614dSXin LI                                                        unsigned long long activationThresholdBytes);
2245cc68614dSXin LI</pre>
2246cc68614dSXin LI<div class="fcndef">
2247cc68614dSXin LI  <p>
2248cc68614dSXin LI    Sets number of output bytes (including amplification from entity expansion and reading DTD files)
2249cc68614dSXin LI    needed to activate protection against
2250cc68614dSXin LI    <a href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs attacks</a>
2251cc68614dSXin LI    (default: <code>8 MiB</code>)
2252cc68614dSXin LI    of parser <code>p</code> to <code>activationThresholdBytes</code>, and
2253cc68614dSXin LI    returns <code>XML_TRUE</code> upon success and <code>XML_FALSE</code> upon error.
2254cc68614dSXin LI  </p>
2255cc68614dSXin LI
2256cc68614dSXin LI  <p>For a call to <code>XML_SetBillionLaughsAttackProtectionActivationThreshold</code> to succeed:</p>
2257cc68614dSXin LI  <ul>
2258cc68614dSXin LI    <li>parser <code>p</code> must be a non-<code>NULL</code> root parser (without any parent parsers).</li>
2259cc68614dSXin LI  </ul>
2260cc68614dSXin LI
2261cc68614dSXin LI  <p>
2262cc68614dSXin LI    <strong>Note:</strong>
2263cc68614dSXin LI    If you ever need to increase this value for non-attack payload,
2264cc68614dSXin LI    please <a href="https://github.com/libexpat/libexpat/issues">file a bug report</a>.
2265cc68614dSXin LI  </p>
2266cc68614dSXin LI
2267cc68614dSXin LI  <p>
2268cc68614dSXin LI    <strong>Note:</strong>
2269cc68614dSXin LI    Activation thresholds below 4 MiB are known to break support for
2270cc68614dSXin LI    <a href="https://en.wikipedia.org/wiki/Darwin_Information_Typing_Architecture">DITA</a> 1.3 payload
2271cc68614dSXin LI    and are hence not recommended.
2272cc68614dSXin LI  </p>
2273cc68614dSXin LI</div>
2274cc68614dSXin LI
2275627b778dSXin LI<h4 id="XML_SetAllocTrackerMaximumAmplification">XML_SetAllocTrackerMaximumAmplification</h4>
2276627b778dSXin LI<pre class="fcndec">
2277627b778dSXin LI/* Added in Expat 2.7.2. */
2278627b778dSXin LIXML_Bool
2279627b778dSXin LIXML_SetAllocTrackerMaximumAmplification(XML_Parser p,
2280627b778dSXin LI                                        float maximumAmplificationFactor);
2281627b778dSXin LI</pre>
2282627b778dSXin LI<div class="fcndef">
2283627b778dSXin LI  <p>
2284627b778dSXin LI    Sets the maximum tolerated amplification factor
2285627b778dSXin LI    between direct input and bytes of dynamic memory allocated
2286627b778dSXin LI    (default: <code>100.0</code>)
2287627b778dSXin LI    of parser <code>p</code> to <code>maximumAmplificationFactor</code>, and
2288627b778dSXin LI    returns <code>XML_TRUE</code> upon success and <code>XML_FALSE</code> upon error.
2289627b778dSXin LI  </p>
2290627b778dSXin LI
2291627b778dSXin LI  <p>
2292627b778dSXin LI    <strong>Note:</strong>
2293627b778dSXin LI    There are three types of allocations that intentionally bypass tracking and limiting:
2294627b778dSXin LI  </p>
2295627b778dSXin LI  <ul>
2296627b778dSXin LI    <li>
2297627b778dSXin LI      application calls to functions
2298627b778dSXin LI      <code><a href="#XML_MemMalloc">XML_MemMalloc</a></code>
2299627b778dSXin LI      and
2300627b778dSXin LI      <code><a href="#XML_MemRealloc">XML_MemRealloc</a></code>
2301627b778dSXin LI      &mdash;
2302627b778dSXin LI      <em>healthy</em> use of these two functions continues to be a responsibility
2303627b778dSXin LI      of the application using Expat
2304627b778dSXin LI      &mdash;,
2305627b778dSXin LI    </li>
2306627b778dSXin LI    <li>
2307627b778dSXin LI      the main character buffer used by functions
2308627b778dSXin LI      <code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>
2309627b778dSXin LI      and
2310627b778dSXin LI      <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>
2311627b778dSXin LI      (and thus also by plain
2312627b778dSXin LI      <code><a href="#XML_Parse">XML_Parse</a></code>), and
2313627b778dSXin LI    </li>
2314627b778dSXin LI    <li>
2315627b778dSXin LI      the <a href="#XML_SetElementDeclHandler">content model memory</a>
2316627b778dSXin LI      (that is passed to the
2317627b778dSXin LI      <a href="#XML_SetElementDeclHandler">element declaration handler</a>
2318627b778dSXin LI      and freed by a call to
2319627b778dSXin LI      <code><a href="#XML_FreeContentModel">XML_FreeContentModel</a></code>).
2320627b778dSXin LI    </li>
2321627b778dSXin LI  </ul>
2322627b778dSXin LI
2323*8d485a84SXin LI  <p>
2324*8d485a84SXin LI    Once the <a href="#XML_SetAllocTrackerActivationThreshold">threshold for activation</a> is reached,
2325*8d485a84SXin LI    the amplification factor is calculated as ..
2326*8d485a84SXin LI  </p>
2327627b778dSXin LI  <pre>amplification := allocated / direct</pre>
2328627b778dSXin LI  <p>
2329627b778dSXin LI    .. while parsing, whereas
2330627b778dSXin LI    <code>direct</code> is the number of bytes read from the primary document in parsing and
2331627b778dSXin LI    <code>allocated</code> is the number of bytes of dynamic memory allocated in the parser hierarchy.
2332627b778dSXin LI  </p>
2333627b778dSXin LI
2334627b778dSXin LI  <p>For a call to <code>XML_SetAllocTrackerMaximumAmplification</code> to succeed:</p>
2335627b778dSXin LI  <ul>
2336627b778dSXin LI    <li>parser <code>p</code> must be a non-<code>NULL</code> root parser (without any parent parsers) and</li>
2337627b778dSXin LI    <li><code>maximumAmplificationFactor</code> must be non-<code>NaN</code> and greater than or equal to <code>1.0</code>.</li>
2338627b778dSXin LI  </ul>
2339627b778dSXin LI
2340627b778dSXin LI  <p>
2341627b778dSXin LI    <strong>Note:</strong>
2342627b778dSXin LI    If you ever need to increase this value for non-attack payload,
2343627b778dSXin LI    please <a href="https://github.com/libexpat/libexpat/issues">file a bug report</a>.
2344627b778dSXin LI  </p>
2345627b778dSXin LI
2346627b778dSXin LI  <p>
2347627b778dSXin LI    <strong>Note:</strong>
2348*8d485a84SXin LI    Amplifications factors greater than <code>100.0</code> can been observed near the start of parsing
2349627b778dSXin LI    even with benign files in practice.
2350627b778dSXin LI
2351627b778dSXin LI    So if you do reduce the maximum allowed amplification,
2352627b778dSXin LI    please make sure that the activation threshold is still big enough
2353627b778dSXin LI    to not end up with undesired false positives (i.e. benign files being rejected).
2354627b778dSXin LI  </p>
2355627b778dSXin LI</div>
2356627b778dSXin LI
2357627b778dSXin LI<h4 id="XML_SetAllocTrackerActivationThreshold">XML_SetAllocTrackerActivationThreshold</h4>
2358627b778dSXin LI<pre class="fcndec">
2359627b778dSXin LI/* Added in Expat 2.7.2. */
2360627b778dSXin LIXML_Bool
2361627b778dSXin LIXML_SetAllocTrackerActivationThreshold(XML_Parser p,
2362627b778dSXin LI                                       unsigned long long activationThresholdBytes);
2363627b778dSXin LI</pre>
2364627b778dSXin LI<div class="fcndef">
2365627b778dSXin LI  <p>
2366627b778dSXin LI    Sets number of allocated bytes of dynamic memory
2367627b778dSXin LI    needed to activate protection against disproportionate use of RAM
2368627b778dSXin LI    (default: <code>64 MiB</code>)
2369627b778dSXin LI    of parser <code>p</code> to <code>activationThresholdBytes</code>, and
2370627b778dSXin LI    returns <code>XML_TRUE</code> upon success and <code>XML_FALSE</code> upon error.
2371627b778dSXin LI  </p>
2372627b778dSXin LI
2373627b778dSXin LI  <p>
2374627b778dSXin LI    <strong>Note:</strong>
2375627b778dSXin LI    For types of allocations that intentionally bypass tracking and limiting, please see
2376627b778dSXin LI    <code><a href="#XML_SetAllocTrackerMaximumAmplification">XML_SetAllocTrackerMaximumAmplification</a></code>
2377627b778dSXin LI    above.
2378627b778dSXin LI  </p>
2379627b778dSXin LI
2380627b778dSXin LI  <p>For a call to <code>XML_SetAllocTrackerActivationThreshold</code> to succeed:</p>
2381627b778dSXin LI  <ul>
2382627b778dSXin LI    <li>parser <code>p</code> must be a non-<code>NULL</code> root parser (without any parent parsers).</li>
2383627b778dSXin LI  </ul>
2384627b778dSXin LI
2385627b778dSXin LI  <p>
2386627b778dSXin LI    <strong>Note:</strong>
2387627b778dSXin LI    If you ever need to increase this value for non-attack payload,
2388627b778dSXin LI    please <a href="https://github.com/libexpat/libexpat/issues">file a bug report</a>.
2389627b778dSXin LI  </p>
2390627b778dSXin LI</div>
2391627b778dSXin LI
23924543ef51SXin LI<h4 id="XML_SetReparseDeferralEnabled">XML_SetReparseDeferralEnabled</h4>
23934543ef51SXin LI<pre class="fcndec">
23944543ef51SXin LI/* Added in Expat 2.6.0. */
23954543ef51SXin LIXML_Bool XMLCALL
23964543ef51SXin LIXML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
23974543ef51SXin LI</pre>
23984543ef51SXin LI<div class="fcndef">
23994543ef51SXin LI  <p>
24004543ef51SXin LI    Large tokens may require many parse calls before enough data is available for Expat to parse it in full.
24014543ef51SXin LI    If Expat retried parsing the token on every parse call, parsing could take quadratic time.
24024543ef51SXin LI    To avoid this, Expat only retries once a significant amount of new data is available.
24034543ef51SXin LI    This function allows disabling this behavior.
24044543ef51SXin LI  </p>
24054543ef51SXin LI  <p>
24064543ef51SXin LI    The <code>enabled</code> argument should be <code>XML_TRUE</code> or <code>XML_FALSE</code>.
24074543ef51SXin LI  </p>
24084543ef51SXin LI  <p>
24094543ef51SXin LI    Returns <code>XML_TRUE</code> on success, and <code>XML_FALSE</code> on error.
24104543ef51SXin LI  </p>
24114543ef51SXin LI</div>
24124543ef51SXin LI
24135bb6a25fSPoul-Henning Kamp<h3><a name="miscellaneous">Miscellaneous functions</a></h3>
24145bb6a25fSPoul-Henning Kamp
24155bb6a25fSPoul-Henning Kamp<p>The functions in this section either obtain state information from
24160a48773fSEric van Gyzenthe parser or can be used to dynamically set parser options.</p>
24175bb6a25fSPoul-Henning Kamp
2418cc68614dSXin LI<h4 id="XML_SetUserData">XML_SetUserData</h4>
2419cc68614dSXin LI<pre class="fcndec">
2420220ed979SColeman Kanevoid XMLCALL
24215bb6a25fSPoul-Henning KampXML_SetUserData(XML_Parser p,
24225bb6a25fSPoul-Henning Kamp                void *userData);
24235bb6a25fSPoul-Henning Kamp</pre>
24245bb6a25fSPoul-Henning Kamp<div class="fcndef">
24255bb6a25fSPoul-Henning KampThis sets the user data pointer that gets passed to handlers.  It
24265bb6a25fSPoul-Henning Kampoverwrites any previous value for this pointer. Note that the
24275bb6a25fSPoul-Henning Kampapplication is responsible for freeing the memory associated with
24285bb6a25fSPoul-Henning Kamp<code>userData</code> when it is finished with the parser. So if you
24295bb6a25fSPoul-Henning Kampcall this when there's already a pointer there, and you haven't freed
24305bb6a25fSPoul-Henning Kampthe memory associated with it, then you've probably just leaked
24315bb6a25fSPoul-Henning Kampmemory.
24325bb6a25fSPoul-Henning Kamp</div>
24335bb6a25fSPoul-Henning Kamp
2434cc68614dSXin LI<h4 id="XML_GetUserData">XML_GetUserData</h4>
2435cc68614dSXin LI<pre class="fcndec">
2436220ed979SColeman Kanevoid * XMLCALL
24375bb6a25fSPoul-Henning KampXML_GetUserData(XML_Parser p);
24385bb6a25fSPoul-Henning Kamp</pre>
24395bb6a25fSPoul-Henning Kamp<div class="fcndef">
24405bb6a25fSPoul-Henning KampThis returns the user data pointer that gets passed to handlers.
24415bb6a25fSPoul-Henning KampIt is actually implemented as a macro.
24425bb6a25fSPoul-Henning Kamp</div>
24435bb6a25fSPoul-Henning Kamp
2444cc68614dSXin LI<h4 id="XML_UseParserAsHandlerArg">XML_UseParserAsHandlerArg</h4>
2445cc68614dSXin LI<pre class="fcndec">
2446220ed979SColeman Kanevoid XMLCALL
24475bb6a25fSPoul-Henning KampXML_UseParserAsHandlerArg(XML_Parser p);
24485bb6a25fSPoul-Henning Kamp</pre>
24495bb6a25fSPoul-Henning Kamp<div class="fcndef">
2450220ed979SColeman KaneAfter this is called, handlers receive the parser in their
2451220ed979SColeman Kane<code>userData</code> arguments.  The user data can still be obtained
2452220ed979SColeman Kaneusing the <code><a href= "#XML_GetUserData"
2453220ed979SColeman Kane>XML_GetUserData</a></code> function.
24545bb6a25fSPoul-Henning Kamp</div>
24555bb6a25fSPoul-Henning Kamp
2456cc68614dSXin LI<h4 id="XML_SetBase">XML_SetBase</h4>
2457cc68614dSXin LI<pre class="fcndec">
2458220ed979SColeman Kaneenum XML_Status XMLCALL
24595bb6a25fSPoul-Henning KampXML_SetBase(XML_Parser p,
24605bb6a25fSPoul-Henning Kamp            const XML_Char *base);
24615bb6a25fSPoul-Henning Kamp</pre>
24625bb6a25fSPoul-Henning Kamp<div class="fcndef">
24635bb6a25fSPoul-Henning KampSet the base to be used for resolving relative URIs in system
2464220ed979SColeman Kaneidentifiers.  The return value is <code>XML_STATUS_ERROR</code> if
2465220ed979SColeman Kanethere's no memory to store base, otherwise it's
2466220ed979SColeman Kane<code>XML_STATUS_OK</code>.
24675bb6a25fSPoul-Henning Kamp</div>
24685bb6a25fSPoul-Henning Kamp
2469cc68614dSXin LI<h4 id="XML_GetBase">XML_GetBase</h4>
2470cc68614dSXin LI<pre class="fcndec">
2471220ed979SColeman Kaneconst XML_Char * XMLCALL
24725bb6a25fSPoul-Henning KampXML_GetBase(XML_Parser p);
24735bb6a25fSPoul-Henning Kamp</pre>
24745bb6a25fSPoul-Henning Kamp<div class="fcndef">
24755bb6a25fSPoul-Henning KampReturn the base for resolving relative URIs.
24765bb6a25fSPoul-Henning Kamp</div>
24775bb6a25fSPoul-Henning Kamp
2478cc68614dSXin LI<h4 id="XML_GetSpecifiedAttributeCount">XML_GetSpecifiedAttributeCount</h4>
2479cc68614dSXin LI<pre class="fcndec">
2480220ed979SColeman Kaneint XMLCALL
24815bb6a25fSPoul-Henning KampXML_GetSpecifiedAttributeCount(XML_Parser p);
24825bb6a25fSPoul-Henning Kamp</pre>
24835bb6a25fSPoul-Henning Kamp<div class="fcndef">
24845bb6a25fSPoul-Henning KampWhen attributes are reported to the start handler in the atts vector,
24855bb6a25fSPoul-Henning Kampattributes that were explicitly set in the element occur before any
24865bb6a25fSPoul-Henning Kampattributes that receive their value from default information in an
24875bb6a25fSPoul-Henning KampATTLIST declaration. This function returns the number of attributes
24885bb6a25fSPoul-Henning Kampthat were explicitly set times two, thus giving the offset in the
24895bb6a25fSPoul-Henning Kamp<code>atts</code> array passed to the start tag handler of the first
24905bb6a25fSPoul-Henning Kampattribute set due to defaults. It supplies information for the last
24915bb6a25fSPoul-Henning Kampcall to a start handler. If called inside a start handler, then that
24925bb6a25fSPoul-Henning Kampmeans the current call.
24935bb6a25fSPoul-Henning Kamp</div>
24945bb6a25fSPoul-Henning Kamp
2495cc68614dSXin LI<h4 id="XML_GetIdAttributeIndex">XML_GetIdAttributeIndex</h4>
2496cc68614dSXin LI<pre class="fcndec">
2497220ed979SColeman Kaneint XMLCALL
24985bb6a25fSPoul-Henning KampXML_GetIdAttributeIndex(XML_Parser p);
24995bb6a25fSPoul-Henning Kamp</pre>
25005bb6a25fSPoul-Henning Kamp<div class="fcndef">
25015bb6a25fSPoul-Henning KampReturns the index of the ID attribute passed in the atts array in the
25025bb6a25fSPoul-Henning Kamplast call to <code><a href= "#XML_StartElementHandler"
25035bb6a25fSPoul-Henning Kamp>XML_StartElementHandler</a></code>, or -1 if there is no ID
25045bb6a25fSPoul-Henning Kampattribute. If called inside a start handler, then that means the
25055bb6a25fSPoul-Henning Kampcurrent call.
25065bb6a25fSPoul-Henning Kamp</div>
25075bb6a25fSPoul-Henning Kamp
2508cc68614dSXin LI<h4 id="XML_GetAttributeInfo">XML_GetAttributeInfo</h4>
2509cc68614dSXin LI<pre class="fcndec">
2510e3466a89SXin LIconst XML_AttrInfo * XMLCALL
2511e3466a89SXin LIXML_GetAttributeInfo(XML_Parser parser);
2512e3466a89SXin LI</pre>
2513e3466a89SXin LI<pre class="signature">
2514e3466a89SXin LItypedef struct {
2515e3466a89SXin LI  XML_Index  nameStart;  /* Offset to beginning of the attribute name. */
2516e3466a89SXin LI  XML_Index  nameEnd;    /* Offset after the attribute name's last byte. */
2517e3466a89SXin LI  XML_Index  valueStart; /* Offset to beginning of the attribute value. */
2518e3466a89SXin LI  XML_Index  valueEnd;   /* Offset after the attribute value's last byte. */
2519e3466a89SXin LI} XML_AttrInfo;
2520e3466a89SXin LI</pre>
2521e3466a89SXin LI<div class="fcndef">
2522e3466a89SXin LIReturns an array of <code>XML_AttrInfo</code> structures for the
2523e3466a89SXin LIattribute/value pairs passed in the last call to the
2524e3466a89SXin LI<code>XML_StartElementHandler</code> that were specified
2525e3466a89SXin LIin the start-tag rather than defaulted. Each attribute/value pair counts
2526e3466a89SXin LIas 1; thus the number of entries in the array is
2527e3466a89SXin LI<code>XML_GetSpecifiedAttributeCount(parser) / 2</code>.
2528e3466a89SXin LI</div>
2529e3466a89SXin LI
2530cc68614dSXin LI<h4 id="XML_SetEncoding">XML_SetEncoding</h4>
2531cc68614dSXin LI<pre class="fcndec">
2532220ed979SColeman Kaneenum XML_Status XMLCALL
25335bb6a25fSPoul-Henning KampXML_SetEncoding(XML_Parser p,
25345bb6a25fSPoul-Henning Kamp                const XML_Char *encoding);
25355bb6a25fSPoul-Henning Kamp</pre>
25365bb6a25fSPoul-Henning Kamp<div class="fcndef">
25375bb6a25fSPoul-Henning KampSet the encoding to be used by the parser. It is equivalent to
25384543ef51SXin LIpassing a non-<code>NULL</code> encoding argument to the parser creation functions.
25395bb6a25fSPoul-Henning KampIt must not be called after <code><a href= "#XML_Parse"
25405bb6a25fSPoul-Henning Kamp>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer"
25415bb6a25fSPoul-Henning Kamp>XML_ParseBuffer</a></code> have been called on the given parser.
2542220ed979SColeman KaneReturns <code>XML_STATUS_OK</code> on success or
2543220ed979SColeman Kane<code>XML_STATUS_ERROR</code> on error.
25445bb6a25fSPoul-Henning Kamp</div>
25455bb6a25fSPoul-Henning Kamp
2546cc68614dSXin LI<h4 id="XML_SetParamEntityParsing">XML_SetParamEntityParsing</h4>
2547cc68614dSXin LI<pre class="fcndec">
2548220ed979SColeman Kaneint XMLCALL
25495bb6a25fSPoul-Henning KampXML_SetParamEntityParsing(XML_Parser p,
25505bb6a25fSPoul-Henning Kamp                          enum XML_ParamEntityParsing code);
25515bb6a25fSPoul-Henning Kamp</pre>
25525bb6a25fSPoul-Henning Kamp<div class="fcndef">
25535bb6a25fSPoul-Henning KampThis enables parsing of parameter entities, including the external
25545bb6a25fSPoul-Henning Kampparameter entity that is the external DTD subset, according to
25555bb6a25fSPoul-Henning Kamp<code>code</code>.
25565bb6a25fSPoul-Henning KampThe choices for <code>code</code> are:
25575bb6a25fSPoul-Henning Kamp<ul>
25585bb6a25fSPoul-Henning Kamp<li><code>XML_PARAM_ENTITY_PARSING_NEVER</code></li>
25595bb6a25fSPoul-Henning Kamp<li><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></li>
25605bb6a25fSPoul-Henning Kamp<li><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></li>
25615bb6a25fSPoul-Henning Kamp</ul>
2562e3466a89SXin LI<b>Note:</b> If <code>XML_SetParamEntityParsing</code> is called after
2563e3466a89SXin LI<code>XML_Parse</code> or <code>XML_ParseBuffer</code>, then it has
2564e3466a89SXin LIno effect and will always return 0.
2565e3466a89SXin LI</div>
2566e3466a89SXin LI
2567cc68614dSXin LI<h4 id="XML_SetHashSalt">XML_SetHashSalt</h4>
2568cc68614dSXin LI<pre class="fcndec">
2569e3466a89SXin LIint XMLCALL
2570e3466a89SXin LIXML_SetHashSalt(XML_Parser p,
2571e3466a89SXin LI                unsigned long hash_salt);
2572e3466a89SXin LI</pre>
2573e3466a89SXin LI<div class="fcndef">
2574e3466a89SXin LISets the hash salt to use for internal hash calculations.
2575e3466a89SXin LIHelps in preventing DoS attacks based on predicting hash
2576e3466a89SXin LIfunction behavior. In order to have an effect this must be called
2577e3466a89SXin LIbefore parsing has started. Returns 1 if successful, 0 when called
2578e3466a89SXin LIafter <code>XML_Parse</code> or <code>XML_ParseBuffer</code>.
2579be8aff81SXin LI<p><b>Note:</b> This call is optional, as the parser will auto-generate
25806b2c1e49SXin LIa new random salt value if no value has been set at the start of parsing.</p>
2581be8aff81SXin LI<p><b>Note:</b> One should not call <code>XML_SetHashSalt</code> with a
2582be8aff81SXin LIhash salt value of 0, as this value is used as sentinel value to indicate
2583be8aff81SXin LIthat <code>XML_SetHashSalt</code> has <b>not</b> been called. Consequently
2584be8aff81SXin LIsuch a call will have no effect, even if it returns 1.</p>
25855bb6a25fSPoul-Henning Kamp</div>
25865bb6a25fSPoul-Henning Kamp
2587cc68614dSXin LI<h4 id="XML_UseForeignDTD">XML_UseForeignDTD</h4>
2588cc68614dSXin LI<pre class="fcndec">
2589220ed979SColeman Kaneenum XML_Error XMLCALL
25905bb6a25fSPoul-Henning KampXML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
25915bb6a25fSPoul-Henning Kamp</pre>
25925bb6a25fSPoul-Henning Kamp<div class="fcndef">
25935bb6a25fSPoul-Henning Kamp<p>This function allows an application to provide an external subset
25945bb6a25fSPoul-Henning Kampfor the document type declaration for documents which do not specify
25955bb6a25fSPoul-Henning Kampan external subset of their own.  For documents which specify an
25965bb6a25fSPoul-Henning Kampexternal subset in their DOCTYPE declaration, the application-provided
25975bb6a25fSPoul-Henning Kampsubset will be ignored.  If the document does not contain a DOCTYPE
25985bb6a25fSPoul-Henning Kampdeclaration at all and <code>useDTD</code> is true, the
25995bb6a25fSPoul-Henning Kampapplication-provided subset will be parsed, but the
26005bb6a25fSPoul-Henning Kamp<code>startDoctypeDeclHandler</code> and
26015bb6a25fSPoul-Henning Kamp<code>endDoctypeDeclHandler</code> functions, if set, will not be
26025bb6a25fSPoul-Henning Kampcalled.  The setting of parameter entity parsing, controlled using
26035bb6a25fSPoul-Henning Kamp<code><a href= "#XML_SetParamEntityParsing"
26045bb6a25fSPoul-Henning Kamp>XML_SetParamEntityParsing</a></code>, will be honored.</p>
26055bb6a25fSPoul-Henning Kamp
26065bb6a25fSPoul-Henning Kamp<p>The application-provided external subset is read by calling the
26075bb6a25fSPoul-Henning Kampexternal entity reference handler set via <code><a href=
26085bb6a25fSPoul-Henning Kamp"#XML_SetExternalEntityRefHandler"
26095bb6a25fSPoul-Henning Kamp>XML_SetExternalEntityRefHandler</a></code> with both
26104543ef51SXin LI<code>publicId</code> and <code>systemId</code> set to <code>NULL</code>.</p>
26115bb6a25fSPoul-Henning Kamp
26125bb6a25fSPoul-Henning Kamp<p>If this function is called after parsing has begun, it returns
26135bb6a25fSPoul-Henning Kamp<code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores
26145bb6a25fSPoul-Henning Kamp<code>useDTD</code>.  If called when Expat has been compiled without
26155bb6a25fSPoul-Henning KampDTD support, it returns
26165bb6a25fSPoul-Henning Kamp<code>XML_ERROR_FEATURE_REQUIRES_XML_DTD</code>.  Otherwise, it
26175bb6a25fSPoul-Henning Kampreturns <code>XML_ERROR_NONE</code>.</p>
2618220ed979SColeman Kane
2619220ed979SColeman Kane<p><b>Note:</b> For the purpose of checking WFC: Entity Declared, passing
2620220ed979SColeman Kane<code>useDTD == XML_TRUE</code> will make the parser behave as if
2621220ed979SColeman Kanethe document had a DTD with an external subset. This holds true even if
2622220ed979SColeman Kanethe external entity reference handler returns without action.</p>
26235bb6a25fSPoul-Henning Kamp</div>
26245bb6a25fSPoul-Henning Kamp
2625cc68614dSXin LI<h4 id="XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</h4>
2626cc68614dSXin LI<pre class="fcndec">
2627220ed979SColeman Kanevoid XMLCALL
26285bb6a25fSPoul-Henning KampXML_SetReturnNSTriplet(XML_Parser parser,
26295bb6a25fSPoul-Henning Kamp                       int        do_nst);
26305bb6a25fSPoul-Henning Kamp</pre>
26315bb6a25fSPoul-Henning Kamp<div class="fcndef">
26325bb6a25fSPoul-Henning Kamp<p>
26335bb6a25fSPoul-Henning KampThis function only has an effect when using a parser created with
26345bb6a25fSPoul-Henning Kamp<code><a href= "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>,
26355bb6a25fSPoul-Henning Kampi.e. when namespace processing is in effect. The <code>do_nst</code>
26365bb6a25fSPoul-Henning Kampsets whether or not prefixes are returned with names qualified with a
26375bb6a25fSPoul-Henning Kampnamespace prefix. If this function is called with <code>do_nst</code>
26385bb6a25fSPoul-Henning Kampnon-zero, then afterwards namespace qualified names (that is qualified
26395bb6a25fSPoul-Henning Kampwith a prefix as opposed to belonging to a default namespace) are
26405bb6a25fSPoul-Henning Kampreturned as a triplet with the three parts separated by the namespace
26415bb6a25fSPoul-Henning Kampseparator specified when the parser was created.  The order of
26425bb6a25fSPoul-Henning Kampreturned parts is URI, local name, and prefix.</p> <p>If
26435bb6a25fSPoul-Henning Kamp<code>do_nst</code> is zero, then namespaces are reported in the
26445bb6a25fSPoul-Henning Kampdefault manner, URI then local_name separated by the namespace
26455bb6a25fSPoul-Henning Kampseparator.</p>
26465bb6a25fSPoul-Henning Kamp</div>
26475bb6a25fSPoul-Henning Kamp
2648cc68614dSXin LI<h4 id="XML_DefaultCurrent">XML_DefaultCurrent</h4>
2649cc68614dSXin LI<pre class="fcndec">
2650220ed979SColeman Kanevoid XMLCALL
26515bb6a25fSPoul-Henning KampXML_DefaultCurrent(XML_Parser parser);
26525bb6a25fSPoul-Henning Kamp</pre>
26535bb6a25fSPoul-Henning Kamp<div class="fcndef">
26545bb6a25fSPoul-Henning KampThis can be called within a handler for a start element, end element,
26555bb6a25fSPoul-Henning Kampprocessing instruction or character data.  It causes the corresponding
26565bb6a25fSPoul-Henning Kampmarkup to be passed to the default handler set by <code><a
26575bb6a25fSPoul-Henning Kamphref="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or
26585bb6a25fSPoul-Henning Kamp<code><a href="#XML_SetDefaultHandlerExpand"
26595bb6a25fSPoul-Henning Kamp>XML_SetDefaultHandlerExpand</a></code>.  It does nothing if there is
26605bb6a25fSPoul-Henning Kampnot a default handler.
26615bb6a25fSPoul-Henning Kamp</div>
26625bb6a25fSPoul-Henning Kamp
2663cc68614dSXin LI<h4 id="XML_ExpatVersion">XML_ExpatVersion</h4>
2664cc68614dSXin LI<pre class="fcndec">
2665220ed979SColeman KaneXML_LChar * XMLCALL
26665bb6a25fSPoul-Henning KampXML_ExpatVersion();
26675bb6a25fSPoul-Henning Kamp</pre>
26685bb6a25fSPoul-Henning Kamp<div class="fcndef">
26695bb6a25fSPoul-Henning KampReturn the library version as a string (e.g. <code>"expat_1.95.1"</code>).
26705bb6a25fSPoul-Henning Kamp</div>
26715bb6a25fSPoul-Henning Kamp
2672cc68614dSXin LI<h4 id="XML_ExpatVersionInfo">XML_ExpatVersionInfo</h4>
2673cc68614dSXin LI<pre class="fcndec">
2674220ed979SColeman Kanestruct XML_Expat_Version XMLCALL
26755bb6a25fSPoul-Henning KampXML_ExpatVersionInfo();
26765bb6a25fSPoul-Henning Kamp</pre>
26775bb6a25fSPoul-Henning Kamp<pre class="signature">
26785bb6a25fSPoul-Henning Kamptypedef struct {
26795bb6a25fSPoul-Henning Kamp  int major;
26805bb6a25fSPoul-Henning Kamp  int minor;
26815bb6a25fSPoul-Henning Kamp  int micro;
26825bb6a25fSPoul-Henning Kamp} XML_Expat_Version;
26835bb6a25fSPoul-Henning Kamp</pre>
26845bb6a25fSPoul-Henning Kamp<div class="fcndef">
26855bb6a25fSPoul-Henning KampReturn the library version information as a structure.
26865bb6a25fSPoul-Henning KampSome macros are also defined that support compile-time tests of the
26875bb6a25fSPoul-Henning Kamplibrary version:
26885bb6a25fSPoul-Henning Kamp<ul>
26895bb6a25fSPoul-Henning Kamp<li><code>XML_MAJOR_VERSION</code></li>
26905bb6a25fSPoul-Henning Kamp<li><code>XML_MINOR_VERSION</code></li>
26915bb6a25fSPoul-Henning Kamp<li><code>XML_MICRO_VERSION</code></li>
26925bb6a25fSPoul-Henning Kamp</ul>
26935bb6a25fSPoul-Henning KampTesting these constants is currently the best way to determine if
26945bb6a25fSPoul-Henning Kampparticular parts of the Expat API are available.
26955bb6a25fSPoul-Henning Kamp</div>
26965bb6a25fSPoul-Henning Kamp
2697cc68614dSXin LI<h4 id="XML_GetFeatureList">XML_GetFeatureList</h4>
2698cc68614dSXin LI<pre class="fcndec">
2699220ed979SColeman Kaneconst XML_Feature * XMLCALL
27005bb6a25fSPoul-Henning KampXML_GetFeatureList();
27015bb6a25fSPoul-Henning Kamp</pre>
27025bb6a25fSPoul-Henning Kamp<pre class="signature">
27035bb6a25fSPoul-Henning Kampenum XML_FeatureEnum {
27045bb6a25fSPoul-Henning Kamp  XML_FEATURE_END = 0,
27055bb6a25fSPoul-Henning Kamp  XML_FEATURE_UNICODE,
27065bb6a25fSPoul-Henning Kamp  XML_FEATURE_UNICODE_WCHAR_T,
27075bb6a25fSPoul-Henning Kamp  XML_FEATURE_DTD,
27085bb6a25fSPoul-Henning Kamp  XML_FEATURE_CONTEXT_BYTES,
27095bb6a25fSPoul-Henning Kamp  XML_FEATURE_MIN_SIZE,
27105bb6a25fSPoul-Henning Kamp  XML_FEATURE_SIZEOF_XML_CHAR,
2711220ed979SColeman Kane  XML_FEATURE_SIZEOF_XML_LCHAR,
2712220ed979SColeman Kane  XML_FEATURE_NS,
2713220ed979SColeman Kane  XML_FEATURE_LARGE_SIZE
27145bb6a25fSPoul-Henning Kamp};
27155bb6a25fSPoul-Henning Kamp
27165bb6a25fSPoul-Henning Kamptypedef struct {
27175bb6a25fSPoul-Henning Kamp  enum XML_FeatureEnum  feature;
27185bb6a25fSPoul-Henning Kamp  XML_LChar            *name;
27195bb6a25fSPoul-Henning Kamp  long int              value;
27205bb6a25fSPoul-Henning Kamp} XML_Feature;
27215bb6a25fSPoul-Henning Kamp</pre>
27225bb6a25fSPoul-Henning Kamp<div class="fcndef">
27235bb6a25fSPoul-Henning Kamp<p>Returns a list of "feature" records, providing details on how
27245bb6a25fSPoul-Henning KampExpat was configured at compile time.  Most applications should not
27255bb6a25fSPoul-Henning Kampneed to worry about this, but this information is otherwise not
27265bb6a25fSPoul-Henning Kampavailable from Expat.  This function allows code that does need to
27275bb6a25fSPoul-Henning Kampcheck these features to do so at runtime.</p>
27285bb6a25fSPoul-Henning Kamp
27295bb6a25fSPoul-Henning Kamp<p>The return value is an array of <code>XML_Feature</code>,
27305bb6a25fSPoul-Henning Kampterminated by a record with a <code>feature</code> of
27314543ef51SXin LI<code>XML_FEATURE_END</code> and <code>name</code> of <code>NULL</code>,
27325bb6a25fSPoul-Henning Kampidentifying the feature-test macros Expat was compiled with.  Since an
27335bb6a25fSPoul-Henning Kampapplication that requires this kind of information needs to determine
27345bb6a25fSPoul-Henning Kampthe type of character the <code>name</code> points to, records for the
27355bb6a25fSPoul-Henning Kamp<code>XML_FEATURE_SIZEOF_XML_CHAR</code> and
27365bb6a25fSPoul-Henning Kamp<code>XML_FEATURE_SIZEOF_XML_LCHAR</code> will be located at the
27375bb6a25fSPoul-Henning Kampbeginning of the list, followed by <code>XML_FEATURE_UNICODE</code>
27385bb6a25fSPoul-Henning Kampand <code>XML_FEATURE_UNICODE_WCHAR_T</code>, if they are present at
27395bb6a25fSPoul-Henning Kampall.</p>
27405bb6a25fSPoul-Henning Kamp
27415bb6a25fSPoul-Henning Kamp<p>Some features have an associated value.  If there isn't an
27425bb6a25fSPoul-Henning Kampassociated value, the <code>value</code> field is set to 0.  At this
27435bb6a25fSPoul-Henning Kamptime, the following features have been defined to have values:</p>
27445bb6a25fSPoul-Henning Kamp
27455bb6a25fSPoul-Henning Kamp<dl>
27465bb6a25fSPoul-Henning Kamp  <dt><code>XML_FEATURE_SIZEOF_XML_CHAR</code></dt>
27475bb6a25fSPoul-Henning Kamp  <dd>The number of bytes occupied by one <code>XML_Char</code>
27485bb6a25fSPoul-Henning Kamp  character.</dd>
27495bb6a25fSPoul-Henning Kamp  <dt><code>XML_FEATURE_SIZEOF_XML_LCHAR</code></dt>
27505bb6a25fSPoul-Henning Kamp  <dd>The number of bytes occupied by one <code>XML_LChar</code>
27515bb6a25fSPoul-Henning Kamp  character.</dd>
27525bb6a25fSPoul-Henning Kamp  <dt><code>XML_FEATURE_CONTEXT_BYTES</code></dt>
27535bb6a25fSPoul-Henning Kamp  <dd>The maximum number of characters of context which can be
27545bb6a25fSPoul-Henning Kamp  reported by <code><a href= "#XML_GetInputContext"
27555bb6a25fSPoul-Henning Kamp  >XML_GetInputContext</a></code>.</dd>
27565bb6a25fSPoul-Henning Kamp</dl>
27575bb6a25fSPoul-Henning Kamp</div>
27585bb6a25fSPoul-Henning Kamp
2759cc68614dSXin LI<h4 id="XML_FreeContentModel">XML_FreeContentModel</h4>
2760cc68614dSXin LI<pre class="fcndec">
2761220ed979SColeman Kanevoid XMLCALL
2762220ed979SColeman KaneXML_FreeContentModel(XML_Parser parser, XML_Content *model);
2763220ed979SColeman Kane</pre>
2764220ed979SColeman Kane<div class="fcndef">
2765220ed979SColeman KaneFunction to deallocate the <code>model</code> argument passed to the
2766220ed979SColeman Kane<code>XML_ElementDeclHandler</code> callback set using <code><a
2767220ed979SColeman Kanehref="#XML_SetElementDeclHandler" >XML_ElementDeclHandler</a></code>.
2768220ed979SColeman KaneThis function should not be used for any other purpose.
2769220ed979SColeman Kane</div>
2770220ed979SColeman Kane
2771220ed979SColeman Kane<p>The following functions allow external code to share the memory
2772220ed979SColeman Kaneallocator an <code>XML_Parser</code> has been configured to use.  This
2773220ed979SColeman Kaneis especially useful for third-party libraries that interact with a
2774220ed979SColeman Kaneparser object created by application code, or heavily layered
2775220ed979SColeman Kaneapplications.  This can be essential when using dynamically loaded
2776220ed979SColeman Kanelibraries which use different C standard libraries (this can happen on
2777220ed979SColeman KaneWindows, at least).</p>
2778220ed979SColeman Kane
2779cc68614dSXin LI<h4 id="XML_MemMalloc">XML_MemMalloc</h4>
2780cc68614dSXin LI<pre class="fcndec">
2781220ed979SColeman Kanevoid * XMLCALL
2782220ed979SColeman KaneXML_MemMalloc(XML_Parser parser, size_t size);
2783220ed979SColeman Kane</pre>
2784220ed979SColeman Kane<div class="fcndef">
2785220ed979SColeman KaneAllocate <code>size</code> bytes of memory using the allocator the
2786220ed979SColeman Kane<code>parser</code> object has been configured to use.  Returns a
27874543ef51SXin LIpointer to the memory or <code>NULL</code> on failure.  Memory allocated in this
2788220ed979SColeman Kaneway must be freed using <code><a href="#XML_MemFree"
2789220ed979SColeman Kane>XML_MemFree</a></code>.
2790220ed979SColeman Kane</div>
2791220ed979SColeman Kane
2792cc68614dSXin LI<h4 id="XML_MemRealloc">XML_MemRealloc</h4>
2793cc68614dSXin LI<pre class="fcndec">
2794220ed979SColeman Kanevoid * XMLCALL
2795220ed979SColeman KaneXML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
2796220ed979SColeman Kane</pre>
2797220ed979SColeman Kane<div class="fcndef">
2798220ed979SColeman KaneAllocate <code>size</code> bytes of memory using the allocator the
2799220ed979SColeman Kane<code>parser</code> object has been configured to use.
2800220ed979SColeman Kane<code>ptr</code> must point to a block of memory allocated by <code><a
2801220ed979SColeman Kanehref="#XML_MemMalloc" >XML_MemMalloc</a></code> or
28024543ef51SXin LI<code>XML_MemRealloc</code>, or be <code>NULL</code>.  This function tries to
2803220ed979SColeman Kaneexpand the block pointed to by <code>ptr</code> if possible.  Returns
28044543ef51SXin LIa pointer to the memory or <code>NULL</code> on failure.  On success, the original
2805220ed979SColeman Kaneblock has either been expanded or freed.  On failure, the original
2806220ed979SColeman Kaneblock has not been freed; the caller is responsible for freeing the
2807220ed979SColeman Kaneoriginal block.  Memory allocated in this way must be freed using
2808220ed979SColeman Kane<code><a href="#XML_MemFree"
2809220ed979SColeman Kane>XML_MemFree</a></code>.
2810220ed979SColeman Kane</div>
2811220ed979SColeman Kane
2812cc68614dSXin LI<h4 id="XML_MemFree">XML_MemFree</h4>
2813cc68614dSXin LI<pre class="fcndec">
2814220ed979SColeman Kanevoid XMLCALL
2815220ed979SColeman KaneXML_MemFree(XML_Parser parser, void *ptr);
2816220ed979SColeman Kane</pre>
2817220ed979SColeman Kane<div class="fcndef">
2818220ed979SColeman KaneFree a block of memory pointed to by <code>ptr</code>.  The block must
2819220ed979SColeman Kanehave been allocated by <code><a href="#XML_MemMalloc"
28204543ef51SXin LI>XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be <code>NULL</code>.
2821220ed979SColeman Kane</div>
2822220ed979SColeman Kane
28235bb6a25fSPoul-Henning Kamp<hr />
2824cc68614dSXin LI
2825cc68614dSXin LI  <div class="footer">
2826cc68614dSXin LI    Found a bug in the documentation?
2827cc68614dSXin LI    <a href="https://github.com/libexpat/libexpat/issues">Please file a bug report.</a>
2828cc68614dSXin LI  </div>
2829cc68614dSXin LI
2830220ed979SColeman Kane</div>
28315bb6a25fSPoul-Henning Kamp</body>
28325bb6a25fSPoul-Henning Kamp</html>
2833