reference.html 102 KB

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