reference.html 93 KB

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