1104349Sphk<?xml version="1.0" encoding="iso-8859-1"?> 2104349Sphk<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3104349Sphk "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4104349Sphk<html> 5104349Sphk<head> 6104349Sphk<!-- Copyright 1999,2000 Clark Cooper <coopercc@netheaven.com> 7104349Sphk All rights reserved. 8104349Sphk This is free software. You may distribute or modify according to 9104349Sphk the terms of the MIT/X License --> 10104349Sphk <title>Expat XML Parser</title> 11104349Sphk <meta name="author" content="Clark Cooper, coopercc@netheaven.com" /> 12104349Sphk <meta http-equiv="Content-Style-Type" content="text/css" /> 13104349Sphk <link href="style.css" rel="stylesheet" type="text/css" /> 14104349Sphk</head> 15104349Sphk<body> 16178848Scokane <table cellspacing="0" cellpadding="0" width="100%"> 17178848Scokane <tr> 18178848Scokane <td class="corner"><img src="expat.png" alt="(Expat logo)" /></td> 19178848Scokane <td class="banner"><h1>The Expat XML Parser</h1></td> 20178848Scokane </tr> 21178848Scokane <tr> 22178848Scokane <td class="releaseno">Release 2.0.1</td> 23178848Scokane <td></td> 24178848Scokane </tr> 25178848Scokane </table> 26178848Scokane<div class="content"> 27104349Sphk 28104349Sphk<p>Expat is a library, written in C, for parsing XML documents. It's 29104349Sphkthe underlying XML parser for the open source Mozilla project, Perl's 30104349Sphk<code>XML::Parser</code>, Python's <code>xml.parsers.expat</code>, and 31104349Sphkother open-source XML parsers.</p> 32104349Sphk 33104349Sphk<p>This library is the creation of James Clark, who's also given us 34355604Sdelphijgroff (an nroff look-alike), Jade (an implementation of ISO's DSSSL 35104349Sphkstylesheet language for SGML), XP (a Java XML parser package), XT (a 36104349SphkJava XSL engine). James was also the technical lead on the XML 37104349SphkWorking Group at W3C that produced the XML specification.</p> 38104349Sphk 39104349Sphk<p>This is free software, licensed under the <a 40104349Sphkhref="../COPYING">MIT/X Consortium license</a>. You may download it 41104349Sphkfrom <a href="http://www.libexpat.org/">the Expat home page</a>. 42104349Sphk</p> 43104349Sphk 44178848Scokane<p>The bulk of this document was originally commissioned as an article 45178848Scokaneby <a href="http://www.xml.com/">XML.com</a>. They graciously allowed 46178848ScokaneClark Cooper to retain copyright and to distribute it with Expat. 47178848ScokaneThis version has been substantially extended to include documentation 48178848Scokaneon features which have been added since the original article was 49178848Scokanepublished, and additional information on using the original 50178848Scokaneinterface.</p> 51104349Sphk 52104349Sphk<hr /> 53104349Sphk<h2>Table of Contents</h2> 54104349Sphk<ul> 55104349Sphk <li><a href="#overview">Overview</a></li> 56104349Sphk <li><a href="#building">Building and Installing</a></li> 57104349Sphk <li><a href="#using">Using Expat</a></li> 58104349Sphk <li><a href="#reference">Reference</a> 59104349Sphk <ul> 60104349Sphk <li><a href="#creation">Parser Creation Functions</a> 61104349Sphk <ul> 62104349Sphk <li><a href="#XML_ParserCreate">XML_ParserCreate</a></li> 63104349Sphk <li><a href="#XML_ParserCreateNS">XML_ParserCreateNS</a></li> 64104349Sphk <li><a href="#XML_ParserCreate_MM">XML_ParserCreate_MM</a></li> 65104349Sphk <li><a href="#XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</a></li> 66104349Sphk <li><a href="#XML_ParserFree">XML_ParserFree</a></li> 67104349Sphk <li><a href="#XML_ParserReset">XML_ParserReset</a></li> 68104349Sphk </ul> 69104349Sphk </li> 70104349Sphk <li><a href="#parsing">Parsing Functions</a> 71104349Sphk <ul> 72104349Sphk <li><a href="#XML_Parse">XML_Parse</a></li> 73104349Sphk <li><a href="#XML_ParseBuffer">XML_ParseBuffer</a></li> 74104349Sphk <li><a href="#XML_GetBuffer">XML_GetBuffer</a></li> 75178848Scokane <li><a href="#XML_StopParser">XML_StopParser</a></li> 76178848Scokane <li><a href="#XML_ResumeParser">XML_ResumeParser</a></li> 77178848Scokane <li><a href="#XML_GetParsingStatus">XML_GetParsingStatus</a></li> 78104349Sphk </ul> 79104349Sphk </li> 80104349Sphk <li><a href="#setting">Handler Setting Functions</a> 81104349Sphk <ul> 82104349Sphk <li><a href="#XML_SetStartElementHandler">XML_SetStartElementHandler</a></li> 83104349Sphk <li><a href="#XML_SetEndElementHandler">XML_SetEndElementHandler</a></li> 84104349Sphk <li><a href="#XML_SetElementHandler">XML_SetElementHandler</a></li> 85104349Sphk <li><a href="#XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</a></li> 86104349Sphk <li><a href="#XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</a></li> 87104349Sphk <li><a href="#XML_SetCommentHandler">XML_SetCommentHandler</a></li> 88104349Sphk <li><a href="#XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</a></li> 89104349Sphk <li><a href="#XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</a></li> 90104349Sphk <li><a href="#XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</a></li> 91104349Sphk <li><a href="#XML_SetDefaultHandler">XML_SetDefaultHandler</a></li> 92104349Sphk <li><a href="#XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</a></li> 93104349Sphk <li><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></li> 94178848Scokane <li><a href="#XML_SetExternalEntityRefHandlerArg">XML_SetExternalEntityRefHandlerArg</a></li> 95104349Sphk <li><a href="#XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</a></li> 96104349Sphk <li><a href="#XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</a></li> 97104349Sphk <li><a href="#XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</a></li> 98104349Sphk <li><a href="#XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</a></li> 99104349Sphk <li><a href="#XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</a></li> 100104349Sphk <li><a href="#XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</a></li> 101104349Sphk <li><a href="#XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</a></li> 102104349Sphk <li><a href="#XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</a></li> 103104349Sphk <li><a href="#XML_SetDoctypeDeclHandler">XML_SetDoctypeDeclHandler</a></li> 104104349Sphk <li><a href="#XML_SetElementDeclHandler">XML_SetElementDeclHandler</a></li> 105104349Sphk <li><a href="#XML_SetAttlistDeclHandler">XML_SetAttlistDeclHandler</a></li> 106104349Sphk <li><a href="#XML_SetEntityDeclHandler">XML_SetEntityDeclHandler</a></li> 107104349Sphk <li><a href="#XML_SetUnparsedEntityDeclHandler">XML_SetUnparsedEntityDeclHandler</a></li> 108104349Sphk <li><a href="#XML_SetNotationDeclHandler">XML_SetNotationDeclHandler</a></li> 109104349Sphk <li><a href="#XML_SetNotStandaloneHandler">XML_SetNotStandaloneHandler</a></li> 110104349Sphk </ul> 111104349Sphk </li> 112104349Sphk <li><a href="#position">Parse Position and Error Reporting Functions</a> 113104349Sphk <ul> 114104349Sphk <li><a href="#XML_GetErrorCode">XML_GetErrorCode</a></li> 115104349Sphk <li><a href="#XML_ErrorString">XML_ErrorString</a></li> 116104349Sphk <li><a href="#XML_GetCurrentByteIndex">XML_GetCurrentByteIndex</a></li> 117104349Sphk <li><a href="#XML_GetCurrentLineNumber">XML_GetCurrentLineNumber</a></li> 118104349Sphk <li><a href="#XML_GetCurrentColumnNumber">XML_GetCurrentColumnNumber</a></li> 119104349Sphk <li><a href="#XML_GetCurrentByteCount">XML_GetCurrentByteCount</a></li> 120104349Sphk <li><a href="#XML_GetInputContext">XML_GetInputContext</a></li> 121104349Sphk </ul> 122104349Sphk </li> 123104349Sphk <li><a href="#miscellaneous">Miscellaneous Functions</a> 124104349Sphk <ul> 125104349Sphk <li><a href="#XML_SetUserData">XML_SetUserData</a></li> 126104349Sphk <li><a href="#XML_GetUserData">XML_GetUserData</a></li> 127104349Sphk <li><a href="#XML_UseParserAsHandlerArg">XML_UseParserAsHandlerArg</a></li> 128104349Sphk <li><a href="#XML_SetBase">XML_SetBase</a></li> 129104349Sphk <li><a href="#XML_GetBase">XML_GetBase</a></li> 130104349Sphk <li><a href="#XML_GetSpecifiedAttributeCount">XML_GetSpecifiedAttributeCount</a></li> 131104349Sphk <li><a href="#XML_GetIdAttributeIndex">XML_GetIdAttributeIndex</a></li> 132247296Sdelphij <li><a href="#XML_GetAttributeInfo">XML_GetAttributeInfo</a></li> 133104349Sphk <li><a href="#XML_SetEncoding">XML_SetEncoding</a></li> 134104349Sphk <li><a href="#XML_SetParamEntityParsing">XML_SetParamEntityParsing</a></li> 135247296Sdelphij <li><a href="#XML_SetHashSalt">XML_SetHashSalt</a></li> 136104349Sphk <li><a href="#XML_UseForeignDTD">XML_UseForeignDTD</a></li> 137104349Sphk <li><a href="#XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</a></li> 138104349Sphk <li><a href="#XML_DefaultCurrent">XML_DefaultCurrent</a></li> 139104349Sphk <li><a href="#XML_ExpatVersion">XML_ExpatVersion</a></li> 140104349Sphk <li><a href="#XML_ExpatVersionInfo">XML_ExpatVersionInfo</a></li> 141104349Sphk <li><a href="#XML_GetFeatureList">XML_GetFeatureList</a></li> 142178848Scokane <li><a href="#XML_FreeContentModel">XML_FreeContentModel</a></li> 143178848Scokane <li><a href="#XML_MemMalloc">XML_MemMalloc</a></li> 144178848Scokane <li><a href="#XML_MemRealloc">XML_MemRealloc</a></li> 145178848Scokane <li><a href="#XML_MemFree">XML_MemFree</a></li> 146104349Sphk </ul> 147104349Sphk </li> 148104349Sphk </ul> 149104349Sphk </li> 150104349Sphk</ul> 151104349Sphk 152104349Sphk<hr /> 153104349Sphk<h2><a name="overview">Overview</a></h2> 154104349Sphk 155104349Sphk<p>Expat is a stream-oriented parser. You register callback (or 156104349Sphkhandler) functions with the parser and then start feeding it the 157104349Sphkdocument. As the parser recognizes parts of the document, it will 158104349Sphkcall the appropriate handler for that part (if you've registered one.) 159104349SphkThe document is fed to the parser in pieces, so you can start parsing 160104349Sphkbefore you have all the document. This also allows you to parse really 161104349Sphkhuge documents that won't fit into memory.</p> 162104349Sphk 163104349Sphk<p>Expat can be intimidating due to the many kinds of handlers and 164104349Sphkoptions you can set. But you only need to learn four functions in 165104349Sphkorder to do 90% of what you'll want to do with it:</p> 166104349Sphk 167104349Sphk<dl> 168104349Sphk 169104349Sphk<dt><code><a href= "#XML_ParserCreate" 170104349Sphk >XML_ParserCreate</a></code></dt> 171104349Sphk <dd>Create a new parser object.</dd> 172104349Sphk 173104349Sphk<dt><code><a href= "#XML_SetElementHandler" 174104349Sphk >XML_SetElementHandler</a></code></dt> 175104349Sphk <dd>Set handlers for start and end tags.</dd> 176104349Sphk 177104349Sphk<dt><code><a href= "#XML_SetCharacterDataHandler" 178104349Sphk >XML_SetCharacterDataHandler</a></code></dt> 179104349Sphk <dd>Set handler for text.</dd> 180104349Sphk 181104349Sphk<dt><code><a href= "#XML_Parse" 182104349Sphk >XML_Parse</a></code></dt> 183104349Sphk <dd>Pass a buffer full of document to the parser</dd> 184104349Sphk</dl> 185104349Sphk 186104349Sphk<p>These functions and others are described in the <a 187104349Sphkhref="#reference">reference</a> part of this document. The reference 188104349Sphksection also describes in detail the parameters passed to the 189104349Sphkdifferent types of handlers.</p> 190104349Sphk 191104349Sphk<p>Let's look at a very simple example program that only uses 3 of the 192104349Sphkabove functions (it doesn't need to set a character handler.) The 193104349Sphkprogram <a href="../examples/outline.c">outline.c</a> prints an 194104349Sphkelement outline, indenting child elements to distinguish them from the 195104349Sphkparent element that contains them. The start handler does all the 196104349Sphkwork. It prints two indenting spaces for every level of ancestor 197104349Sphkelements, then it prints the element and attribute 198104349Sphkinformation. Finally it increments the global <code>Depth</code> 199104349Sphkvariable.</p> 200104349Sphk 201104349Sphk<pre class="eg"> 202104349Sphkint Depth; 203104349Sphk 204178848Scokanevoid XMLCALL 205104349Sphkstart(void *data, const char *el, const char **attr) { 206104349Sphk int i; 207104349Sphk 208104349Sphk for (i = 0; i < Depth; i++) 209104349Sphk printf(" "); 210104349Sphk 211104349Sphk printf("%s", el); 212104349Sphk 213104349Sphk for (i = 0; attr[i]; i += 2) { 214104349Sphk printf(" %s='%s'", attr[i], attr[i + 1]); 215104349Sphk } 216104349Sphk 217104349Sphk printf("\n"); 218104349Sphk Depth++; 219104349Sphk} /* End of start handler */ 220104349Sphk</pre> 221104349Sphk 222104349Sphk<p>The end tag simply does the bookkeeping work of decrementing 223104349Sphk<code>Depth</code>.</p> 224104349Sphk<pre class="eg"> 225178848Scokanevoid XMLCALL 226104349Sphkend(void *data, const char *el) { 227104349Sphk Depth--; 228104349Sphk} /* End of end handler */ 229104349Sphk</pre> 230104349Sphk 231178848Scokane<p>Note the <code>XMLCALL</code> annotation used for the callbacks. 232178848ScokaneThis is used to ensure that the Expat and the callbacks are using the 233178848Scokanesame calling convention in case the compiler options used for Expat 234178848Scokaneitself and the client code are different. Expat tries not to care 235178848Scokanewhat the default calling convention is, though it may require that it 236178848Scokanebe compiled with a default convention of "cdecl" on some platforms. 237178848ScokaneFor code which uses Expat, however, the calling convention is 238178848Scokanespecified by the <code>XMLCALL</code> annotation on most platforms; 239178848Scokanecallbacks should be defined using this annotation.</p> 240178848Scokane 241178848Scokane<p>The <code>XMLCALL</code> annotation was added in Expat 1.95.7, but 242178848Scokaneexisting working Expat applications don't need to add it (since they 243178848Scokaneare already using the "cdecl" calling convention, or they wouldn't be 244178848Scokaneworking). The annotation is only needed if the default calling 245178848Scokaneconvention may be something other than "cdecl". To use the annotation 246178848Scokanesafely with older versions of Expat, you can conditionally define it 247178848Scokane<em>after</em> including Expat's header file:</p> 248178848Scokane 249178848Scokane<pre class="eg"> 250178848Scokane#include <expat.h> 251178848Scokane 252178848Scokane#ifndef XMLCALL 253178848Scokane#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) 254178848Scokane#define XMLCALL __cdecl 255178848Scokane#elif defined(__GNUC__) 256178848Scokane#define XMLCALL __attribute__((cdecl)) 257178848Scokane#else 258178848Scokane#define XMLCALL 259178848Scokane#endif 260178848Scokane#endif 261178848Scokane</pre> 262178848Scokane 263104349Sphk<p>After creating the parser, the main program just has the job of 264104349Sphkshoveling the document to the parser so that it can do its work.</p> 265104349Sphk 266104349Sphk<hr /> 267104349Sphk<h2><a name="building">Building and Installing Expat</a></h2> 268104349Sphk 269104349Sphk<p>The Expat distribution comes as a compressed (with GNU gzip) tar 270104349Sphkfile. You may download the latest version from <a href= 271104349Sphk"http://sourceforge.net/projects/expat/" >Source Forge</a>. After 272104349Sphkunpacking this, cd into the directory. Then follow either the Win32 273104349Sphkdirections or Unix directions below.</p> 274104349Sphk 275104349Sphk<h3>Building under Win32</h3> 276104349Sphk 277104349Sphk<p>If you're using the GNU compiler under cygwin, follow the Unix 278104349Sphkdirections in the next section. Otherwise if you have Microsoft's 279355604SdelphijDeveloper Studio installed, 280355604Sdelphijyou can use CMake to generate a <code>.sln</code> file, e.g. 281355604Sdelphij<code> 282355604Sdelphijcmake -G"Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=RelWithDebInfo . 283355604Sdelphij</code>, and build Expat using <code>msbuild /m expat.sln</code> after.</p> 284104349Sphk 285104349Sphk<p>Alternatively, you may download the Win32 binary package that 286104349Sphkcontains the "expat.h" include file and a pre-built DLL.</p> 287104349Sphk 288104349Sphk<h3>Building under Unix (or GNU)</h3> 289104349Sphk 290104349Sphk<p>First you'll need to run the configure shell script in order to 291104349Sphkconfigure the Makefiles and headers for your system.</p> 292104349Sphk 293104349Sphk<p>If you're happy with all the defaults that configure picks for you, 294104349Sphkand you have permission on your system to install into /usr/local, you 295104349Sphkcan install Expat with this sequence of commands:</p> 296104349Sphk 297104349Sphk<pre class="eg"> 298178848Scokane./configure 299178848Scokanemake 300178848Scokanemake install 301104349Sphk</pre> 302104349Sphk 303104349Sphk<p>There are some options that you can provide to this script, but the 304104349Sphkonly one we'll mention here is the <code>--prefix</code> option. You 305104349Sphkcan find out all the options available by running configure with just 306104349Sphkthe <code>--help</code> option.</p> 307104349Sphk 308104349Sphk<p>By default, the configure script sets things up so that the library 309104349Sphkgets installed in <code>/usr/local/lib</code> and the associated 310104349Sphkheader file in <code>/usr/local/include</code>. But if you were to 311104349Sphkgive the option, <code>--prefix=/home/me/mystuff</code>, then the 312104349Sphklibrary and header would get installed in 313104349Sphk<code>/home/me/mystuff/lib</code> and 314104349Sphk<code>/home/me/mystuff/include</code> respectively.</p> 315104349Sphk 316178848Scokane<h3>Configuring Expat Using the Pre-Processor</h3> 317178848Scokane 318178848Scokane<p>Expat's feature set can be configured using a small number of 319178848Scokanepre-processor definitions. The definition of this symbols does not 320178848Scokaneaffect the set of entry points for Expat, only the behavior of the API 321178848Scokaneand the definition of character types in the case of 322178848Scokane<code>XML_UNICODE_WCHAR_T</code>. The symbols are:</p> 323178848Scokane 324178848Scokane<dl class="cpp-symbols"> 325178848Scokane<dt>XML_DTD</dt> 326178848Scokane<dd>Include support for using and reporting DTD-based content. If 327178848Scokanethis is defined, default attribute values from an external DTD subset 328178848Scokaneare reported and attribute value normalization occurs based on the 329178848Scokanetype of attributes defined in the external subset. Without 330178848Scokanethis, Expat has a smaller memory footprint and can be faster, but will 331178848Scokanenot load external entities or process conditional sections. This does 332178848Scokanenot affect the set of functions available in the API.</dd> 333178848Scokane 334178848Scokane<dt>XML_NS</dt> 335178848Scokane<dd>When defined, support for the <cite><a href= 336178848Scokane"http://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite> 337178848Scokanespecification is included.</dd> 338178848Scokane 339178848Scokane<dt>XML_UNICODE</dt> 340178848Scokane<dd>When defined, character data reported to the application is 341178848Scokaneencoded in UTF-16 using wide characters of the type 342178848Scokane<code>XML_Char</code>. This is implied if 343178848Scokane<code>XML_UNICODE_WCHAR_T</code> is defined.</dd> 344178848Scokane 345178848Scokane<dt>XML_UNICODE_WCHAR_T</dt> 346178848Scokane<dd>If defined, causes the <code>XML_Char</code> character type to be 347178848Scokanedefined using the <code>wchar_t</code> type; otherwise, <code>unsigned 348178848Scokaneshort</code> is used. Defining this implies 349178848Scokane<code>XML_UNICODE</code>.</dd> 350178848Scokane 351178848Scokane<dt>XML_LARGE_SIZE</dt> 352178848Scokane<dd>If defined, causes the <code>XML_Size</code> and <code>XML_Index</code> 353178848Scokaneinteger types to be at least 64 bits in size. This is intended to support 354178848Scokaneprocessing of very large input streams, where the return values of 355178848Scokane<code><a href="#XML_GetCurrentByteIndex" >XML_GetCurrentByteIndex</a></code>, 356178848Scokane<code><a href="#XML_GetCurrentLineNumber" >XML_GetCurrentLineNumber</a></code> and 357178848Scokane<code><a href="#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code> 358178848Scokanecould overflow. It may not be supported by all compilers, and is turned 359178848Scokaneoff by default.</dd> 360178848Scokane 361178848Scokane<dt>XML_CONTEXT_BYTES</dt> 362178848Scokane<dd>The number of input bytes of markup context which the parser will 363178848Scokaneensure are available for reporting via <code><a href= 364178848Scokane"#XML_GetInputContext" >XML_GetInputContext</a></code>. This is 365355604Sdelphijnormally set to 1024, and must be set to a positive integer. If this 366178848Scokaneis not defined, the input context will not be available and <code><a 367178848Scokanehref= "#XML_GetInputContext" >XML_GetInputContext</a></code> will 368178848Scokanealways report NULL. Without this, Expat has a smaller memory 369178848Scokanefootprint and can be faster.</dd> 370178848Scokane 371178848Scokane<dt>XML_STATIC</dt> 372178848Scokane<dd>On Windows, this should be set if Expat is going to be linked 373178848Scokanestatically with the code that calls it; this is required to get all 374178848Scokanethe right MSVC magic annotations correct. This is ignored on other 375178848Scokaneplatforms.</dd> 376247296Sdelphij 377247296Sdelphij<dt>XML_ATTR_INFO</dt> 378355604Sdelphij<dd>If defined, makes the additional function <code><a href= 379247296Sdelphij"#XML_GetAttributeInfo" >XML_GetAttributeInfo</a></code> available 380247296Sdelphijfor reporting attribute byte offsets.</dd> 381178848Scokane</dl> 382178848Scokane 383104349Sphk<hr /> 384104349Sphk<h2><a name="using">Using Expat</a></h2> 385104349Sphk 386104349Sphk<h3>Compiling and Linking Against Expat</h3> 387104349Sphk 388104349Sphk<p>Unless you installed Expat in a location not expected by your 389104349Sphkcompiler and linker, all you have to do to use Expat in your programs 390104349Sphkis to include the Expat header (<code>#include <expat.h></code>) 391104349Sphkin your files that make calls to it and to tell the linker that it 392104349Sphkneeds to link against the Expat library. On Unix systems, this would 393104349Sphkusually be done with the <code>-lexpat</code> argument. Otherwise, 394104349Sphkyou'll need to tell the compiler where to look for the Expat header 395104349Sphkand the linker where to find the Expat library. You may also need to 396178848Scokanetake steps to tell the operating system where to find this library at 397104349Sphkrun time.</p> 398104349Sphk 399104349Sphk<p>On a Unix-based system, here's what a Makefile might look like when 400104349SphkExpat is installed in a standard location:</p> 401104349Sphk 402104349Sphk<pre class="eg"> 403104349SphkCC=cc 404104349SphkLDFLAGS= 405104349SphkLIBS= -lexpat 406104349Sphkxmlapp: xmlapp.o 407104349Sphk $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS) 408104349Sphk</pre> 409104349Sphk 410104349Sphk<p>If you installed Expat in, say, <code>/home/me/mystuff</code>, then 411104349Sphkthe Makefile would look like this:</p> 412104349Sphk 413104349Sphk<pre class="eg"> 414104349SphkCC=cc 415104349SphkCFLAGS= -I/home/me/mystuff/include 416104349SphkLDFLAGS= 417104349SphkLIBS= -L/home/me/mystuff/lib -lexpat 418104349Sphkxmlapp: xmlapp.o 419104349Sphk $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS) 420104349Sphk</pre> 421104349Sphk 422104349Sphk<p>You'd also have to set the environment variable 423104349Sphk<code>LD_LIBRARY_PATH</code> to <code>/home/me/mystuff/lib</code> (or 424104349Sphkto <code>${LD_LIBRARY_PATH}:/home/me/mystuff/lib</code> if 425104349SphkLD_LIBRARY_PATH already has some directories in it) in order to run 426104349Sphkyour application.</p> 427104349Sphk 428104349Sphk<h3>Expat Basics</h3> 429104349Sphk 430104349Sphk<p>As we saw in the example in the overview, the first step in parsing 431104349Sphkan XML document with Expat is to create a parser object. There are <a 432104349Sphkhref="#creation">three functions</a> in the Expat API for creating a 433104349Sphkparser object. However, only two of these (<code><a href= 434104349Sphk"#XML_ParserCreate" >XML_ParserCreate</a></code> and <code><a href= 435104349Sphk"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>) can be used for 436104349Sphkconstructing a parser for a top-level document. The object returned 437104349Sphkby these functions is an opaque pointer (i.e. "expat.h" declares it as 438104349Sphkvoid *) to data with further internal structure. In order to free the 439104349Sphkmemory associated with this object you must call <code><a href= 440104349Sphk"#XML_ParserFree" >XML_ParserFree</a></code>. Note that if you have 441178848Scokaneprovided any <a href="#userdata">user data</a> that gets stored in the 442104349Sphkparser, then your application is responsible for freeing it prior to 443104349Sphkcalling <code>XML_ParserFree</code>.</p> 444104349Sphk 445104349Sphk<p>The objects returned by the parser creation functions are good for 446104349Sphkparsing only one XML document or external parsed entity. If your 447104349Sphkapplication needs to parse many XML documents, then it needs to create 448104349Sphka parser object for each one. The best way to deal with this is to 449104349Sphkcreate a higher level object that contains all the default 450104349Sphkinitialization you want for your parser objects.</p> 451104349Sphk 452104349Sphk<p>Walking through a document hierarchy with a stream oriented parser 453104349Sphkwill require a good stack mechanism in order to keep track of current 454104349Sphkcontext. For instance, to answer the simple question, "What element 455104349Sphkdoes this text belong to?" requires a stack, since the parser may have 456104349Sphkdescended into other elements that are children of the current one and 457104349Sphkhas encountered this text on the way out.</p> 458104349Sphk 459104349Sphk<p>The things you're likely to want to keep on a stack are the 460104349Sphkcurrently opened element and it's attributes. You push this 461104349Sphkinformation onto the stack in the start handler and you pop it off in 462104349Sphkthe end handler.</p> 463104349Sphk 464104349Sphk<p>For some tasks, it is sufficient to just keep information on what 465104349Sphkthe depth of the stack is (or would be if you had one.) The outline 466104349Sphkprogram shown above presents one example. Another such task would be 467104349Sphkskipping over a complete element. When you see the start tag for the 468104349Sphkelement you want to skip, you set a skip flag and record the depth at 469104349Sphkwhich the element started. When the end tag handler encounters the 470104349Sphksame depth, the skipped element has ended and the flag may be 471104349Sphkcleared. If you follow the convention that the root element starts at 472104349Sphk1, then you can use the same variable for skip flag and skip 473104349Sphkdepth.</p> 474104349Sphk 475104349Sphk<pre class="eg"> 476104349Sphkvoid 477104349Sphkinit_info(Parseinfo *info) { 478104349Sphk info->skip = 0; 479104349Sphk info->depth = 1; 480104349Sphk /* Other initializations here */ 481104349Sphk} /* End of init_info */ 482104349Sphk 483178848Scokanevoid XMLCALL 484104349Sphkrawstart(void *data, const char *el, const char **attr) { 485104349Sphk Parseinfo *inf = (Parseinfo *) data; 486104349Sphk 487104349Sphk if (! inf->skip) { 488104349Sphk if (should_skip(inf, el, attr)) { 489104349Sphk inf->skip = inf->depth; 490104349Sphk } 491104349Sphk else 492104349Sphk start(inf, el, attr); /* This does rest of start handling */ 493104349Sphk } 494104349Sphk 495104349Sphk inf->depth++; 496104349Sphk} /* End of rawstart */ 497104349Sphk 498178848Scokanevoid XMLCALL 499104349Sphkrawend(void *data, const char *el) { 500104349Sphk Parseinfo *inf = (Parseinfo *) data; 501104349Sphk 502104349Sphk inf->depth--; 503104349Sphk 504104349Sphk if (! inf->skip) 505104349Sphk end(inf, el); /* This does rest of end handling */ 506104349Sphk 507104349Sphk if (inf->skip == inf->depth) 508104349Sphk inf->skip = 0; 509104349Sphk} /* End rawend */ 510104349Sphk</pre> 511104349Sphk 512104349Sphk<p>Notice in the above example the difference in how depth is 513104349Sphkmanipulated in the start and end handlers. The end tag handler should 514104349Sphkbe the mirror image of the start tag handler. This is necessary to 515104349Sphkproperly model containment. Since, in the start tag handler, we 516104349Sphkincremented depth <em>after</em> the main body of start tag code, then 517104349Sphkin the end handler, we need to manipulate it <em>before</em> the main 518104349Sphkbody. If we'd decided to increment it first thing in the start 519104349Sphkhandler, then we'd have had to decrement it last thing in the end 520104349Sphkhandler.</p> 521104349Sphk 522104349Sphk<h3 id="userdata">Communicating between handlers</h3> 523104349Sphk 524104349Sphk<p>In order to be able to pass information between different handlers 525104349Sphkwithout using globals, you'll need to define a data structure to hold 526104349Sphkthe shared variables. You can then tell Expat (with the <code><a href= 527104349Sphk"#XML_SetUserData" >XML_SetUserData</a></code> function) to pass a 528178848Scokanepointer to this structure to the handlers. This is the first 529178848Scokaneargument received by most handlers. In the <a href="#reference" 530178848Scokane>reference section</a>, an argument to a callback function is named 531178848Scokane<code>userData</code> and have type <code>void *</code> if the user 532178848Scokanedata is passed; it will have the type <code>XML_Parser</code> if the 533178848Scokaneparser itself is passed. When the parser is passed, the user data may 534178848Scokanebe retrieved using <code><a href="#XML_GetUserData" 535178848Scokane>XML_GetUserData</a></code>.</p> 536104349Sphk 537178848Scokane<p>One common case where multiple calls to a single handler may need 538178848Scokaneto communicate using an application data structure is the case when 539178848Scokanecontent passed to the character data handler (set by <code><a href= 540178848Scokane"#XML_SetCharacterDataHandler" 541178848Scokane>XML_SetCharacterDataHandler</a></code>) needs to be accumulated. A 542178848Scokanecommon first-time mistake with any of the event-oriented interfaces to 543178848Scokanean XML parser is to expect all the text contained in an element to be 544178848Scokanereported by a single call to the character data handler. Expat, like 545178848Scokanemany other XML parsers, reports such data as a sequence of calls; 546178848Scokanethere's no way to know when the end of the sequence is reached until a 547178848Scokanedifferent callback is made. A buffer referenced by the user data 548178848Scokanestructure proves both an effective and convenient place to accumulate 549178848Scokanecharacter data.</p> 550178848Scokane 551178848Scokane<!-- XXX example needed here --> 552178848Scokane 553178848Scokane 554104349Sphk<h3>XML Version</h3> 555104349Sphk 556104349Sphk<p>Expat is an XML 1.0 parser, and as such never complains based on 557104349Sphkthe value of the <code>version</code> pseudo-attribute in the XML 558104349Sphkdeclaration, if present.</p> 559104349Sphk 560104349Sphk<p>If an application needs to check the version number (to support 561104349Sphkalternate processing), it should use the <code><a href= 562104349Sphk"#XML_SetXmlDeclHandler" >XML_SetXmlDeclHandler</a></code> function to 563104349Sphkset a handler that uses the information in the XML declaration to 564104349Sphkdetermine what to do. This example shows how to check that only a 565104349Sphkversion number of <code>"1.0"</code> is accepted:</p> 566104349Sphk 567104349Sphk<pre class="eg"> 568104349Sphkstatic int wrong_version; 569104349Sphkstatic XML_Parser parser; 570104349Sphk 571178848Scokanestatic void XMLCALL 572104349Sphkxmldecl_handler(void *userData, 573104349Sphk const XML_Char *version, 574104349Sphk const XML_Char *encoding, 575104349Sphk int standalone) 576104349Sphk{ 577104349Sphk static const XML_Char Version_1_0[] = {'1', '.', '0', 0}; 578104349Sphk 579104349Sphk int i; 580104349Sphk 581104349Sphk for (i = 0; i < (sizeof(Version_1_0) / sizeof(Version_1_0[0])); ++i) { 582104349Sphk if (version[i] != Version_1_0[i]) { 583104349Sphk wrong_version = 1; 584104349Sphk /* also clear all other handlers: */ 585104349Sphk XML_SetCharacterDataHandler(parser, NULL); 586104349Sphk ... 587104349Sphk return; 588104349Sphk } 589104349Sphk } 590104349Sphk ... 591104349Sphk} 592104349Sphk</pre> 593104349Sphk 594104349Sphk<h3>Namespace Processing</h3> 595104349Sphk 596104349Sphk<p>When the parser is created using the <code><a href= 597104349Sphk"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>, function, Expat 598104349Sphkperforms namespace processing. Under namespace processing, Expat 599104349Sphkconsumes <code>xmlns</code> and <code>xmlns:...</code> attributes, 600104349Sphkwhich declare namespaces for the scope of the element in which they 601104349Sphkoccur. This means that your start handler will not see these 602104349Sphkattributes. Your application can still be informed of these 603104349Sphkdeclarations by setting namespace declaration handlers with <a href= 604104349Sphk"#XML_SetNamespaceDeclHandler" 605104349Sphk><code>XML_SetNamespaceDeclHandler</code></a>.</p> 606104349Sphk 607104349Sphk<p>Element type and attribute names that belong to a given namespace 608104349Sphkare passed to the appropriate handler in expanded form. By default 609104349Sphkthis expanded form is a concatenation of the namespace URI, the 610104349Sphkseparator character (which is the 2nd argument to <code><a href= 611104349Sphk"#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>), and the local 612104349Sphkname (i.e. the part after the colon). Names with undeclared prefixes 613178848Scokaneare not well-formed when namespace processing is enabled, and will 614178848Scokanetrigger an error. Unprefixed attribute names are never expanded, 615104349Sphkand unprefixed element names are only expanded when they are in the 616104349Sphkscope of a default namespace.</p> 617104349Sphk 618178848Scokane<p>However if <code><a href= "#XML_SetReturnNSTriplet" 619104349Sphk>XML_SetReturnNSTriplet</a></code> has been called with a non-zero 620104349Sphk<code>do_nst</code> parameter, then the expanded form for names with 621104349Sphkan explicit prefix is a concatenation of: URI, separator, local name, 622104349Sphkseparator, prefix.</p> 623104349Sphk 624104349Sphk<p>You can set handlers for the start of a namespace declaration and 625104349Sphkfor the end of a scope of a declaration with the <code><a href= 626104349Sphk"#XML_SetNamespaceDeclHandler" >XML_SetNamespaceDeclHandler</a></code> 627104349Sphkfunction. The StartNamespaceDeclHandler is called prior to the start 628178848Scokanetag handler and the EndNamespaceDeclHandler is called after the 629104349Sphkcorresponding end tag that ends the namespace's scope. The namespace 630104349Sphkstart handler gets passed the prefix and URI for the namespace. For a 631104349Sphkdefault namespace declaration (xmlns='...'), the prefix will be null. 632104349SphkThe URI will be null for the case where the default namespace is being 633104349Sphkunset. The namespace end handler just gets the prefix for the closing 634104349Sphkscope.</p> 635104349Sphk 636104349Sphk<p>These handlers are called for each declaration. So if, for 637104349Sphkinstance, a start tag had three namespace declarations, then the 638104349SphkStartNamespaceDeclHandler would be called three times before the start 639104349Sphktag handler is called, once for each declaration.</p> 640104349Sphk 641104349Sphk<h3>Character Encodings</h3> 642104349Sphk 643104349Sphk<p>While XML is based on Unicode, and every XML processor is required 644104349Sphkto recognized UTF-8 and UTF-16 (1 and 2 byte encodings of Unicode), 645104349Sphkother encodings may be declared in XML documents or entities. For the 646104349Sphkmain document, an XML declaration may contain an encoding 647104349Sphkdeclaration:</p> 648104349Sphk<pre> 649104349Sphk<?xml version="1.0" encoding="ISO-8859-2"?> 650104349Sphk</pre> 651104349Sphk 652104349Sphk<p>External parsed entities may begin with a text declaration, which 653104349Sphklooks like an XML declaration with just an encoding declaration:</p> 654104349Sphk<pre> 655104349Sphk<?xml encoding="Big5"?> 656104349Sphk</pre> 657104349Sphk 658104349Sphk<p>With Expat, you may also specify an encoding at the time of 659104349Sphkcreating a parser. This is useful when the encoding information may 660104349Sphkcome from a source outside the document itself (like a higher level 661104349Sphkprotocol.)</p> 662104349Sphk 663104349Sphk<p><a name="builtin_encodings"></a>There are four built-in encodings 664104349Sphkin Expat:</p> 665104349Sphk<ul> 666104349Sphk<li>UTF-8</li> 667104349Sphk<li>UTF-16</li> 668104349Sphk<li>ISO-8859-1</li> 669104349Sphk<li>US-ASCII</li> 670104349Sphk</ul> 671104349Sphk 672104349Sphk<p>Anything else discovered in an encoding declaration or in the 673104349Sphkprotocol encoding specified in the parser constructor, triggers a call 674104349Sphkto the <code>UnknownEncodingHandler</code>. This handler gets passed 675104349Sphkthe encoding name and a pointer to an <code>XML_Encoding</code> data 676178848Scokanestructure. Your handler must fill in this structure and return 677178848Scokane<code>XML_STATUS_OK</code> if it knows how to deal with the 678178848Scokaneencoding. Otherwise the handler should return 679178848Scokane<code>XML_STATUS_ERROR</code>. The handler also gets passed a pointer 680178848Scokaneto an optional application data structure that you may indicate when 681178848Scokaneyou set the handler.</p> 682104349Sphk 683104349Sphk<p>Expat places restrictions on character encodings that it can 684104349Sphksupport by filling in the <code>XML_Encoding</code> structure. 685104349Sphkinclude file:</p> 686104349Sphk<ol> 687104349Sphk<li>Every ASCII character that can appear in a well-formed XML document 688104349Sphkmust be represented by a single byte, and that byte must correspond to 689104349Sphkit's ASCII encoding (except for the characters $@\^'{}~)</li> 690104349Sphk<li>Characters must be encoded in 4 bytes or less.</li> 691104349Sphk<li>All characters encoded must have Unicode scalar values less than or 692104349Sphkequal to 65535 (0xFFFF)<em>This does not apply to the built-in support 693104349Sphkfor UTF-16 and UTF-8</em></li> 694104349Sphk<li>No character may be encoded by more that one distinct sequence of 695104349Sphkbytes</li> 696104349Sphk</ol> 697104349Sphk 698104349Sphk<p><code>XML_Encoding</code> contains an array of integers that 699104349Sphkcorrespond to the 1st byte of an encoding sequence. If the value in 700104349Sphkthe array for a byte is zero or positive, then the byte is a single 701104349Sphkbyte encoding that encodes the Unicode scalar value contained in the 702104349Sphkarray. A -1 in this array indicates a malformed byte. If the value is 703104349Sphk-2, -3, or -4, then the byte is the beginning of a 2, 3, or 4 byte 704104349Sphksequence respectively. Multi-byte sequences are sent to the convert 705104349Sphkfunction pointed at in the <code>XML_Encoding</code> structure. This 706104349Sphkfunction should return the Unicode scalar value for the sequence or -1 707104349Sphkif the sequence is malformed.</p> 708104349Sphk 709104349Sphk<p>One pitfall that novice Expat users are likely to fall into is that 710104349Sphkalthough Expat may accept input in various encodings, the strings that 711104349Sphkit passes to the handlers are always encoded in UTF-8 or UTF-16 712104349Sphk(depending on how Expat was compiled). Your application is responsible 713104349Sphkfor any translation of these strings into other encodings.</p> 714104349Sphk 715104349Sphk<h3>Handling External Entity References</h3> 716104349Sphk 717104349Sphk<p>Expat does not read or parse external entities directly. Note that 718104349Sphkany external DTD is a special case of an external entity. If you've 719104349Sphkset no <code>ExternalEntityRefHandler</code>, then external entity 720104349Sphkreferences are silently ignored. Otherwise, it calls your handler with 721104349Sphkthe information needed to read and parse the external entity.</p> 722104349Sphk 723104349Sphk<p>Your handler isn't actually responsible for parsing the entity, but 724104349Sphkit is responsible for creating a subsidiary parser with <code><a href= 725104349Sphk"#XML_ExternalEntityParserCreate" 726104349Sphk>XML_ExternalEntityParserCreate</a></code> that will do the job. This 727104349Sphkreturns an instance of <code>XML_Parser</code> that has handlers and 728104349Sphkother data structures initialized from the parent parser. You may then 729104349Sphkuse <code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a 730104349Sphkhref= "#XML_ParseBuffer">XML_ParseBuffer</a></code> calls against this 731104349Sphkparser. Since external entities my refer to other external entities, 732104349Sphkyour handler should be prepared to be called recursively.</p> 733104349Sphk 734104349Sphk<h3>Parsing DTDs</h3> 735104349Sphk 736104349Sphk<p>In order to parse parameter entities, before starting the parse, 737104349Sphkyou must call <code><a href= "#XML_SetParamEntityParsing" 738104349Sphk>XML_SetParamEntityParsing</a></code> with one of the following 739104349Sphkarguments:</p> 740104349Sphk<dl> 741104349Sphk<dt><code>XML_PARAM_ENTITY_PARSING_NEVER</code></dt> 742104349Sphk<dd>Don't parse parameter entities or the external subset</dd> 743104349Sphk<dt><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></dt> 744355604Sdelphij<dd>Parse parameter entities and the external subset unless 745104349Sphk<code>standalone</code> was set to "yes" in the XML declaration.</dd> 746104349Sphk<dt><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></dt> 747104349Sphk<dd>Always parse parameter entities and the external subset</dd> 748104349Sphk</dl> 749104349Sphk 750104349Sphk<p>In order to read an external DTD, you also have to set an external 751104349Sphkentity reference handler as described above.</p> 752104349Sphk 753178848Scokane<h3 id="stop-resume">Temporarily Stopping Parsing</h3> 754178848Scokane 755178848Scokane<p>Expat 1.95.8 introduces a new feature: its now possible to stop 756178848Scokaneparsing temporarily from within a handler function, even if more data 757178848Scokanehas already been passed into the parser. Applications for this 758178848Scokaneinclude</p> 759178848Scokane 760178848Scokane<ul> 761178848Scokane <li>Supporting the <a href= "http://www.w3.org/TR/xinclude/" 762178848Scokane >XInclude</a> specification.</li> 763178848Scokane 764178848Scokane <li>Delaying further processing until additional information is 765178848Scokane available from some other source.</li> 766178848Scokane 767178848Scokane <li>Adjusting processor load as task priorities shift within an 768178848Scokane application.</li> 769178848Scokane 770178848Scokane <li>Stopping parsing completely (simply free or reset the parser 771178848Scokane instead of resuming in the outer parsing loop). This can be useful 772355604Sdelphij if an application-domain error is found in the XML being parsed or if 773178848Scokane the result of the parse is determined not to be useful after 774178848Scokane all.</li> 775178848Scokane</ul> 776178848Scokane 777178848Scokane<p>To take advantage of this feature, the main parsing loop of an 778178848Scokaneapplication needs to support this specifically. It cannot be 779178848Scokanesupported with a parsing loop compatible with Expat 1.95.7 or 780178848Scokaneearlier (though existing loops will continue to work without 781178848Scokanesupporting the stop/resume feature).</p> 782178848Scokane 783178848Scokane<p>An application that uses this feature for a single parser will have 784178848Scokanethe rough structure (in pseudo-code):</p> 785178848Scokane 786178848Scokane<pre class="pseudocode"> 787178848Scokanefd = open_input() 788178848Scokanep = create_parser() 789178848Scokane 790178848Scokaneif parse_xml(p, fd) { 791178848Scokane /* suspended */ 792178848Scokane 793178848Scokane int suspended = 1; 794178848Scokane 795178848Scokane while (suspended) { 796178848Scokane do_something_else() 797178848Scokane if ready_to_resume() { 798178848Scokane suspended = continue_parsing(p, fd); 799178848Scokane } 800178848Scokane } 801178848Scokane} 802178848Scokane</pre> 803178848Scokane 804178848Scokane<p>An application that may resume any of several parsers based on 805178848Scokaneinput (either from the XML being parsed or some other source) will 806178848Scokanecertainly have more interesting control structures.</p> 807178848Scokane 808178848Scokane<p>This C function could be used for the <code>parse_xml</code> 809178848Scokanefunction mentioned in the pseudo-code above:</p> 810178848Scokane 811178848Scokane<pre class="eg"> 812178848Scokane#define BUFF_SIZE 10240 813178848Scokane 814178848Scokane/* Parse a document from the open file descriptor 'fd' until the parse 815178848Scokane is complete (the document has been completely parsed, or there's 816178848Scokane been an error), or the parse is stopped. Return non-zero when 817178848Scokane the parse is merely suspended. 818178848Scokane*/ 819178848Scokaneint 820178848Scokaneparse_xml(XML_Parser p, int fd) 821178848Scokane{ 822178848Scokane for (;;) { 823178848Scokane int last_chunk; 824178848Scokane int bytes_read; 825178848Scokane enum XML_Status status; 826178848Scokane 827178848Scokane void *buff = XML_GetBuffer(p, BUFF_SIZE); 828178848Scokane if (buff == NULL) { 829178848Scokane /* handle error... */ 830178848Scokane return 0; 831178848Scokane } 832178848Scokane bytes_read = read(fd, buff, BUFF_SIZE); 833178848Scokane if (bytes_read < 0) { 834178848Scokane /* handle error... */ 835178848Scokane return 0; 836178848Scokane } 837178848Scokane status = XML_ParseBuffer(p, bytes_read, bytes_read == 0); 838178848Scokane switch (status) { 839178848Scokane case XML_STATUS_ERROR: 840178848Scokane /* handle error... */ 841178848Scokane return 0; 842178848Scokane case XML_STATUS_SUSPENDED: 843178848Scokane return 1; 844178848Scokane } 845178848Scokane if (bytes_read == 0) 846178848Scokane return 0; 847178848Scokane } 848178848Scokane} 849178848Scokane</pre> 850178848Scokane 851178848Scokane<p>The corresponding <code>continue_parsing</code> function is 852178848Scokanesomewhat simpler, since it only need deal with the return code from 853178848Scokane<code><a href= "#XML_ResumeParser">XML_ResumeParser</a></code>; it can 854178848Scokanedelegate the input handling to the <code>parse_xml</code> 855178848Scokanefunction:</p> 856178848Scokane 857178848Scokane<pre class="eg"> 858178848Scokane/* Continue parsing a document which had been suspended. The 'p' and 859178848Scokane 'fd' arguments are the same as passed to parse_xml(). Return 860178848Scokane non-zero when the parse is suspended. 861178848Scokane*/ 862178848Scokaneint 863178848Scokanecontinue_parsing(XML_Parser p, int fd) 864178848Scokane{ 865178848Scokane enum XML_Status status = XML_ResumeParser(p); 866178848Scokane switch (status) { 867178848Scokane case XML_STATUS_ERROR: 868178848Scokane /* handle error... */ 869178848Scokane return 0; 870178848Scokane case XML_ERROR_NOT_SUSPENDED: 871178848Scokane /* handle error... */ 872178848Scokane return 0;. 873178848Scokane case XML_STATUS_SUSPENDED: 874178848Scokane return 1; 875178848Scokane } 876178848Scokane return parse_xml(p, fd); 877178848Scokane} 878178848Scokane</pre> 879178848Scokane 880178848Scokane<p>Now that we've seen what a mess the top-level parsing loop can 881178848Scokanebecome, what have we gained? Very simply, we can now use the <code><a 882178848Scokanehref= "#XML_StopParser" >XML_StopParser</a></code> function to stop 883178848Scokaneparsing, without having to go to great lengths to avoid additional 884178848Scokaneprocessing that we're expecting to ignore. As a bonus, we get to stop 885178848Scokaneparsing <em>temporarily</em>, and come back to it when we're 886178848Scokaneready.</p> 887178848Scokane 888178848Scokane<p>To stop parsing from a handler function, use the <code><a href= 889178848Scokane"#XML_StopParser" >XML_StopParser</a></code> function. This function 890178848Scokanetakes two arguments; the parser being stopped and a flag indicating 891178848Scokanewhether the parse can be resumed in the future.</p> 892178848Scokane 893178848Scokane<!-- XXX really need more here --> 894178848Scokane 895178848Scokane 896104349Sphk<hr /> 897104349Sphk<!-- ================================================================ --> 898104349Sphk 899104349Sphk<h2><a name="reference">Expat Reference</a></h2> 900104349Sphk 901104349Sphk<h3><a name="creation">Parser Creation</a></h3> 902104349Sphk 903104349Sphk<pre class="fcndec" id="XML_ParserCreate"> 904178848ScokaneXML_Parser XMLCALL 905104349SphkXML_ParserCreate(const XML_Char *encoding); 906104349Sphk</pre> 907104349Sphk<div class="fcndef"> 908104349SphkConstruct a new parser. If encoding is non-null, it specifies a 909104349Sphkcharacter encoding to use for the document. This overrides the document 910104349Sphkencoding declaration. There are four built-in encodings: 911104349Sphk<ul> 912104349Sphk<li>US-ASCII</li> 913104349Sphk<li>UTF-8</li> 914104349Sphk<li>UTF-16</li> 915104349Sphk<li>ISO-8859-1</li> 916104349Sphk</ul> 917104349SphkAny other value will invoke a call to the UnknownEncodingHandler. 918104349Sphk</div> 919104349Sphk 920104349Sphk<pre class="fcndec" id="XML_ParserCreateNS"> 921178848ScokaneXML_Parser XMLCALL 922104349SphkXML_ParserCreateNS(const XML_Char *encoding, 923104349Sphk XML_Char sep); 924104349Sphk</pre> 925104349Sphk<div class="fcndef"> 926104349SphkConstructs a new parser that has namespace processing in effect. Namespace 927104349Sphkexpanded element names and attribute names are returned as a concatenation 928104349Sphkof the namespace URI, <em>sep</em>, and the local part of the name. This 929247296Sdelphijmeans that you should pick a character for <em>sep</em> that can't be part 930247296Sdelphijof an URI. Since Expat does not check namespace URIs for conformance, the 931247296Sdelphijonly safe choice for a namespace separator is a character that is illegal 932247296Sdelphijin XML. For instance, <code>'\xFF'</code> is not legal in UTF-8, and 933247296Sdelphij<code>'\xFFFF'</code> is not legal in UTF-16. There is a special case when 934247296Sdelphij<em>sep</em> is the null character <code>'\0'</code>: the namespace URI and 935247296Sdelphijthe local part will be concatenated without any separator - this is intended 936247296Sdelphijto support RDF processors. It is a programming error to use the null separator 937247296Sdelphijwith <a href= "#XML_SetReturnNSTriplet">namespace triplets</a>.</div> 938104349Sphk 939104349Sphk<pre class="fcndec" id="XML_ParserCreate_MM"> 940178848ScokaneXML_Parser XMLCALL 941104349SphkXML_ParserCreate_MM(const XML_Char *encoding, 942104349Sphk const XML_Memory_Handling_Suite *ms, 943104349Sphk const XML_Char *sep); 944104349Sphk</pre> 945104349Sphk<pre class="signature"> 946104349Sphktypedef struct { 947178848Scokane void *(XMLCALL *malloc_fcn)(size_t size); 948178848Scokane void *(XMLCALL *realloc_fcn)(void *ptr, size_t size); 949178848Scokane void (XMLCALL *free_fcn)(void *ptr); 950104349Sphk} XML_Memory_Handling_Suite; 951104349Sphk</pre> 952104349Sphk<div class="fcndef"> 953104349Sphk<p>Construct a new parser using the suite of memory handling functions 954104349Sphkspecified in <code>ms</code>. If <code>ms</code> is NULL, then use the 955104349Sphkstandard set of memory management functions. If <code>sep</code> is 956104349Sphknon NULL, then namespace processing is enabled in the created parser 957104349Sphkand the character pointed at by sep is used as the separator between 958104349Sphkthe namespace URI and the local part of the name.</p> 959104349Sphk</div> 960104349Sphk 961104349Sphk<pre class="fcndec" id="XML_ExternalEntityParserCreate"> 962178848ScokaneXML_Parser XMLCALL 963104349SphkXML_ExternalEntityParserCreate(XML_Parser p, 964104349Sphk const XML_Char *context, 965104349Sphk const XML_Char *encoding); 966104349Sphk</pre> 967104349Sphk<div class="fcndef"> 968104349SphkConstruct a new <code>XML_Parser</code> object for parsing an external 969104349Sphkgeneral entity. Context is the context argument passed in a call to a 970104349SphkExternalEntityRefHandler. Other state information such as handlers, 971104349Sphkuser data, namespace processing is inherited from the parser passed as 972104349Sphkthe 1st argument. So you shouldn't need to call any of the behavior 973104349Sphkchanging functions on this parser (unless you want it to act 974104349Sphkdifferently than the parent parser). 975104349Sphk</div> 976104349Sphk 977104349Sphk<pre class="fcndec" id="XML_ParserFree"> 978178848Scokanevoid XMLCALL 979104349SphkXML_ParserFree(XML_Parser p); 980104349Sphk</pre> 981104349Sphk<div class="fcndef"> 982104349SphkFree memory used by the parser. Your application is responsible for 983104349Sphkfreeing any memory associated with <a href="#userdata">user data</a>. 984104349Sphk</div> 985104349Sphk 986104349Sphk<pre class="fcndec" id="XML_ParserReset"> 987178848ScokaneXML_Bool XMLCALL 988178848ScokaneXML_ParserReset(XML_Parser p, 989178848Scokane const XML_Char *encoding); 990104349Sphk</pre> 991104349Sphk<div class="fcndef"> 992104349SphkClean up the memory structures maintained by the parser so that it may 993104349Sphkbe used again. After this has been called, <code>parser</code> is 994178848Scokaneready to start parsing a new document. All handlers are cleared from 995178848Scokanethe parser, except for the unknownEncodingHandler. The parser's external 996178848Scokanestate is re-initialized except for the values of ns and ns_triplets. 997178848ScokaneThis function may not be used on a parser created using <code><a href= 998104349Sphk"#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a 999104349Sphk></code>; it will return <code>XML_FALSE</code> in that case. Returns 1000104349Sphk<code>XML_TRUE</code> on success. Your application is responsible for 1001104349Sphkdealing with any memory associated with <a href="#userdata">user data</a>. 1002104349Sphk</div> 1003104349Sphk 1004104349Sphk<h3><a name="parsing">Parsing</a></h3> 1005104349Sphk 1006104349Sphk<p>To state the obvious: the three parsing functions <code><a href= 1007178848Scokane"#XML_Parse" >XML_Parse</a></code>, <code><a href= "#XML_ParseBuffer"> 1008178848ScokaneXML_ParseBuffer</a></code> and <code><a href= "#XML_GetBuffer"> 1009178848ScokaneXML_GetBuffer</a></code> must not be called from within a handler 1010178848Scokaneunless they operate on a separate parser instance, that is, one that 1011178848Scokanedid not call the handler. For example, it is OK to call the parsing 1012178848Scokanefunctions from within an <code>XML_ExternalEntityRefHandler</code>, 1013178848Scokaneif they apply to the parser created by 1014178848Scokane<code><a href= "#XML_ExternalEntityParserCreate" 1015104349Sphk>XML_ExternalEntityParserCreate</a></code>.</p> 1016104349Sphk 1017178848Scokane<p>Note: the <code>len</code> argument passed to these functions 1018178848Scokaneshould be considerably less than the maximum value for an integer, 1019178848Scokaneas it could create an integer overflow situation if the added 1020178848Scokanelengths of a buffer and the unprocessed portion of the previous buffer 1021178848Scokaneexceed the maximum integer value. Input data at the end of a buffer 1022178848Scokanewill remain unprocessed if it is part of an XML token for which the 1023178848Scokaneend is not part of that buffer.</p> 1024178848Scokane 1025104349Sphk<pre class="fcndec" id="XML_Parse"> 1026178848Scokaneenum XML_Status XMLCALL 1027104349SphkXML_Parse(XML_Parser p, 1028104349Sphk const char *s, 1029104349Sphk int len, 1030104349Sphk int isFinal); 1031104349Sphk</pre> 1032104349Sphk<pre class="signature"> 1033104349Sphkenum XML_Status { 1034104349Sphk XML_STATUS_ERROR = 0, 1035104349Sphk XML_STATUS_OK = 1 1036104349Sphk}; 1037104349Sphk</pre> 1038104349Sphk<div class="fcndef"> 1039104349SphkParse some more of the document. The string <code>s</code> is a buffer 1040104349Sphkcontaining part (or perhaps all) of the document. The number of bytes of s 1041104349Sphkthat are part of the document is indicated by <code>len</code>. This means 1042104349Sphkthat <code>s</code> doesn't have to be null terminated. It also means that 1043104349Sphkif <code>len</code> is larger than the number of bytes in the block of 1044104349Sphkmemory that <code>s</code> points at, then a memory fault is likely. The 1045104349Sphk<code>isFinal</code> parameter informs the parser that this is the last 1046104349Sphkpiece of the document. Frequently, the last piece is empty (i.e. 1047104349Sphk<code>len</code> is zero.) 1048104349SphkIf a parse error occurred, it returns <code>XML_STATUS_ERROR</code>. 1049104349SphkOtherwise it returns <code>XML_STATUS_OK</code> value. 1050104349Sphk</div> 1051104349Sphk 1052104349Sphk<pre class="fcndec" id="XML_ParseBuffer"> 1053178848Scokaneenum XML_Status XMLCALL 1054104349SphkXML_ParseBuffer(XML_Parser p, 1055104349Sphk int len, 1056104349Sphk int isFinal); 1057104349Sphk</pre> 1058104349Sphk<div class="fcndef"> 1059104349SphkThis is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>, 1060104349Sphkexcept in this case Expat provides the buffer. By obtaining the 1061104349Sphkbuffer from Expat with the <code><a href= "#XML_GetBuffer" 1062104349Sphk>XML_GetBuffer</a></code> function, the application can avoid double 1063104349Sphkcopying of the input. 1064104349Sphk</div> 1065104349Sphk 1066104349Sphk<pre class="fcndec" id="XML_GetBuffer"> 1067178848Scokanevoid * XMLCALL 1068104349SphkXML_GetBuffer(XML_Parser p, 1069104349Sphk int len); 1070104349Sphk</pre> 1071104349Sphk<div class="fcndef"> 1072104349SphkObtain a buffer of size <code>len</code> to read a piece of the document 1073104349Sphkinto. A NULL value is returned if Expat can't allocate enough memory for 1074104349Sphkthis buffer. This has to be called prior to every call to 1075104349Sphk<code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A 1076104349Sphktypical use would look like this: 1077104349Sphk 1078104349Sphk<pre class="eg"> 1079104349Sphkfor (;;) { 1080104349Sphk int bytes_read; 1081104349Sphk void *buff = XML_GetBuffer(p, BUFF_SIZE); 1082104349Sphk if (buff == NULL) { 1083104349Sphk /* handle error */ 1084104349Sphk } 1085104349Sphk 1086104349Sphk bytes_read = read(docfd, buff, BUFF_SIZE); 1087104349Sphk if (bytes_read < 0) { 1088104349Sphk /* handle error */ 1089104349Sphk } 1090104349Sphk 1091104349Sphk if (! XML_ParseBuffer(p, bytes_read, bytes_read == 0)) { 1092104349Sphk /* handle parse error */ 1093104349Sphk } 1094104349Sphk 1095104349Sphk if (bytes_read == 0) 1096104349Sphk break; 1097104349Sphk} 1098104349Sphk</pre> 1099104349Sphk</div> 1100104349Sphk 1101178848Scokane<pre class="fcndec" id="XML_StopParser"> 1102178848Scokaneenum XML_Status XMLCALL 1103178848ScokaneXML_StopParser(XML_Parser p, 1104178848Scokane XML_Bool resumable); 1105178848Scokane</pre> 1106178848Scokane<div class="fcndef"> 1107178848Scokane 1108178848Scokane<p>Stops parsing, causing <code><a href= "#XML_Parse" 1109178848Scokane>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer" 1110178848Scokane>XML_ParseBuffer</a></code> to return. Must be called from within a 1111178848Scokanecall-back handler, except when aborting (when <code>resumable</code> 1112178848Scokaneis <code>XML_FALSE</code>) an already suspended parser. Some 1113178848Scokanecall-backs may still follow because they would otherwise get 1114178848Scokanelost, including 1115178848Scokane<ul> 1116178848Scokane <li> the end element handler for empty elements when stopped in the 1117178848Scokane start element handler,</li> 1118178848Scokane <li> the end namespace declaration handler when stopped in the end 1119178848Scokane element handler,</li> 1120178848Scokane <li> the character data handler when stopped in the character data handler 1121178848Scokane while making multiple call-backs on a contiguous chunk of characters,</li> 1122178848Scokane</ul> 1123178848Scokaneand possibly others.</p> 1124178848Scokane 1125178848Scokane<p>This can be called from most handlers, including DTD related 1126178848Scokanecall-backs, except when parsing an external parameter entity and 1127178848Scokane<code>resumable</code> is <code>XML_TRUE</code>. Returns 1128178848Scokane<code>XML_STATUS_OK</code> when successful, 1129178848Scokane<code>XML_STATUS_ERROR</code> otherwise. The possible error codes 1130178848Scokaneare:</p> 1131178848Scokane<dl> 1132178848Scokane <dt><code>XML_ERROR_SUSPENDED</code></dt> 1133178848Scokane <dd>when suspending an already suspended parser.</dd> 1134178848Scokane <dt><code>XML_ERROR_FINISHED</code></dt> 1135178848Scokane <dd>when the parser has already finished.</dd> 1136178848Scokane <dt><code>XML_ERROR_SUSPEND_PE</code></dt> 1137178848Scokane <dd>when suspending while parsing an external PE.</dd> 1138178848Scokane</dl> 1139178848Scokane 1140178848Scokane<p>Since the stop/resume feature requires application support in the 1141178848Scokaneouter parsing loop, it is an error to call this function for a parser 1142178848Scokanenot being handled appropriately; see <a href= "#stop-resume" 1143178848Scokane>Temporarily Stopping Parsing</a> for more information.</p> 1144178848Scokane 1145178848Scokane<p>When <code>resumable</code> is <code>XML_TRUE</code> then parsing 1146178848Scokaneis <em>suspended</em>, that is, <code><a href= "#XML_Parse" 1147178848Scokane>XML_Parse</a></code> and <code><a href= "#XML_ParseBuffer" 1148178848Scokane>XML_ParseBuffer</a></code> return <code>XML_STATUS_SUSPENDED</code>. 1149178848ScokaneOtherwise, parsing is <em>aborted</em>, that is, <code><a href= 1150178848Scokane"#XML_Parse" >XML_Parse</a></code> and <code><a href= 1151178848Scokane"#XML_ParseBuffer" >XML_ParseBuffer</a></code> return 1152178848Scokane<code>XML_STATUS_ERROR</code> with error code 1153178848Scokane<code>XML_ERROR_ABORTED</code>.</p> 1154178848Scokane 1155178848Scokane<p><strong>Note:</strong> 1156178848ScokaneThis will be applied to the current parser instance only, that is, if 1157178848Scokanethere is a parent parser then it will continue parsing when the 1158178848Scokaneexternal entity reference handler returns. It is up to the 1159178848Scokaneimplementation of that handler to call <code><a href= 1160178848Scokane"#XML_StopParser" >XML_StopParser</a></code> on the parent parser 1161178848Scokane(recursively), if one wants to stop parsing altogether.</p> 1162178848Scokane 1163178848Scokane<p>When suspended, parsing can be resumed by calling <code><a href= 1164178848Scokane"#XML_ResumeParser" >XML_ResumeParser</a></code>.</p> 1165178848Scokane 1166178848Scokane<p>New in Expat 1.95.8.</p> 1167178848Scokane</div> 1168178848Scokane 1169178848Scokane<pre class="fcndec" id="XML_ResumeParser"> 1170178848Scokaneenum XML_Status XMLCALL 1171178848ScokaneXML_ResumeParser(XML_Parser p); 1172178848Scokane</pre> 1173178848Scokane<div class="fcndef"> 1174178848Scokane<p>Resumes parsing after it has been suspended with <code><a href= 1175178848Scokane"#XML_StopParser" >XML_StopParser</a></code>. Must not be called from 1176178848Scokanewithin a handler call-back. Returns same status codes as <code><a 1177178848Scokanehref= "#XML_Parse">XML_Parse</a></code> or <code><a href= 1178178848Scokane"#XML_ParseBuffer" >XML_ParseBuffer</a></code>. An additional error 1179178848Scokanecode, <code>XML_ERROR_NOT_SUSPENDED</code>, will be returned if the 1180178848Scokaneparser was not currently suspended.</p> 1181178848Scokane 1182178848Scokane<p><strong>Note:</strong> 1183178848ScokaneThis must be called on the most deeply nested child parser instance 1184178848Scokanefirst, and on its parent parser only after the child parser has 1185178848Scokanefinished, to be applied recursively until the document entity's parser 1186178848Scokaneis restarted. That is, the parent parser will not resume by itself 1187178848Scokaneand it is up to the application to call <code><a href= 1188178848Scokane"#XML_ResumeParser" >XML_ResumeParser</a></code> on it at the 1189178848Scokaneappropriate moment.</p> 1190178848Scokane 1191178848Scokane<p>New in Expat 1.95.8.</p> 1192178848Scokane</div> 1193178848Scokane 1194178848Scokane<pre class="fcndec" id="XML_GetParsingStatus"> 1195178848Scokanevoid XMLCALL 1196178848ScokaneXML_GetParsingStatus(XML_Parser p, 1197178848Scokane XML_ParsingStatus *status); 1198178848Scokane</pre> 1199178848Scokane<pre class="signature"> 1200178848Scokaneenum XML_Parsing { 1201178848Scokane XML_INITIALIZED, 1202178848Scokane XML_PARSING, 1203178848Scokane XML_FINISHED, 1204178848Scokane XML_SUSPENDED 1205178848Scokane}; 1206178848Scokane 1207178848Scokanetypedef struct { 1208178848Scokane enum XML_Parsing parsing; 1209178848Scokane XML_Bool finalBuffer; 1210178848Scokane} XML_ParsingStatus; 1211178848Scokane</pre> 1212178848Scokane<div class="fcndef"> 1213178848Scokane<p>Returns status of parser with respect to being initialized, 1214178848Scokaneparsing, finished, or suspended, and whether the final buffer is being 1215178848Scokaneprocessed. The <code>status</code> parameter <em>must not</em> be 1216178848ScokaneNULL.</p> 1217178848Scokane 1218178848Scokane<p>New in Expat 1.95.8.</p> 1219178848Scokane</div> 1220178848Scokane 1221178848Scokane 1222104349Sphk<h3><a name="setting">Handler Setting</a></h3> 1223104349Sphk 1224104349Sphk<p>Although handlers are typically set prior to parsing and left alone, an 1225104349Sphkapplication may choose to set or change the handler for a parsing event 1226104349Sphkwhile the parse is in progress. For instance, your application may choose 1227104349Sphkto ignore all text not descended from a <code>para</code> element. One 1228104349Sphkway it could do this is to set the character handler when a para start tag 1229104349Sphkis seen, and unset it for the corresponding end tag.</p> 1230104349Sphk 1231104349Sphk<p>A handler may be <em>unset</em> by providing a NULL pointer to the 1232104349Sphkappropriate handler setter. None of the handler setting functions have 1233104349Sphka return value.</p> 1234104349Sphk 1235104349Sphk<p>Your handlers will be receiving strings in arrays of type 1236178848Scokane<code>XML_Char</code>. This type is conditionally defined in expat.h as 1237178848Scokaneeither <code>char</code>, <code>wchar_t</code> or <code>unsigned short</code>. 1238178848ScokaneThe former implies UTF-8 encoding, the latter two imply UTF-16 encoding. 1239178848ScokaneNote that you'll receive them in this form independent of the original 1240178848Scokaneencoding of the document.</p> 1241104349Sphk 1242104349Sphk<div class="handler"> 1243104349Sphk<pre class="setter" id="XML_SetStartElementHandler"> 1244178848Scokanevoid XMLCALL 1245104349SphkXML_SetStartElementHandler(XML_Parser p, 1246104349Sphk XML_StartElementHandler start); 1247104349Sphk</pre> 1248104349Sphk<pre class="signature"> 1249104349Sphktypedef void 1250178848Scokane(XMLCALL *XML_StartElementHandler)(void *userData, 1251178848Scokane const XML_Char *name, 1252178848Scokane const XML_Char **atts); 1253104349Sphk</pre> 1254104349Sphk<p>Set handler for start (and empty) tags. Attributes are passed to the start 1255104349Sphkhandler as a pointer to a vector of char pointers. Each attribute seen in 1256104349Sphka start (or empty) tag occupies 2 consecutive places in this vector: the 1257104349Sphkattribute name followed by the attribute value. These pairs are terminated 1258104349Sphkby a null pointer.</p> 1259104349Sphk<p>Note that an empty tag generates a call to both start and end handlers 1260104349Sphk(in that order).</p> 1261104349Sphk</div> 1262104349Sphk 1263104349Sphk<div class="handler"> 1264104349Sphk<pre class="setter" id="XML_SetEndElementHandler"> 1265178848Scokanevoid XMLCALL 1266104349SphkXML_SetEndElementHandler(XML_Parser p, 1267104349Sphk XML_EndElementHandler); 1268104349Sphk</pre> 1269104349Sphk<pre class="signature"> 1270104349Sphktypedef void 1271178848Scokane(XMLCALL *XML_EndElementHandler)(void *userData, 1272178848Scokane const XML_Char *name); 1273104349Sphk</pre> 1274104349Sphk<p>Set handler for end (and empty) tags. As noted above, an empty tag 1275104349Sphkgenerates a call to both start and end handlers.</p> 1276104349Sphk</div> 1277104349Sphk 1278104349Sphk<div class="handler"> 1279104349Sphk<pre class="setter" id="XML_SetElementHandler"> 1280178848Scokanevoid XMLCALL 1281104349SphkXML_SetElementHandler(XML_Parser p, 1282104349Sphk XML_StartElementHandler start, 1283104349Sphk XML_EndElementHandler end); 1284104349Sphk</pre> 1285104349Sphk<p>Set handlers for start and end tags with one call.</p> 1286104349Sphk</div> 1287104349Sphk 1288104349Sphk<div class="handler"> 1289104349Sphk<pre class="setter" id="XML_SetCharacterDataHandler"> 1290178848Scokanevoid XMLCALL 1291104349SphkXML_SetCharacterDataHandler(XML_Parser p, 1292104349Sphk XML_CharacterDataHandler charhndl) 1293104349Sphk</pre> 1294104349Sphk<pre class="signature"> 1295104349Sphktypedef void 1296178848Scokane(XMLCALL *XML_CharacterDataHandler)(void *userData, 1297178848Scokane const XML_Char *s, 1298178848Scokane int len); 1299104349Sphk</pre> 1300104349Sphk<p>Set a text handler. The string your handler receives 1301104349Sphkis <em>NOT nul-terminated</em>. You have to use the length argument 1302104349Sphkto deal with the end of the string. A single block of contiguous text 1303104349Sphkfree of markup may still result in a sequence of calls to this handler. 1304104349SphkIn other words, if you're searching for a pattern in the text, it may 1305178848Scokanebe split across calls to this handler. Note: Setting this handler to NULL 1306178848Scokanemay <em>NOT immediately</em> terminate call-backs if the parser is currently 1307178848Scokaneprocessing such a single block of contiguous markup-free text, as the parser 1308178848Scokanewill continue calling back until the end of the block is reached.</p> 1309104349Sphk</div> 1310104349Sphk 1311104349Sphk<div class="handler"> 1312104349Sphk<pre class="setter" id="XML_SetProcessingInstructionHandler"> 1313178848Scokanevoid XMLCALL 1314104349SphkXML_SetProcessingInstructionHandler(XML_Parser p, 1315104349Sphk XML_ProcessingInstructionHandler proc) 1316104349Sphk</pre> 1317104349Sphk<pre class="signature"> 1318104349Sphktypedef void 1319178848Scokane(XMLCALL *XML_ProcessingInstructionHandler)(void *userData, 1320178848Scokane const XML_Char *target, 1321178848Scokane const XML_Char *data); 1322104349Sphk 1323104349Sphk</pre> 1324104349Sphk<p>Set a handler for processing instructions. The target is the first word 1325104349Sphkin the processing instruction. The data is the rest of the characters in 1326104349Sphkit after skipping all whitespace after the initial word.</p> 1327104349Sphk</div> 1328104349Sphk 1329104349Sphk<div class="handler"> 1330104349Sphk<pre class="setter" id="XML_SetCommentHandler"> 1331178848Scokanevoid XMLCALL 1332104349SphkXML_SetCommentHandler(XML_Parser p, 1333104349Sphk XML_CommentHandler cmnt) 1334104349Sphk</pre> 1335104349Sphk<pre class="signature"> 1336104349Sphktypedef void 1337178848Scokane(XMLCALL *XML_CommentHandler)(void *userData, 1338178848Scokane const XML_Char *data); 1339104349Sphk</pre> 1340104349Sphk<p>Set a handler for comments. The data is all text inside the comment 1341104349Sphkdelimiters.</p> 1342104349Sphk</div> 1343104349Sphk 1344104349Sphk<div class="handler"> 1345104349Sphk<pre class="setter" id="XML_SetStartCdataSectionHandler"> 1346178848Scokanevoid XMLCALL 1347104349SphkXML_SetStartCdataSectionHandler(XML_Parser p, 1348104349Sphk XML_StartCdataSectionHandler start); 1349104349Sphk</pre> 1350104349Sphk<pre class="signature"> 1351104349Sphktypedef void 1352178848Scokane(XMLCALL *XML_StartCdataSectionHandler)(void *userData); 1353104349Sphk</pre> 1354104349Sphk<p>Set a handler that gets called at the beginning of a CDATA section.</p> 1355104349Sphk</div> 1356104349Sphk 1357104349Sphk<div class="handler"> 1358104349Sphk<pre class="setter" id="XML_SetEndCdataSectionHandler"> 1359178848Scokanevoid XMLCALL 1360104349SphkXML_SetEndCdataSectionHandler(XML_Parser p, 1361104349Sphk XML_EndCdataSectionHandler end); 1362104349Sphk</pre> 1363104349Sphk<pre class="signature"> 1364104349Sphktypedef void 1365178848Scokane(XMLCALL *XML_EndCdataSectionHandler)(void *userData); 1366104349Sphk</pre> 1367104349Sphk<p>Set a handler that gets called at the end of a CDATA section.</p> 1368104349Sphk</div> 1369104349Sphk 1370104349Sphk<div class="handler"> 1371104349Sphk<pre class="setter" id="XML_SetCdataSectionHandler"> 1372178848Scokanevoid XMLCALL 1373104349SphkXML_SetCdataSectionHandler(XML_Parser p, 1374104349Sphk XML_StartCdataSectionHandler start, 1375104349Sphk XML_EndCdataSectionHandler end) 1376104349Sphk</pre> 1377104349Sphk<p>Sets both CDATA section handlers with one call.</p> 1378104349Sphk</div> 1379104349Sphk 1380104349Sphk<div class="handler"> 1381104349Sphk<pre class="setter" id="XML_SetDefaultHandler"> 1382178848Scokanevoid XMLCALL 1383104349SphkXML_SetDefaultHandler(XML_Parser p, 1384104349Sphk XML_DefaultHandler hndl) 1385104349Sphk</pre> 1386104349Sphk<pre class="signature"> 1387104349Sphktypedef void 1388178848Scokane(XMLCALL *XML_DefaultHandler)(void *userData, 1389178848Scokane const XML_Char *s, 1390178848Scokane int len); 1391104349Sphk</pre> 1392104349Sphk 1393104349Sphk<p>Sets a handler for any characters in the document which wouldn't 1394104349Sphkotherwise be handled. This includes both data for which no handlers 1395104349Sphkcan be set (like some kinds of DTD declarations) and data which could 1396104349Sphkbe reported but which currently has no handler set. The characters 1397104349Sphkare passed exactly as they were present in the XML document except 1398104349Sphkthat they will be encoded in UTF-8 or UTF-16. Line boundaries are not 1399104349Sphknormalized. Note that a byte order mark character is not passed to the 1400104349Sphkdefault handler. There are no guarantees about how characters are 1401104349Sphkdivided between calls to the default handler: for example, a comment 1402104349Sphkmight be split between multiple calls. Setting the handler with 1403104349Sphkthis call has the side effect of turning off expansion of references 1404104349Sphkto internally defined general entities. Instead these references are 1405104349Sphkpassed to the default handler.</p> 1406104349Sphk 1407104349Sphk<p>See also <code><a 1408104349Sphkhref="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p> 1409104349Sphk</div> 1410104349Sphk 1411104349Sphk<div class="handler"> 1412104349Sphk<pre class="setter" id="XML_SetDefaultHandlerExpand"> 1413178848Scokanevoid XMLCALL 1414104349SphkXML_SetDefaultHandlerExpand(XML_Parser p, 1415104349Sphk XML_DefaultHandler hndl) 1416104349Sphk</pre> 1417104349Sphk<pre class="signature"> 1418104349Sphktypedef void 1419178848Scokane(XMLCALL *XML_DefaultHandler)(void *userData, 1420178848Scokane const XML_Char *s, 1421178848Scokane int len); 1422104349Sphk</pre> 1423104349Sphk<p>This sets a default handler, but doesn't inhibit the expansion of 1424104349Sphkinternal entity references. The entity reference will not be passed 1425104349Sphkto the default handler.</p> 1426104349Sphk 1427104349Sphk<p>See also <code><a 1428104349Sphkhref="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p> 1429104349Sphk</div> 1430104349Sphk 1431104349Sphk<div class="handler"> 1432104349Sphk<pre class="setter" id="XML_SetExternalEntityRefHandler"> 1433178848Scokanevoid XMLCALL 1434104349SphkXML_SetExternalEntityRefHandler(XML_Parser p, 1435104349Sphk XML_ExternalEntityRefHandler hndl) 1436104349Sphk</pre> 1437104349Sphk<pre class="signature"> 1438104349Sphktypedef int 1439178848Scokane(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser p, 1440178848Scokane const XML_Char *context, 1441178848Scokane const XML_Char *base, 1442178848Scokane const XML_Char *systemId, 1443178848Scokane const XML_Char *publicId); 1444104349Sphk</pre> 1445104349Sphk<p>Set an external entity reference handler. This handler is also 1446104349Sphkcalled for processing an external DTD subset if parameter entity parsing 1447104349Sphkis in effect. (See <a href="#XML_SetParamEntityParsing"> 1448104349Sphk<code>XML_SetParamEntityParsing</code></a>.)</p> 1449104349Sphk 1450178848Scokane<p>The <code>context</code> parameter specifies the parsing context in 1451178848Scokanethe format expected by the <code>context</code> argument to <code><a 1452178848Scokanehref="#XML_ExternalEntityParserCreate" 1453178848Scokane>XML_ExternalEntityParserCreate</a></code>. <code>code</code> is 1454178848Scokanevalid only until the handler returns, so if the referenced entity is 1455178848Scokaneto be parsed later, it must be copied. <code>context</code> is NULL 1456178848Scokaneonly when the entity is a parameter entity, which is how one can 1457178848Scokanedifferentiate between general and parameter entities.</p> 1458104349Sphk 1459178848Scokane<p>The <code>base</code> parameter is the base to use for relative 1460178848Scokanesystem identifiers. It is set by <code><a 1461178848Scokanehref="#XML_SetBase">XML_SetBase</a></code> and may be NULL. The 1462178848Scokane<code>publicId</code> parameter is the public id given in the entity 1463178848Scokanedeclaration and may be NULL. <code>systemId</code> is the system 1464178848Scokaneidentifier specified in the entity declaration and is never NULL.</p> 1465104349Sphk 1466178848Scokane<p>There are a couple of ways in which this handler differs from 1467178848Scokaneothers. First, this handler returns a status indicator (an 1468178848Scokaneinteger). <code>XML_STATUS_OK</code> should be returned for successful 1469178848Scokanehandling of the external entity reference. Returning 1470178848Scokane<code>XML_STATUS_ERROR</code> indicates failure, and causes the 1471178848Scokanecalling parser to return an 1472178848Scokane<code>XML_ERROR_EXTERNAL_ENTITY_HANDLING</code> error.</p> 1473104349Sphk 1474178848Scokane<p>Second, instead of having the user data as its first argument, it 1475178848Scokanereceives the parser that encountered the entity reference. This, along 1476178848Scokanewith the context parameter, may be used as arguments to a call to 1477178848Scokane<code><a href= "#XML_ExternalEntityParserCreate" 1478178848Scokane>XML_ExternalEntityParserCreate</a></code>. Using the returned 1479178848Scokaneparser, the body of the external entity can be recursively parsed.</p> 1480104349Sphk 1481104349Sphk<p>Since this handler may be called recursively, it should not be saving 1482104349Sphkinformation into global or static variables.</p> 1483104349Sphk</div> 1484104349Sphk 1485178848Scokane<pre class="fcndec" id="XML_SetExternalEntityRefHandlerArg"> 1486178848Scokanevoid XMLCALL 1487178848ScokaneXML_SetExternalEntityRefHandlerArg(XML_Parser p, 1488178848Scokane void *arg) 1489178848Scokane</pre> 1490178848Scokane<div class="fcndef"> 1491178848Scokane<p>Set the argument passed to the ExternalEntityRefHandler. If 1492178848Scokane<code>arg</code> is not NULL, it is the new value passed to the 1493178848Scokanehandler set using <code><a href="#XML_SetExternalEntityRefHandler" 1494178848Scokane>XML_SetExternalEntityRefHandler</a></code>; if <code>arg</code> is 1495178848ScokaneNULL, the argument passed to the handler function will be the parser 1496178848Scokaneobject itself.</p> 1497178848Scokane 1498178848Scokane<p><strong>Note:</strong> 1499178848ScokaneThe type of <code>arg</code> and the type of the first argument to the 1500178848ScokaneExternalEntityRefHandler do not match. This function takes a 1501178848Scokane<code>void *</code> to be passed to the handler, while the handler 1502178848Scokaneaccepts an <code>XML_Parser</code>. This is a historical accident, 1503178848Scokanebut will not be corrected before Expat 2.0 (at the earliest) to avoid 1504178848Scokanecausing compiler warnings for code that's known to work with this 1505178848ScokaneAPI. It is the responsibility of the application code to know the 1506178848Scokaneactual type of the argument passed to the handler and to manage it 1507178848Scokaneproperly.</p> 1508178848Scokane</div> 1509178848Scokane 1510104349Sphk<div class="handler"> 1511104349Sphk<pre class="setter" id="XML_SetSkippedEntityHandler"> 1512178848Scokanevoid XMLCALL 1513104349SphkXML_SetSkippedEntityHandler(XML_Parser p, 1514104349Sphk XML_SkippedEntityHandler handler) 1515104349Sphk</pre> 1516104349Sphk<pre class="signature"> 1517104349Sphktypedef void 1518178848Scokane(XMLCALL *XML_SkippedEntityHandler)(void *userData, 1519178848Scokane const XML_Char *entityName, 1520178848Scokane int is_parameter_entity); 1521104349Sphk</pre> 1522104349Sphk<p>Set a skipped entity handler. This is called in two situations:</p> 1523104349Sphk<ol> 1524104349Sphk <li>An entity reference is encountered for which no declaration 1525104349Sphk has been read <em>and</em> this is not an error.</li> 1526104349Sphk <li>An internal entity reference is read, but not expanded, because 1527104349Sphk <a href="#XML_SetDefaultHandler"><code>XML_SetDefaultHandler</code></a> 1528104349Sphk has been called.</li> 1529104349Sphk</ol> 1530104349Sphk<p>The <code>is_parameter_entity</code> argument will be non-zero for 1531104349Sphka parameter entity and zero for a general entity.</p> <p>Note: skipped 1532104349Sphkparameter entities in declarations and skipped general entities in 1533104349Sphkattribute values cannot be reported, because the event would be out of 1534104349Sphksync with the reporting of the declarations or attribute values</p> 1535104349Sphk</div> 1536104349Sphk 1537104349Sphk<div class="handler"> 1538104349Sphk<pre class="setter" id="XML_SetUnknownEncodingHandler"> 1539178848Scokanevoid XMLCALL 1540104349SphkXML_SetUnknownEncodingHandler(XML_Parser p, 1541104349Sphk XML_UnknownEncodingHandler enchandler, 1542104349Sphk void *encodingHandlerData) 1543104349Sphk</pre> 1544104349Sphk<pre class="signature"> 1545104349Sphktypedef int 1546178848Scokane(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, 1547178848Scokane const XML_Char *name, 1548178848Scokane XML_Encoding *info); 1549104349Sphk 1550104349Sphktypedef struct { 1551104349Sphk int map[256]; 1552104349Sphk void *data; 1553178848Scokane int (XMLCALL *convert)(void *data, const char *s); 1554178848Scokane void (XMLCALL *release)(void *data); 1555104349Sphk} XML_Encoding; 1556104349Sphk</pre> 1557178848Scokane<p>Set a handler to deal with encodings other than the <a 1558178848Scokanehref="#builtin_encodings">built in set</a>. This should be done before 1559104349Sphk<code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href= 1560104349Sphk"#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the 1561178848Scokanegiven parser.</p> <p>If the handler knows how to deal with an encoding 1562178848Scokanewith the given name, it should fill in the <code>info</code> data 1563178848Scokanestructure and return <code>XML_STATUS_OK</code>. Otherwise it 1564178848Scokaneshould return <code>XML_STATUS_ERROR</code>. The handler will be called 1565178848Scokaneat most once per parsed (external) entity. The optional application 1566178848Scokanedata pointer <code>encodingHandlerData</code> will be passed back to 1567178848Scokanethe handler.</p> 1568104349Sphk 1569355604Sdelphij<p>The map array contains information for every possible leading 1570104349Sphkbyte in a byte sequence. If the corresponding value is >= 0, then it's 1571104349Sphka single byte sequence and the byte encodes that Unicode value. If the 1572104349Sphkvalue is -1, then that byte is invalid as the initial byte in a sequence. 1573104349SphkIf the value is -n, where n is an integer > 1, then n is the number of 1574104349Sphkbytes in the sequence and the actual conversion is accomplished by a 1575104349Sphkcall to the function pointed at by convert. This function may return -1 1576104349Sphkif the sequence itself is invalid. The convert pointer may be null if 1577104349Sphkthere are only single byte codes. The data parameter passed to the convert 1578104349Sphkfunction is the data pointer from <code>XML_Encoding</code>. The 1579104349Sphkstring s is <em>NOT</em> nul-terminated and points at the sequence of 1580104349Sphkbytes to be converted.</p> 1581104349Sphk 1582104349Sphk<p>The function pointed at by <code>release</code> is called by the 1583104349Sphkparser when it is finished with the encoding. It may be NULL.</p> 1584104349Sphk</div> 1585104349Sphk 1586104349Sphk<div class="handler"> 1587104349Sphk<pre class="setter" id="XML_SetStartNamespaceDeclHandler"> 1588178848Scokanevoid XMLCALL 1589104349SphkXML_SetStartNamespaceDeclHandler(XML_Parser p, 1590104349Sphk XML_StartNamespaceDeclHandler start); 1591104349Sphk</pre> 1592104349Sphk<pre class="signature"> 1593104349Sphktypedef void 1594178848Scokane(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData, 1595178848Scokane const XML_Char *prefix, 1596178848Scokane const XML_Char *uri); 1597104349Sphk</pre> 1598104349Sphk<p>Set a handler to be called when a namespace is declared. Namespace 1599104349Sphkdeclarations occur inside start tags. But the namespace declaration start 1600104349Sphkhandler is called before the start tag handler for each namespace declared 1601104349Sphkin that start tag.</p> 1602104349Sphk</div> 1603104349Sphk 1604104349Sphk<div class="handler"> 1605104349Sphk<pre class="setter" id="XML_SetEndNamespaceDeclHandler"> 1606178848Scokanevoid XMLCALL 1607104349SphkXML_SetEndNamespaceDeclHandler(XML_Parser p, 1608104349Sphk XML_EndNamespaceDeclHandler end); 1609104349Sphk</pre> 1610104349Sphk<pre class="signature"> 1611104349Sphktypedef void 1612178848Scokane(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, 1613178848Scokane const XML_Char *prefix); 1614104349Sphk</pre> 1615104349Sphk<p>Set a handler to be called when leaving the scope of a namespace 1616104349Sphkdeclaration. This will be called, for each namespace declaration, 1617104349Sphkafter the handler for the end tag of the element in which the 1618104349Sphknamespace was declared.</p> 1619104349Sphk</div> 1620104349Sphk 1621104349Sphk<div class="handler"> 1622104349Sphk<pre class="setter" id="XML_SetNamespaceDeclHandler"> 1623178848Scokanevoid XMLCALL 1624104349SphkXML_SetNamespaceDeclHandler(XML_Parser p, 1625104349Sphk XML_StartNamespaceDeclHandler start, 1626104349Sphk XML_EndNamespaceDeclHandler end) 1627104349Sphk</pre> 1628178848Scokane<p>Sets both namespace declaration handlers with a single call.</p> 1629104349Sphk</div> 1630104349Sphk 1631104349Sphk<div class="handler"> 1632104349Sphk<pre class="setter" id="XML_SetXmlDeclHandler"> 1633178848Scokanevoid XMLCALL 1634104349SphkXML_SetXmlDeclHandler(XML_Parser p, 1635104349Sphk XML_XmlDeclHandler xmldecl); 1636104349Sphk</pre> 1637104349Sphk<pre class="signature"> 1638104349Sphktypedef void 1639178848Scokane(XMLCALL *XML_XmlDeclHandler)(void *userData, 1640178848Scokane const XML_Char *version, 1641178848Scokane const XML_Char *encoding, 1642178848Scokane int standalone); 1643104349Sphk</pre> 1644104349Sphk<p>Sets a handler that is called for XML declarations and also for 1645104349Sphktext declarations discovered in external entities. The way to 1646104349Sphkdistinguish is that the <code>version</code> parameter will be NULL 1647104349Sphkfor text declarations. The <code>encoding</code> parameter may be NULL 1648104349Sphkfor an XML declaration. The <code>standalone</code> argument will 1649104349Sphkcontain -1, 0, or 1 indicating respectively that there was no 1650104349Sphkstandalone parameter in the declaration, that it was given as no, or 1651104349Sphkthat it was given as yes.</p> 1652104349Sphk</div> 1653104349Sphk 1654104349Sphk<div class="handler"> 1655104349Sphk<pre class="setter" id="XML_SetStartDoctypeDeclHandler"> 1656178848Scokanevoid XMLCALL 1657104349SphkXML_SetStartDoctypeDeclHandler(XML_Parser p, 1658104349Sphk XML_StartDoctypeDeclHandler start); 1659104349Sphk</pre> 1660104349Sphk<pre class="signature"> 1661104349Sphktypedef void 1662178848Scokane(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, 1663178848Scokane const XML_Char *doctypeName, 1664178848Scokane const XML_Char *sysid, 1665178848Scokane const XML_Char *pubid, 1666178848Scokane int has_internal_subset); 1667104349Sphk</pre> 1668104349Sphk<p>Set a handler that is called at the start of a DOCTYPE declaration, 1669104349Sphkbefore any external or internal subset is parsed. Both <code>sysid</code> 1670104349Sphkand <code>pubid</code> may be NULL. The <code>has_internal_subset</code> 1671104349Sphkwill be non-zero if the DOCTYPE declaration has an internal subset.</p> 1672104349Sphk</div> 1673104349Sphk 1674104349Sphk<div class="handler"> 1675104349Sphk<pre class="setter" id="XML_SetEndDoctypeDeclHandler"> 1676178848Scokanevoid XMLCALL 1677104349SphkXML_SetEndDoctypeDeclHandler(XML_Parser p, 1678104349Sphk XML_EndDoctypeDeclHandler end); 1679104349Sphk</pre> 1680104349Sphk<pre class="signature"> 1681104349Sphktypedef void 1682178848Scokane(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); 1683104349Sphk</pre> 1684104349Sphk<p>Set a handler that is called at the end of a DOCTYPE declaration, 1685104349Sphkafter parsing any external subset.</p> 1686104349Sphk</div> 1687104349Sphk 1688104349Sphk<div class="handler"> 1689104349Sphk<pre class="setter" id="XML_SetDoctypeDeclHandler"> 1690178848Scokanevoid XMLCALL 1691104349SphkXML_SetDoctypeDeclHandler(XML_Parser p, 1692104349Sphk XML_StartDoctypeDeclHandler start, 1693104349Sphk XML_EndDoctypeDeclHandler end); 1694104349Sphk</pre> 1695104349Sphk<p>Set both doctype handlers with one call.</p> 1696104349Sphk</div> 1697104349Sphk 1698104349Sphk<div class="handler"> 1699104349Sphk<pre class="setter" id="XML_SetElementDeclHandler"> 1700178848Scokanevoid XMLCALL 1701104349SphkXML_SetElementDeclHandler(XML_Parser p, 1702104349Sphk XML_ElementDeclHandler eldecl); 1703104349Sphk</pre> 1704104349Sphk<pre class="signature"> 1705104349Sphktypedef void 1706178848Scokane(XMLCALL *XML_ElementDeclHandler)(void *userData, 1707178848Scokane const XML_Char *name, 1708178848Scokane XML_Content *model); 1709104349Sphk</pre> 1710104349Sphk<pre class="signature"> 1711104349Sphkenum XML_Content_Type { 1712104349Sphk XML_CTYPE_EMPTY = 1, 1713104349Sphk XML_CTYPE_ANY, 1714104349Sphk XML_CTYPE_MIXED, 1715104349Sphk XML_CTYPE_NAME, 1716104349Sphk XML_CTYPE_CHOICE, 1717104349Sphk XML_CTYPE_SEQ 1718104349Sphk}; 1719104349Sphk 1720104349Sphkenum XML_Content_Quant { 1721104349Sphk XML_CQUANT_NONE, 1722104349Sphk XML_CQUANT_OPT, 1723104349Sphk XML_CQUANT_REP, 1724104349Sphk XML_CQUANT_PLUS 1725104349Sphk}; 1726104349Sphk 1727104349Sphktypedef struct XML_cp XML_Content; 1728104349Sphk 1729104349Sphkstruct XML_cp { 1730104349Sphk enum XML_Content_Type type; 1731104349Sphk enum XML_Content_Quant quant; 1732104349Sphk const XML_Char * name; 1733104349Sphk unsigned int numchildren; 1734104349Sphk XML_Content * children; 1735104349Sphk}; 1736104349Sphk</pre> 1737104349Sphk<p>Sets a handler for element declarations in a DTD. The handler gets 1738104349Sphkcalled with the name of the element in the declaration and a pointer 1739104349Sphkto a structure that contains the element model. It is the 1740178848Scokaneapplication's responsibility to free this data structure using 1741178848Scokane<code><a href="#XML_FreeContentModel" 1742178848Scokane>XML_FreeContentModel</a></code>.</p> 1743104349Sphk 1744104349Sphk<p>The <code>model</code> argument is the root of a tree of 1745104349Sphk<code>XML_Content</code> nodes. If <code>type</code> equals 1746104349Sphk<code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then 1747104349Sphk<code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other 1748104349Sphkfields will be zero or NULL. If <code>type</code> is 1749104349Sphk<code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be 1750104349Sphk<code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and 1751104349Sphk<code>numchildren</code> will contain the number of elements that are 1752104349Sphkallowed to be mixed in and <code>children</code> points to an array of 1753104349Sphk<code>XML_Content</code> structures that will all have type 1754104349SphkXML_CTYPE_NAME with no quantification. Only the root node can be type 1755104349Sphk<code>XML_CTYPE_EMPTY</code>, <code>XML_CTYPE_ANY</code>, or 1756104349Sphk<code>XML_CTYPE_MIXED</code>.</p> 1757104349Sphk 1758104349Sphk<p>For type <code>XML_CTYPE_NAME</code>, the <code>name</code> field 1759104349Sphkpoints to the name and the <code>numchildren</code> and 1760104349Sphk<code>children</code> fields will be zero and NULL. The 1761104349Sphk<code>quant</code> field will indicate any quantifiers placed on the 1762104349Sphkname.</p> 1763104349Sphk 1764104349Sphk<p>Types <code>XML_CTYPE_CHOICE</code> and <code>XML_CTYPE_SEQ</code> 1765104349Sphkindicate a choice or sequence respectively. The 1766104349Sphk<code>numchildren</code> field indicates how many nodes in the choice 1767104349Sphkor sequence and <code>children</code> points to the nodes.</p> 1768104349Sphk</div> 1769104349Sphk 1770104349Sphk<div class="handler"> 1771104349Sphk<pre class="setter" id="XML_SetAttlistDeclHandler"> 1772178848Scokanevoid XMLCALL 1773104349SphkXML_SetAttlistDeclHandler(XML_Parser p, 1774104349Sphk XML_AttlistDeclHandler attdecl); 1775104349Sphk</pre> 1776104349Sphk<pre class="signature"> 1777104349Sphktypedef void 1778178848Scokane(XMLCALL *XML_AttlistDeclHandler)(void *userData, 1779178848Scokane const XML_Char *elname, 1780178848Scokane const XML_Char *attname, 1781178848Scokane const XML_Char *att_type, 1782178848Scokane const XML_Char *dflt, 1783178848Scokane int isrequired); 1784104349Sphk</pre> 1785104349Sphk<p>Set a handler for attlist declarations in the DTD. This handler is 1786104349Sphkcalled for <em>each</em> attribute. So a single attlist declaration 1787104349Sphkwith multiple attributes declared will generate multiple calls to this 1788104349Sphkhandler. The <code>elname</code> parameter returns the name of the 1789104349Sphkelement for which the attribute is being declared. The attribute name 1790104349Sphkis in the <code>attname</code> parameter. The attribute type is in the 1791104349Sphk<code>att_type</code> parameter. It is the string representing the 1792104349Sphktype in the declaration with whitespace removed.</p> 1793104349Sphk 1794104349Sphk<p>The <code>dflt</code> parameter holds the default value. It will be 1795104349SphkNULL in the case of "#IMPLIED" or "#REQUIRED" attributes. You can 1796104349Sphkdistinguish these two cases by checking the <code>isrequired</code> 1797104349Sphkparameter, which will be true in the case of "#REQUIRED" attributes. 1798104349SphkAttributes which are "#FIXED" will have also have a true 1799104349Sphk<code>isrequired</code>, but they will have the non-NULL fixed value 1800104349Sphkin the <code>dflt</code> parameter.</p> 1801104349Sphk</div> 1802104349Sphk 1803104349Sphk<div class="handler"> 1804104349Sphk<pre class="setter" id="XML_SetEntityDeclHandler"> 1805178848Scokanevoid XMLCALL 1806104349SphkXML_SetEntityDeclHandler(XML_Parser p, 1807104349Sphk XML_EntityDeclHandler handler); 1808104349Sphk</pre> 1809104349Sphk<pre class="signature"> 1810104349Sphktypedef void 1811178848Scokane(XMLCALL *XML_EntityDeclHandler)(void *userData, 1812178848Scokane const XML_Char *entityName, 1813178848Scokane int is_parameter_entity, 1814178848Scokane const XML_Char *value, 1815178848Scokane int value_length, 1816178848Scokane const XML_Char *base, 1817178848Scokane const XML_Char *systemId, 1818178848Scokane const XML_Char *publicId, 1819178848Scokane const XML_Char *notationName); 1820104349Sphk</pre> 1821104349Sphk<p>Sets a handler that will be called for all entity declarations. 1822104349SphkThe <code>is_parameter_entity</code> argument will be non-zero in the 1823104349Sphkcase of parameter entities and zero otherwise.</p> 1824104349Sphk 1825104349Sphk<p>For internal entities (<code><!ENTITY foo "bar"></code>), 1826104349Sphk<code>value</code> will be non-NULL and <code>systemId</code>, 1827104349Sphk<code>publicId</code>, and <code>notationName</code> will all be NULL. 1828104349SphkThe value string is <em>not</em> NULL terminated; the length is 1829104349Sphkprovided in the <code>value_length</code> parameter. Do not use 1830104349Sphk<code>value_length</code> to test for internal entities, since it is 1831104349Sphklegal to have zero-length values. Instead check for whether or not 1832104349Sphk<code>value</code> is NULL.</p> <p>The <code>notationName</code> 1833104349Sphkargument will have a non-NULL value only for unparsed entity 1834104349Sphkdeclarations.</p> 1835104349Sphk</div> 1836104349Sphk 1837104349Sphk<div class="handler"> 1838104349Sphk<pre class="setter" id="XML_SetUnparsedEntityDeclHandler"> 1839178848Scokanevoid XMLCALL 1840104349SphkXML_SetUnparsedEntityDeclHandler(XML_Parser p, 1841104349Sphk XML_UnparsedEntityDeclHandler h) 1842104349Sphk</pre> 1843104349Sphk<pre class="signature"> 1844104349Sphktypedef void 1845178848Scokane(XMLCALL *XML_UnparsedEntityDeclHandler)(void *userData, 1846178848Scokane const XML_Char *entityName, 1847178848Scokane const XML_Char *base, 1848178848Scokane const XML_Char *systemId, 1849178848Scokane const XML_Char *publicId, 1850178848Scokane const XML_Char *notationName); 1851104349Sphk</pre> 1852104349Sphk<p>Set a handler that receives declarations of unparsed entities. These 1853104349Sphkare entity declarations that have a notation (NDATA) field:</p> 1854104349Sphk 1855104349Sphk<div id="eg"><pre> 1856104349Sphk<!ENTITY logo SYSTEM "images/logo.gif" NDATA gif> 1857104349Sphk</pre></div> 1858104349Sphk<p>This handler is obsolete and is provided for backwards 1859104349Sphkcompatibility. Use instead <a href= "#XML_SetEntityDeclHandler" 1860104349Sphk>XML_SetEntityDeclHandler</a>.</p> 1861104349Sphk</div> 1862104349Sphk 1863104349Sphk<div class="handler"> 1864104349Sphk<pre class="setter" id="XML_SetNotationDeclHandler"> 1865178848Scokanevoid XMLCALL 1866104349SphkXML_SetNotationDeclHandler(XML_Parser p, 1867104349Sphk XML_NotationDeclHandler h) 1868104349Sphk</pre> 1869104349Sphk<pre class="signature"> 1870104349Sphktypedef void 1871178848Scokane(XMLCALL *XML_NotationDeclHandler)(void *userData, 1872178848Scokane const XML_Char *notationName, 1873178848Scokane const XML_Char *base, 1874178848Scokane const XML_Char *systemId, 1875178848Scokane const XML_Char *publicId); 1876104349Sphk</pre> 1877104349Sphk<p>Set a handler that receives notation declarations.</p> 1878104349Sphk</div> 1879104349Sphk 1880104349Sphk<div class="handler"> 1881104349Sphk<pre class="setter" id="XML_SetNotStandaloneHandler"> 1882178848Scokanevoid XMLCALL 1883104349SphkXML_SetNotStandaloneHandler(XML_Parser p, 1884104349Sphk XML_NotStandaloneHandler h) 1885104349Sphk</pre> 1886104349Sphk<pre class="signature"> 1887104349Sphktypedef int 1888178848Scokane(XMLCALL *XML_NotStandaloneHandler)(void *userData); 1889104349Sphk</pre> 1890104349Sphk<p>Set a handler that is called if the document is not "standalone". 1891104349SphkThis happens when there is an external subset or a reference to a 1892104349Sphkparameter entity, but does not have standalone set to "yes" in an XML 1893178848Scokanedeclaration. If this handler returns <code>XML_STATUS_ERROR</code>, 1894178848Scokanethen the parser will throw an <code>XML_ERROR_NOT_STANDALONE</code> 1895178848Scokaneerror.</p> 1896104349Sphk</div> 1897104349Sphk 1898104349Sphk<h3><a name="position">Parse position and error reporting functions</a></h3> 1899104349Sphk 1900104349Sphk<p>These are the functions you'll want to call when the parse 1901178848Scokanefunctions return <code>XML_STATUS_ERROR</code> (a parse error has 1902178848Scokaneoccurred), although the position reporting functions are useful outside 1903178848Scokaneof errors. The position reported is the byte position (in the original 1904178848Scokanedocument or entity encoding) of the first of the sequence of 1905178848Scokanecharacters that generated the current event (or the error that caused 1906178848Scokanethe parse functions to return <code>XML_STATUS_ERROR</code>.) The 1907178848Scokaneexceptions are callbacks trigged by declarations in the document 1908178848Scokaneprologue, in which case they exact position reported is somewhere in the 1909178848Scokanerelevant markup, but not necessarily as meaningful as for other 1910178848Scokaneevents.</p> 1911104349Sphk 1912104349Sphk<p>The position reporting functions are accurate only outside of the 1913104349SphkDTD. In other words, they usually return bogus information when 1914104349Sphkcalled from within a DTD declaration handler.</p> 1915104349Sphk 1916104349Sphk<pre class="fcndec" id="XML_GetErrorCode"> 1917178848Scokaneenum XML_Error XMLCALL 1918104349SphkXML_GetErrorCode(XML_Parser p); 1919104349Sphk</pre> 1920104349Sphk<div class="fcndef"> 1921104349SphkReturn what type of error has occurred. 1922104349Sphk</div> 1923104349Sphk 1924104349Sphk<pre class="fcndec" id="XML_ErrorString"> 1925178848Scokaneconst XML_LChar * XMLCALL 1926178848ScokaneXML_ErrorString(enum XML_Error code); 1927104349Sphk</pre> 1928104349Sphk<div class="fcndef"> 1929104349SphkReturn a string describing the error corresponding to code. 1930104349SphkThe code should be one of the enums that can be returned from 1931104349Sphk<code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>. 1932104349Sphk</div> 1933104349Sphk 1934104349Sphk<pre class="fcndec" id="XML_GetCurrentByteIndex"> 1935178848ScokaneXML_Index XMLCALL 1936104349SphkXML_GetCurrentByteIndex(XML_Parser p); 1937104349Sphk</pre> 1938104349Sphk<div class="fcndef"> 1939178848ScokaneReturn the byte offset of the position. This always corresponds to 1940178848Scokanethe values returned by <code><a href= "#XML_GetCurrentLineNumber" 1941178848Scokane>XML_GetCurrentLineNumber</a></code> and <code><a href= 1942178848Scokane"#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>. 1943104349Sphk</div> 1944104349Sphk 1945104349Sphk<pre class="fcndec" id="XML_GetCurrentLineNumber"> 1946178848ScokaneXML_Size XMLCALL 1947104349SphkXML_GetCurrentLineNumber(XML_Parser p); 1948104349Sphk</pre> 1949104349Sphk<div class="fcndef"> 1950178848ScokaneReturn the line number of the position. The first line is reported as 1951178848Scokane<code>1</code>. 1952104349Sphk</div> 1953104349Sphk 1954104349Sphk<pre class="fcndec" id="XML_GetCurrentColumnNumber"> 1955178848ScokaneXML_Size XMLCALL 1956104349SphkXML_GetCurrentColumnNumber(XML_Parser p); 1957104349Sphk</pre> 1958104349Sphk<div class="fcndef"> 1959104349SphkReturn the offset, from the beginning of the current line, of 1960104349Sphkthe position. 1961104349Sphk</div> 1962104349Sphk 1963104349Sphk<pre class="fcndec" id="XML_GetCurrentByteCount"> 1964178848Scokaneint XMLCALL 1965104349SphkXML_GetCurrentByteCount(XML_Parser p); 1966104349Sphk</pre> 1967104349Sphk<div class="fcndef"> 1968104349SphkReturn the number of bytes in the current event. Returns 1969104349Sphk<code>0</code> if the event is inside a reference to an internal 1970104349Sphkentity and for the end-tag event for empty element tags (the later can 1971104349Sphkbe used to distinguish empty-element tags from empty elements using 1972104349Sphkseparate start and end tags). 1973104349Sphk</div> 1974104349Sphk 1975104349Sphk<pre class="fcndec" id="XML_GetInputContext"> 1976178848Scokaneconst char * XMLCALL 1977104349SphkXML_GetInputContext(XML_Parser p, 1978104349Sphk int *offset, 1979104349Sphk int *size); 1980104349Sphk</pre> 1981104349Sphk<div class="fcndef"> 1982104349Sphk 1983104349Sphk<p>Returns the parser's input buffer, sets the integer pointed at by 1984104349Sphk<code>offset</code> to the offset within this buffer of the current 1985104349Sphkparse position, and set the integer pointed at by <code>size</code> to 1986104349Sphkthe size of the returned buffer.</p> 1987104349Sphk 1988104349Sphk<p>This should only be called from within a handler during an active 1989104349Sphkparse and the returned buffer should only be referred to from within 1990104349Sphkthe handler that made the call. This input buffer contains the 1991104349Sphkuntranslated bytes of the input.</p> 1992104349Sphk 1993104349Sphk<p>Only a limited amount of context is kept, so if the event 1994104349Sphktriggering a call spans over a very large amount of input, the actual 1995104349Sphkparse position may be before the beginning of the buffer.</p> 1996178848Scokane 1997178848Scokane<p>If <code>XML_CONTEXT_BYTES</code> is not defined, this will always 1998178848Scokanereturn NULL.</p> 1999104349Sphk</div> 2000104349Sphk 2001104349Sphk<h3><a name="miscellaneous">Miscellaneous functions</a></h3> 2002104349Sphk 2003104349Sphk<p>The functions in this section either obtain state information from 2004355604Sdelphijthe parser or can be used to dynamically set parser options.</p> 2005104349Sphk 2006104349Sphk<pre class="fcndec" id="XML_SetUserData"> 2007178848Scokanevoid XMLCALL 2008104349SphkXML_SetUserData(XML_Parser p, 2009104349Sphk void *userData); 2010104349Sphk</pre> 2011104349Sphk<div class="fcndef"> 2012104349SphkThis sets the user data pointer that gets passed to handlers. It 2013104349Sphkoverwrites any previous value for this pointer. Note that the 2014104349Sphkapplication is responsible for freeing the memory associated with 2015104349Sphk<code>userData</code> when it is finished with the parser. So if you 2016104349Sphkcall this when there's already a pointer there, and you haven't freed 2017104349Sphkthe memory associated with it, then you've probably just leaked 2018104349Sphkmemory. 2019104349Sphk</div> 2020104349Sphk 2021104349Sphk<pre class="fcndec" id="XML_GetUserData"> 2022178848Scokanevoid * XMLCALL 2023104349SphkXML_GetUserData(XML_Parser p); 2024104349Sphk</pre> 2025104349Sphk<div class="fcndef"> 2026104349SphkThis returns the user data pointer that gets passed to handlers. 2027104349SphkIt is actually implemented as a macro. 2028104349Sphk</div> 2029104349Sphk 2030104349Sphk<pre class="fcndec" id="XML_UseParserAsHandlerArg"> 2031178848Scokanevoid XMLCALL 2032104349SphkXML_UseParserAsHandlerArg(XML_Parser p); 2033104349Sphk</pre> 2034104349Sphk<div class="fcndef"> 2035178848ScokaneAfter this is called, handlers receive the parser in their 2036178848Scokane<code>userData</code> arguments. The user data can still be obtained 2037178848Scokaneusing the <code><a href= "#XML_GetUserData" 2038178848Scokane>XML_GetUserData</a></code> function. 2039104349Sphk</div> 2040104349Sphk 2041104349Sphk<pre class="fcndec" id="XML_SetBase"> 2042178848Scokaneenum XML_Status XMLCALL 2043104349SphkXML_SetBase(XML_Parser p, 2044104349Sphk const XML_Char *base); 2045104349Sphk</pre> 2046104349Sphk<div class="fcndef"> 2047104349SphkSet the base to be used for resolving relative URIs in system 2048178848Scokaneidentifiers. The return value is <code>XML_STATUS_ERROR</code> if 2049178848Scokanethere's no memory to store base, otherwise it's 2050178848Scokane<code>XML_STATUS_OK</code>. 2051104349Sphk</div> 2052104349Sphk 2053104349Sphk<pre class="fcndec" id="XML_GetBase"> 2054178848Scokaneconst XML_Char * XMLCALL 2055104349SphkXML_GetBase(XML_Parser p); 2056104349Sphk</pre> 2057104349Sphk<div class="fcndef"> 2058104349SphkReturn the base for resolving relative URIs. 2059104349Sphk</div> 2060104349Sphk 2061104349Sphk<pre class="fcndec" id="XML_GetSpecifiedAttributeCount"> 2062178848Scokaneint XMLCALL 2063104349SphkXML_GetSpecifiedAttributeCount(XML_Parser p); 2064104349Sphk</pre> 2065104349Sphk<div class="fcndef"> 2066104349SphkWhen attributes are reported to the start handler in the atts vector, 2067104349Sphkattributes that were explicitly set in the element occur before any 2068104349Sphkattributes that receive their value from default information in an 2069104349SphkATTLIST declaration. This function returns the number of attributes 2070104349Sphkthat were explicitly set times two, thus giving the offset in the 2071104349Sphk<code>atts</code> array passed to the start tag handler of the first 2072104349Sphkattribute set due to defaults. It supplies information for the last 2073104349Sphkcall to a start handler. If called inside a start handler, then that 2074104349Sphkmeans the current call. 2075104349Sphk</div> 2076104349Sphk 2077104349Sphk<pre class="fcndec" id="XML_GetIdAttributeIndex"> 2078178848Scokaneint XMLCALL 2079104349SphkXML_GetIdAttributeIndex(XML_Parser p); 2080104349Sphk</pre> 2081104349Sphk<div class="fcndef"> 2082104349SphkReturns the index of the ID attribute passed in the atts array in the 2083104349Sphklast call to <code><a href= "#XML_StartElementHandler" 2084104349Sphk>XML_StartElementHandler</a></code>, or -1 if there is no ID 2085104349Sphkattribute. If called inside a start handler, then that means the 2086104349Sphkcurrent call. 2087104349Sphk</div> 2088104349Sphk 2089247296Sdelphij<pre class="fcndec" id="XML_GetAttributeInfo"> 2090247296Sdelphijconst XML_AttrInfo * XMLCALL 2091247296SdelphijXML_GetAttributeInfo(XML_Parser parser); 2092247296Sdelphij</pre> 2093247296Sdelphij<pre class="signature"> 2094247296Sdelphijtypedef struct { 2095247296Sdelphij XML_Index nameStart; /* Offset to beginning of the attribute name. */ 2096247296Sdelphij XML_Index nameEnd; /* Offset after the attribute name's last byte. */ 2097247296Sdelphij XML_Index valueStart; /* Offset to beginning of the attribute value. */ 2098247296Sdelphij XML_Index valueEnd; /* Offset after the attribute value's last byte. */ 2099247296Sdelphij} XML_AttrInfo; 2100247296Sdelphij</pre> 2101247296Sdelphij<div class="fcndef"> 2102247296SdelphijReturns an array of <code>XML_AttrInfo</code> structures for the 2103247296Sdelphijattribute/value pairs passed in the last call to the 2104247296Sdelphij<code>XML_StartElementHandler</code> that were specified 2105247296Sdelphijin the start-tag rather than defaulted. Each attribute/value pair counts 2106247296Sdelphijas 1; thus the number of entries in the array is 2107247296Sdelphij<code>XML_GetSpecifiedAttributeCount(parser) / 2</code>. 2108247296Sdelphij</div> 2109247296Sdelphij 2110104349Sphk<pre class="fcndec" id="XML_SetEncoding"> 2111178848Scokaneenum XML_Status XMLCALL 2112104349SphkXML_SetEncoding(XML_Parser p, 2113104349Sphk const XML_Char *encoding); 2114104349Sphk</pre> 2115104349Sphk<div class="fcndef"> 2116104349SphkSet the encoding to be used by the parser. It is equivalent to 2117104349Sphkpassing a non-null encoding argument to the parser creation functions. 2118104349SphkIt must not be called after <code><a href= "#XML_Parse" 2119104349Sphk>XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer" 2120104349Sphk>XML_ParseBuffer</a></code> have been called on the given parser. 2121178848ScokaneReturns <code>XML_STATUS_OK</code> on success or 2122178848Scokane<code>XML_STATUS_ERROR</code> on error. 2123104349Sphk</div> 2124104349Sphk 2125104349Sphk<pre class="fcndec" id="XML_SetParamEntityParsing"> 2126178848Scokaneint XMLCALL 2127104349SphkXML_SetParamEntityParsing(XML_Parser p, 2128104349Sphk enum XML_ParamEntityParsing code); 2129104349Sphk</pre> 2130104349Sphk<div class="fcndef"> 2131104349SphkThis enables parsing of parameter entities, including the external 2132104349Sphkparameter entity that is the external DTD subset, according to 2133104349Sphk<code>code</code>. 2134104349SphkThe choices for <code>code</code> are: 2135104349Sphk<ul> 2136104349Sphk<li><code>XML_PARAM_ENTITY_PARSING_NEVER</code></li> 2137104349Sphk<li><code>XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE</code></li> 2138104349Sphk<li><code>XML_PARAM_ENTITY_PARSING_ALWAYS</code></li> 2139104349Sphk</ul> 2140247296Sdelphij<b>Note:</b> If <code>XML_SetParamEntityParsing</code> is called after 2141247296Sdelphij<code>XML_Parse</code> or <code>XML_ParseBuffer</code>, then it has 2142247296Sdelphijno effect and will always return 0. 2143104349Sphk</div> 2144104349Sphk 2145247296Sdelphij<pre class="fcndec" id="XML_SetHashSalt"> 2146247296Sdelphijint XMLCALL 2147247296SdelphijXML_SetHashSalt(XML_Parser p, 2148247296Sdelphij unsigned long hash_salt); 2149247296Sdelphij</pre> 2150247296Sdelphij<div class="fcndef"> 2151247296SdelphijSets the hash salt to use for internal hash calculations. 2152247296SdelphijHelps in preventing DoS attacks based on predicting hash 2153247296Sdelphijfunction behavior. In order to have an effect this must be called 2154247296Sdelphijbefore parsing has started. Returns 1 if successful, 0 when called 2155247296Sdelphijafter <code>XML_Parse</code> or <code>XML_ParseBuffer</code>. 2156302305Sdelphij<p><b>Note:</b>This call is optional, as the parser will auto-generate 2157355604Sdelphija new random salt value if no value has been set at the start of parsing.</p> 2158302305Sdelphij<p><b>Note:</b>One should not call <code>XML_SetHashSalt</code> with a 2159302305Sdelphijhash salt value of 0, as this value is used as sentinel value to indicate 2160302305Sdelphijthat <code>XML_SetHashSalt</code> has <b>not</b> been called. Consequently 2161302305Sdelphijsuch a call will have no effect, even if it returns 1.</p> 2162247296Sdelphij</div> 2163247296Sdelphij 2164104349Sphk<pre class="fcndec" id="XML_UseForeignDTD"> 2165178848Scokaneenum XML_Error XMLCALL 2166104349SphkXML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); 2167104349Sphk</pre> 2168104349Sphk<div class="fcndef"> 2169104349Sphk<p>This function allows an application to provide an external subset 2170104349Sphkfor the document type declaration for documents which do not specify 2171104349Sphkan external subset of their own. For documents which specify an 2172104349Sphkexternal subset in their DOCTYPE declaration, the application-provided 2173104349Sphksubset will be ignored. If the document does not contain a DOCTYPE 2174104349Sphkdeclaration at all and <code>useDTD</code> is true, the 2175104349Sphkapplication-provided subset will be parsed, but the 2176104349Sphk<code>startDoctypeDeclHandler</code> and 2177104349Sphk<code>endDoctypeDeclHandler</code> functions, if set, will not be 2178104349Sphkcalled. The setting of parameter entity parsing, controlled using 2179104349Sphk<code><a href= "#XML_SetParamEntityParsing" 2180104349Sphk>XML_SetParamEntityParsing</a></code>, will be honored.</p> 2181104349Sphk 2182104349Sphk<p>The application-provided external subset is read by calling the 2183104349Sphkexternal entity reference handler set via <code><a href= 2184104349Sphk"#XML_SetExternalEntityRefHandler" 2185104349Sphk>XML_SetExternalEntityRefHandler</a></code> with both 2186104349Sphk<code>publicId</code> and <code>systemId</code> set to NULL.</p> 2187104349Sphk 2188104349Sphk<p>If this function is called after parsing has begun, it returns 2189104349Sphk<code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores 2190104349Sphk<code>useDTD</code>. If called when Expat has been compiled without 2191104349SphkDTD support, it returns 2192104349Sphk<code>XML_ERROR_FEATURE_REQUIRES_XML_DTD</code>. Otherwise, it 2193104349Sphkreturns <code>XML_ERROR_NONE</code>.</p> 2194178848Scokane 2195178848Scokane<p><b>Note:</b> For the purpose of checking WFC: Entity Declared, passing 2196178848Scokane<code>useDTD == XML_TRUE</code> will make the parser behave as if 2197178848Scokanethe document had a DTD with an external subset. This holds true even if 2198178848Scokanethe external entity reference handler returns without action.</p> 2199104349Sphk</div> 2200104349Sphk 2201104349Sphk<pre class="fcndec" id="XML_SetReturnNSTriplet"> 2202178848Scokanevoid XMLCALL 2203104349SphkXML_SetReturnNSTriplet(XML_Parser parser, 2204104349Sphk int do_nst); 2205104349Sphk</pre> 2206104349Sphk<div class="fcndef"> 2207104349Sphk<p> 2208104349SphkThis function only has an effect when using a parser created with 2209104349Sphk<code><a href= "#XML_ParserCreateNS" >XML_ParserCreateNS</a></code>, 2210104349Sphki.e. when namespace processing is in effect. The <code>do_nst</code> 2211104349Sphksets whether or not prefixes are returned with names qualified with a 2212104349Sphknamespace prefix. If this function is called with <code>do_nst</code> 2213104349Sphknon-zero, then afterwards namespace qualified names (that is qualified 2214104349Sphkwith a prefix as opposed to belonging to a default namespace) are 2215104349Sphkreturned as a triplet with the three parts separated by the namespace 2216104349Sphkseparator specified when the parser was created. The order of 2217104349Sphkreturned parts is URI, local name, and prefix.</p> <p>If 2218104349Sphk<code>do_nst</code> is zero, then namespaces are reported in the 2219104349Sphkdefault manner, URI then local_name separated by the namespace 2220104349Sphkseparator.</p> 2221104349Sphk</div> 2222104349Sphk 2223104349Sphk<pre class="fcndec" id="XML_DefaultCurrent"> 2224178848Scokanevoid XMLCALL 2225104349SphkXML_DefaultCurrent(XML_Parser parser); 2226104349Sphk</pre> 2227104349Sphk<div class="fcndef"> 2228104349SphkThis can be called within a handler for a start element, end element, 2229104349Sphkprocessing instruction or character data. It causes the corresponding 2230104349Sphkmarkup to be passed to the default handler set by <code><a 2231104349Sphkhref="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or 2232104349Sphk<code><a href="#XML_SetDefaultHandlerExpand" 2233104349Sphk>XML_SetDefaultHandlerExpand</a></code>. It does nothing if there is 2234104349Sphknot a default handler. 2235104349Sphk</div> 2236104349Sphk 2237104349Sphk<pre class="fcndec" id="XML_ExpatVersion"> 2238178848ScokaneXML_LChar * XMLCALL 2239104349SphkXML_ExpatVersion(); 2240104349Sphk</pre> 2241104349Sphk<div class="fcndef"> 2242104349SphkReturn the library version as a string (e.g. <code>"expat_1.95.1"</code>). 2243104349Sphk</div> 2244104349Sphk 2245104349Sphk<pre class="fcndec" id="XML_ExpatVersionInfo"> 2246178848Scokanestruct XML_Expat_Version XMLCALL 2247104349SphkXML_ExpatVersionInfo(); 2248104349Sphk</pre> 2249104349Sphk<pre class="signature"> 2250104349Sphktypedef struct { 2251104349Sphk int major; 2252104349Sphk int minor; 2253104349Sphk int micro; 2254104349Sphk} XML_Expat_Version; 2255104349Sphk</pre> 2256104349Sphk<div class="fcndef"> 2257104349SphkReturn the library version information as a structure. 2258104349SphkSome macros are also defined that support compile-time tests of the 2259104349Sphklibrary version: 2260104349Sphk<ul> 2261104349Sphk<li><code>XML_MAJOR_VERSION</code></li> 2262104349Sphk<li><code>XML_MINOR_VERSION</code></li> 2263104349Sphk<li><code>XML_MICRO_VERSION</code></li> 2264104349Sphk</ul> 2265104349SphkTesting these constants is currently the best way to determine if 2266104349Sphkparticular parts of the Expat API are available. 2267104349Sphk</div> 2268104349Sphk 2269104349Sphk<pre class="fcndec" id="XML_GetFeatureList"> 2270178848Scokaneconst XML_Feature * XMLCALL 2271104349SphkXML_GetFeatureList(); 2272104349Sphk</pre> 2273104349Sphk<pre class="signature"> 2274104349Sphkenum XML_FeatureEnum { 2275104349Sphk XML_FEATURE_END = 0, 2276104349Sphk XML_FEATURE_UNICODE, 2277104349Sphk XML_FEATURE_UNICODE_WCHAR_T, 2278104349Sphk XML_FEATURE_DTD, 2279104349Sphk XML_FEATURE_CONTEXT_BYTES, 2280104349Sphk XML_FEATURE_MIN_SIZE, 2281104349Sphk XML_FEATURE_SIZEOF_XML_CHAR, 2282178848Scokane XML_FEATURE_SIZEOF_XML_LCHAR, 2283178848Scokane XML_FEATURE_NS, 2284178848Scokane XML_FEATURE_LARGE_SIZE 2285104349Sphk}; 2286104349Sphk 2287104349Sphktypedef struct { 2288104349Sphk enum XML_FeatureEnum feature; 2289104349Sphk XML_LChar *name; 2290104349Sphk long int value; 2291104349Sphk} XML_Feature; 2292104349Sphk</pre> 2293104349Sphk<div class="fcndef"> 2294104349Sphk<p>Returns a list of "feature" records, providing details on how 2295104349SphkExpat was configured at compile time. Most applications should not 2296104349Sphkneed to worry about this, but this information is otherwise not 2297104349Sphkavailable from Expat. This function allows code that does need to 2298104349Sphkcheck these features to do so at runtime.</p> 2299104349Sphk 2300104349Sphk<p>The return value is an array of <code>XML_Feature</code>, 2301104349Sphkterminated by a record with a <code>feature</code> of 2302104349Sphk<code>XML_FEATURE_END</code> and <code>name</code> of NULL, 2303104349Sphkidentifying the feature-test macros Expat was compiled with. Since an 2304104349Sphkapplication that requires this kind of information needs to determine 2305104349Sphkthe type of character the <code>name</code> points to, records for the 2306104349Sphk<code>XML_FEATURE_SIZEOF_XML_CHAR</code> and 2307104349Sphk<code>XML_FEATURE_SIZEOF_XML_LCHAR</code> will be located at the 2308104349Sphkbeginning of the list, followed by <code>XML_FEATURE_UNICODE</code> 2309104349Sphkand <code>XML_FEATURE_UNICODE_WCHAR_T</code>, if they are present at 2310104349Sphkall.</p> 2311104349Sphk 2312104349Sphk<p>Some features have an associated value. If there isn't an 2313104349Sphkassociated value, the <code>value</code> field is set to 0. At this 2314104349Sphktime, the following features have been defined to have values:</p> 2315104349Sphk 2316104349Sphk<dl> 2317104349Sphk <dt><code>XML_FEATURE_SIZEOF_XML_CHAR</code></dt> 2318104349Sphk <dd>The number of bytes occupied by one <code>XML_Char</code> 2319104349Sphk character.</dd> 2320104349Sphk <dt><code>XML_FEATURE_SIZEOF_XML_LCHAR</code></dt> 2321104349Sphk <dd>The number of bytes occupied by one <code>XML_LChar</code> 2322104349Sphk character.</dd> 2323104349Sphk <dt><code>XML_FEATURE_CONTEXT_BYTES</code></dt> 2324104349Sphk <dd>The maximum number of characters of context which can be 2325104349Sphk reported by <code><a href= "#XML_GetInputContext" 2326104349Sphk >XML_GetInputContext</a></code>.</dd> 2327104349Sphk</dl> 2328104349Sphk</div> 2329104349Sphk 2330178848Scokane<pre class="fcndec" id="XML_FreeContentModel"> 2331178848Scokanevoid XMLCALL 2332178848ScokaneXML_FreeContentModel(XML_Parser parser, XML_Content *model); 2333178848Scokane</pre> 2334178848Scokane<div class="fcndef"> 2335178848ScokaneFunction to deallocate the <code>model</code> argument passed to the 2336178848Scokane<code>XML_ElementDeclHandler</code> callback set using <code><a 2337178848Scokanehref="#XML_SetElementDeclHandler" >XML_ElementDeclHandler</a></code>. 2338178848ScokaneThis function should not be used for any other purpose. 2339178848Scokane</div> 2340178848Scokane 2341178848Scokane<p>The following functions allow external code to share the memory 2342178848Scokaneallocator an <code>XML_Parser</code> has been configured to use. This 2343178848Scokaneis especially useful for third-party libraries that interact with a 2344178848Scokaneparser object created by application code, or heavily layered 2345178848Scokaneapplications. This can be essential when using dynamically loaded 2346178848Scokanelibraries which use different C standard libraries (this can happen on 2347178848ScokaneWindows, at least).</p> 2348178848Scokane 2349178848Scokane<pre class="fcndec" id="XML_MemMalloc"> 2350178848Scokanevoid * XMLCALL 2351178848ScokaneXML_MemMalloc(XML_Parser parser, size_t size); 2352178848Scokane</pre> 2353178848Scokane<div class="fcndef"> 2354178848ScokaneAllocate <code>size</code> bytes of memory using the allocator the 2355178848Scokane<code>parser</code> object has been configured to use. Returns a 2356178848Scokanepointer to the memory or NULL on failure. Memory allocated in this 2357178848Scokaneway must be freed using <code><a href="#XML_MemFree" 2358178848Scokane>XML_MemFree</a></code>. 2359178848Scokane</div> 2360178848Scokane 2361178848Scokane<pre class="fcndec" id="XML_MemRealloc"> 2362178848Scokanevoid * XMLCALL 2363178848ScokaneXML_MemRealloc(XML_Parser parser, void *ptr, size_t size); 2364178848Scokane</pre> 2365178848Scokane<div class="fcndef"> 2366178848ScokaneAllocate <code>size</code> bytes of memory using the allocator the 2367178848Scokane<code>parser</code> object has been configured to use. 2368178848Scokane<code>ptr</code> must point to a block of memory allocated by <code><a 2369178848Scokanehref="#XML_MemMalloc" >XML_MemMalloc</a></code> or 2370178848Scokane<code>XML_MemRealloc</code>, or be NULL. This function tries to 2371178848Scokaneexpand the block pointed to by <code>ptr</code> if possible. Returns 2372178848Scokanea pointer to the memory or NULL on failure. On success, the original 2373178848Scokaneblock has either been expanded or freed. On failure, the original 2374178848Scokaneblock has not been freed; the caller is responsible for freeing the 2375178848Scokaneoriginal block. Memory allocated in this way must be freed using 2376178848Scokane<code><a href="#XML_MemFree" 2377178848Scokane>XML_MemFree</a></code>. 2378178848Scokane</div> 2379178848Scokane 2380178848Scokane<pre class="fcndec" id="XML_MemFree"> 2381178848Scokanevoid XMLCALL 2382178848ScokaneXML_MemFree(XML_Parser parser, void *ptr); 2383178848Scokane</pre> 2384178848Scokane<div class="fcndef"> 2385178848ScokaneFree a block of memory pointed to by <code>ptr</code>. The block must 2386178848Scokanehave been allocated by <code><a href="#XML_MemMalloc" 2387178848Scokane>XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be NULL. 2388178848Scokane</div> 2389178848Scokane 2390104349Sphk<hr /> 2391104349Sphk<p><a href="http://validator.w3.org/check/referer"><img 2392104349Sphk src="valid-xhtml10.png" alt="Valid XHTML 1.0!" 2393104349Sphk height="31" width="88" class="noborder" /></a></p> 2394178848Scokane</div> 2395104349Sphk</body> 2396104349Sphk</html> 2397