reference.html 135 KB

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