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