reference.html 111 KB

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