reference.html 91 KB

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