expat.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
  2. See the file COPYING for copying permission.
  3. */
  4. #ifndef Expat_INCLUDED
  5. #define Expat_INCLUDED 1
  6. #ifdef __VMS
  7. /* 0 1 2 3 0 1 2 3
  8. 1234567890123456789012345678901 1234567890123456789012345678901 */
  9. #define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler
  10. #define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler
  11. #define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler
  12. #define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg
  13. #endif
  14. #include <stdlib.h>
  15. #include "expat_external.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. struct XML_ParserStruct;
  20. typedef struct XML_ParserStruct *XML_Parser;
  21. /* Should this be defined using stdbool.h when C99 is available? */
  22. typedef unsigned char XML_Bool;
  23. #define XML_TRUE ((XML_Bool) 1)
  24. #define XML_FALSE ((XML_Bool) 0)
  25. /* The XML_Status enum gives the possible return values for several
  26. API functions. The preprocessor #defines are included so this
  27. stanza can be added to code that still needs to support older
  28. versions of Expat 1.95.x:
  29. #ifndef XML_STATUS_OK
  30. #define XML_STATUS_OK 1
  31. #define XML_STATUS_ERROR 0
  32. #endif
  33. Otherwise, the #define hackery is quite ugly and would have been
  34. dropped.
  35. */
  36. enum XML_Status {
  37. XML_STATUS_ERROR = 0,
  38. #define XML_STATUS_ERROR XML_STATUS_ERROR
  39. XML_STATUS_OK = 1,
  40. #define XML_STATUS_OK XML_STATUS_OK
  41. XML_STATUS_SUSPENDED = 2
  42. #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
  43. };
  44. enum XML_Error {
  45. XML_ERROR_NONE,
  46. XML_ERROR_NO_MEMORY,
  47. XML_ERROR_SYNTAX,
  48. XML_ERROR_NO_ELEMENTS,
  49. XML_ERROR_INVALID_TOKEN,
  50. XML_ERROR_UNCLOSED_TOKEN,
  51. XML_ERROR_PARTIAL_CHAR,
  52. XML_ERROR_TAG_MISMATCH,
  53. XML_ERROR_DUPLICATE_ATTRIBUTE,
  54. XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
  55. XML_ERROR_PARAM_ENTITY_REF,
  56. XML_ERROR_UNDEFINED_ENTITY,
  57. XML_ERROR_RECURSIVE_ENTITY_REF,
  58. XML_ERROR_ASYNC_ENTITY,
  59. XML_ERROR_BAD_CHAR_REF,
  60. XML_ERROR_BINARY_ENTITY_REF,
  61. XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
  62. XML_ERROR_MISPLACED_XML_PI,
  63. XML_ERROR_UNKNOWN_ENCODING,
  64. XML_ERROR_INCORRECT_ENCODING,
  65. XML_ERROR_UNCLOSED_CDATA_SECTION,
  66. XML_ERROR_EXTERNAL_ENTITY_HANDLING,
  67. XML_ERROR_NOT_STANDALONE,
  68. XML_ERROR_UNEXPECTED_STATE,
  69. XML_ERROR_ENTITY_DECLARED_IN_PE,
  70. XML_ERROR_FEATURE_REQUIRES_XML_DTD,
  71. XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
  72. /* Added in 1.95.7. */
  73. XML_ERROR_UNBOUND_PREFIX,
  74. /* Added in 1.95.8. */
  75. XML_ERROR_UNDECLARING_PREFIX,
  76. XML_ERROR_INCOMPLETE_PE,
  77. XML_ERROR_XML_DECL,
  78. XML_ERROR_TEXT_DECL,
  79. XML_ERROR_PUBLICID,
  80. XML_ERROR_SUSPENDED,
  81. XML_ERROR_NOT_SUSPENDED,
  82. XML_ERROR_ABORTED,
  83. XML_ERROR_FINISHED,
  84. XML_ERROR_SUSPEND_PE,
  85. /* Added in 2.0. */
  86. XML_ERROR_RESERVED_PREFIX_XML,
  87. XML_ERROR_RESERVED_PREFIX_XMLNS,
  88. XML_ERROR_RESERVED_NAMESPACE_URI,
  89. /* Added in 2.2.1. */
  90. XML_ERROR_INVALID_ARGUMENT
  91. };
  92. enum XML_Content_Type {
  93. XML_CTYPE_EMPTY = 1,
  94. XML_CTYPE_ANY,
  95. XML_CTYPE_MIXED,
  96. XML_CTYPE_NAME,
  97. XML_CTYPE_CHOICE,
  98. XML_CTYPE_SEQ
  99. };
  100. enum XML_Content_Quant {
  101. XML_CQUANT_NONE,
  102. XML_CQUANT_OPT,
  103. XML_CQUANT_REP,
  104. XML_CQUANT_PLUS
  105. };
  106. /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
  107. XML_CQUANT_NONE, and the other fields will be zero or NULL.
  108. If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
  109. numchildren will contain number of elements that may be mixed in
  110. and children point to an array of XML_Content cells that will be
  111. all of XML_CTYPE_NAME type with no quantification.
  112. If type == XML_CTYPE_NAME, then the name points to the name, and
  113. the numchildren field will be zero and children will be NULL. The
  114. quant fields indicates any quantifiers placed on the name.
  115. CHOICE and SEQ will have name NULL, the number of children in
  116. numchildren and children will point, recursively, to an array
  117. of XML_Content cells.
  118. The EMPTY, ANY, and MIXED types will only occur at top level.
  119. */
  120. typedef struct XML_cp XML_Content;
  121. struct XML_cp {
  122. enum XML_Content_Type type;
  123. enum XML_Content_Quant quant;
  124. XML_Char * name;
  125. unsigned int numchildren;
  126. XML_Content * children;
  127. };
  128. /* This is called for an element declaration. See above for
  129. description of the model argument. It's the caller's responsibility
  130. to free model when finished with it.
  131. */
  132. typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
  133. const XML_Char *name,
  134. XML_Content *model);
  135. XMLPARSEAPI(void)
  136. XML_SetElementDeclHandler(XML_Parser parser,
  137. XML_ElementDeclHandler eldecl);
  138. /* The Attlist declaration handler is called for *each* attribute. So
  139. a single Attlist declaration with multiple attributes declared will
  140. generate multiple calls to this handler. The "default" parameter
  141. may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
  142. keyword. The "isrequired" parameter will be true and the default
  143. value will be NULL in the case of "#REQUIRED". If "isrequired" is
  144. true and default is non-NULL, then this is a "#FIXED" default.
  145. */
  146. typedef void (XMLCALL *XML_AttlistDeclHandler) (
  147. void *userData,
  148. const XML_Char *elname,
  149. const XML_Char *attname,
  150. const XML_Char *att_type,
  151. const XML_Char *dflt,
  152. int isrequired);
  153. XMLPARSEAPI(void)
  154. XML_SetAttlistDeclHandler(XML_Parser parser,
  155. XML_AttlistDeclHandler attdecl);
  156. /* The XML declaration handler is called for *both* XML declarations
  157. and text declarations. The way to distinguish is that the version
  158. parameter will be NULL for text declarations. The encoding
  159. parameter may be NULL for XML declarations. The standalone
  160. parameter will be -1, 0, or 1 indicating respectively that there
  161. was no standalone parameter in the declaration, that it was given
  162. as no, or that it was given as yes.
  163. */
  164. typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData,
  165. const XML_Char *version,
  166. const XML_Char *encoding,
  167. int standalone);
  168. XMLPARSEAPI(void)
  169. XML_SetXmlDeclHandler(XML_Parser parser,
  170. XML_XmlDeclHandler xmldecl);
  171. typedef struct {
  172. void *(*malloc_fcn)(size_t size);
  173. void *(*realloc_fcn)(void *ptr, size_t size);
  174. void (*free_fcn)(void *ptr);
  175. } XML_Memory_Handling_Suite;
  176. /* Constructs a new parser; encoding is the encoding specified by the
  177. external protocol or NULL if there is none specified.
  178. */
  179. XMLPARSEAPI(XML_Parser)
  180. XML_ParserCreate(const XML_Char *encoding);
  181. /* Constructs a new parser and namespace processor. Element type
  182. names and attribute names that belong to a namespace will be
  183. expanded; unprefixed attribute names are never expanded; unprefixed
  184. element type names are expanded only if there is a default
  185. namespace. The expanded name is the concatenation of the namespace
  186. URI, the namespace separator character, and the local part of the
  187. name. If the namespace separator is '\0' then the namespace URI
  188. and the local part will be concatenated without any separator.
  189. It is a programming error to use the separator '\0' with namespace
  190. triplets (see XML_SetReturnNSTriplet).
  191. */
  192. XMLPARSEAPI(XML_Parser)
  193. XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
  194. /* Constructs a new parser using the memory management suite referred to
  195. by memsuite. If memsuite is NULL, then use the standard library memory
  196. suite. If namespaceSeparator is non-NULL it creates a parser with
  197. namespace processing as described above. The character pointed at
  198. will serve as the namespace separator.
  199. All further memory operations used for the created parser will come from
  200. the given suite.
  201. */
  202. XMLPARSEAPI(XML_Parser)
  203. XML_ParserCreate_MM(const XML_Char *encoding,
  204. const XML_Memory_Handling_Suite *memsuite,
  205. const XML_Char *namespaceSeparator);
  206. /* Prepare a parser object to be re-used. This is particularly
  207. valuable when memory allocation overhead is disproportionatly high,
  208. such as when a large number of small documnents need to be parsed.
  209. All handlers are cleared from the parser, except for the
  210. unknownEncodingHandler. The parser's external state is re-initialized
  211. except for the values of ns and ns_triplets.
  212. Added in Expat 1.95.3.
  213. */
  214. XMLPARSEAPI(XML_Bool)
  215. XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
  216. /* atts is array of name/value pairs, terminated by 0;
  217. names and values are 0 terminated.
  218. */
  219. typedef void (XMLCALL *XML_StartElementHandler) (void *userData,
  220. const XML_Char *name,
  221. const XML_Char **atts);
  222. typedef void (XMLCALL *XML_EndElementHandler) (void *userData,
  223. const XML_Char *name);
  224. /* s is not 0 terminated. */
  225. typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData,
  226. const XML_Char *s,
  227. int len);
  228. /* target and data are 0 terminated */
  229. typedef void (XMLCALL *XML_ProcessingInstructionHandler) (
  230. void *userData,
  231. const XML_Char *target,
  232. const XML_Char *data);
  233. /* data is 0 terminated */
  234. typedef void (XMLCALL *XML_CommentHandler) (void *userData,
  235. const XML_Char *data);
  236. typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData);
  237. typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData);
  238. /* This is called for any characters in the XML document for which
  239. there is no applicable handler. This includes both characters that
  240. are part of markup which is of a kind that is not reported
  241. (comments, markup declarations), or characters that are part of a
  242. construct which could be reported but for which no handler has been
  243. supplied. The characters are passed exactly as they were in the XML
  244. document except that they will be encoded in UTF-8 or UTF-16.
  245. Line boundaries are not normalized. Note that a byte order mark
  246. character is not passed to the default handler. There are no
  247. guarantees about how characters are divided between calls to the
  248. default handler: for example, a comment might be split between
  249. multiple calls.
  250. */
  251. typedef void (XMLCALL *XML_DefaultHandler) (void *userData,
  252. const XML_Char *s,
  253. int len);
  254. /* This is called for the start of the DOCTYPE declaration, before
  255. any DTD or internal subset is parsed.
  256. */
  257. typedef void (XMLCALL *XML_StartDoctypeDeclHandler) (
  258. void *userData,
  259. const XML_Char *doctypeName,
  260. const XML_Char *sysid,
  261. const XML_Char *pubid,
  262. int has_internal_subset);
  263. /* This is called for the start of the DOCTYPE declaration when the
  264. closing > is encountered, but after processing any external
  265. subset.
  266. */
  267. typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
  268. /* This is called for entity declarations. The is_parameter_entity
  269. argument will be non-zero if the entity is a parameter entity, zero
  270. otherwise.
  271. For internal entities (<!ENTITY foo "bar">), value will
  272. be non-NULL and systemId, publicID, and notationName will be NULL.
  273. The value string is NOT nul-terminated; the length is provided in
  274. the value_length argument. Since it is legal to have zero-length
  275. values, do not use this argument to test for internal entities.
  276. For external entities, value will be NULL and systemId will be
  277. non-NULL. The publicId argument will be NULL unless a public
  278. identifier was provided. The notationName argument will have a
  279. non-NULL value only for unparsed entity declarations.
  280. Note that is_parameter_entity can't be changed to XML_Bool, since
  281. that would break binary compatibility.
  282. */
  283. typedef void (XMLCALL *XML_EntityDeclHandler) (
  284. void *userData,
  285. const XML_Char *entityName,
  286. int is_parameter_entity,
  287. const XML_Char *value,
  288. int value_length,
  289. const XML_Char *base,
  290. const XML_Char *systemId,
  291. const XML_Char *publicId,
  292. const XML_Char *notationName);
  293. XMLPARSEAPI(void)
  294. XML_SetEntityDeclHandler(XML_Parser parser,
  295. XML_EntityDeclHandler handler);
  296. /* OBSOLETE -- OBSOLETE -- OBSOLETE
  297. This handler has been superseded by the EntityDeclHandler above.
  298. It is provided here for backward compatibility.
  299. This is called for a declaration of an unparsed (NDATA) entity.
  300. The base argument is whatever was set by XML_SetBase. The
  301. entityName, systemId and notationName arguments will never be
  302. NULL. The other arguments may be.
  303. */
  304. typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) (
  305. void *userData,
  306. const XML_Char *entityName,
  307. const XML_Char *base,
  308. const XML_Char *systemId,
  309. const XML_Char *publicId,
  310. const XML_Char *notationName);
  311. /* This is called for a declaration of notation. The base argument is
  312. whatever was set by XML_SetBase. The notationName will never be
  313. NULL. The other arguments can be.
  314. */
  315. typedef void (XMLCALL *XML_NotationDeclHandler) (
  316. void *userData,
  317. const XML_Char *notationName,
  318. const XML_Char *base,
  319. const XML_Char *systemId,
  320. const XML_Char *publicId);
  321. /* When namespace processing is enabled, these are called once for
  322. each namespace declaration. The call to the start and end element
  323. handlers occur between the calls to the start and end namespace
  324. declaration handlers. For an xmlns attribute, prefix will be
  325. NULL. For an xmlns="" attribute, uri will be NULL.
  326. */
  327. typedef void (XMLCALL *XML_StartNamespaceDeclHandler) (
  328. void *userData,
  329. const XML_Char *prefix,
  330. const XML_Char *uri);
  331. typedef void (XMLCALL *XML_EndNamespaceDeclHandler) (
  332. void *userData,
  333. const XML_Char *prefix);
  334. /* This is called if the document is not standalone, that is, it has an
  335. external subset or a reference to a parameter entity, but does not
  336. have standalone="yes". If this handler returns XML_STATUS_ERROR,
  337. then processing will not continue, and the parser will return a
  338. XML_ERROR_NOT_STANDALONE error.
  339. If parameter entity parsing is enabled, then in addition to the
  340. conditions above this handler will only be called if the referenced
  341. entity was actually read.
  342. */
  343. typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData);
  344. /* This is called for a reference to an external parsed general
  345. entity. The referenced entity is not automatically parsed. The
  346. application can parse it immediately or later using
  347. XML_ExternalEntityParserCreate.
  348. The parser argument is the parser parsing the entity containing the
  349. reference; it can be passed as the parser argument to
  350. XML_ExternalEntityParserCreate. The systemId argument is the
  351. system identifier as specified in the entity declaration; it will
  352. not be NULL.
  353. The base argument is the system identifier that should be used as
  354. the base for resolving systemId if systemId was relative; this is
  355. set by XML_SetBase; it may be NULL.
  356. The publicId argument is the public identifier as specified in the
  357. entity declaration, or NULL if none was specified; the whitespace
  358. in the public identifier will have been normalized as required by
  359. the XML spec.
  360. The context argument specifies the parsing context in the format
  361. expected by the context argument to XML_ExternalEntityParserCreate;
  362. context is valid only until the handler returns, so if the
  363. referenced entity is to be parsed later, it must be copied.
  364. context is NULL only when the entity is a parameter entity.
  365. The handler should return XML_STATUS_ERROR if processing should not
  366. continue because of a fatal error in the handling of the external
  367. entity. In this case the calling parser will return an
  368. XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
  369. Note that unlike other handlers the first argument is the parser,
  370. not userData.
  371. */
  372. typedef int (XMLCALL *XML_ExternalEntityRefHandler) (
  373. XML_Parser parser,
  374. const XML_Char *context,
  375. const XML_Char *base,
  376. const XML_Char *systemId,
  377. const XML_Char *publicId);
  378. /* This is called in two situations:
  379. 1) An entity reference is encountered for which no declaration
  380. has been read *and* this is not an error.
  381. 2) An internal entity reference is read, but not expanded, because
  382. XML_SetDefaultHandler has been called.
  383. Note: skipped parameter entities in declarations and skipped general
  384. entities in attribute values cannot be reported, because
  385. the event would be out of sync with the reporting of the
  386. declarations or attribute values
  387. */
  388. typedef void (XMLCALL *XML_SkippedEntityHandler) (
  389. void *userData,
  390. const XML_Char *entityName,
  391. int is_parameter_entity);
  392. /* This structure is filled in by the XML_UnknownEncodingHandler to
  393. provide information to the parser about encodings that are unknown
  394. to the parser.
  395. The map[b] member gives information about byte sequences whose
  396. first byte is b.
  397. If map[b] is c where c is >= 0, then b by itself encodes the
  398. Unicode scalar value c.
  399. If map[b] is -1, then the byte sequence is malformed.
  400. If map[b] is -n, where n >= 2, then b is the first byte of an
  401. n-byte sequence that encodes a single Unicode scalar value.
  402. The data member will be passed as the first argument to the convert
  403. function.
  404. The convert function is used to convert multibyte sequences; s will
  405. point to a n-byte sequence where map[(unsigned char)*s] == -n. The
  406. convert function must return the Unicode scalar value represented
  407. by this byte sequence or -1 if the byte sequence is malformed.
  408. The convert function may be NULL if the encoding is a single-byte
  409. encoding, that is if map[b] >= -1 for all bytes b.
  410. When the parser is finished with the encoding, then if release is
  411. not NULL, it will call release passing it the data member; once
  412. release has been called, the convert function will not be called
  413. again.
  414. Expat places certain restrictions on the encodings that are supported
  415. using this mechanism.
  416. 1. Every ASCII character that can appear in a well-formed XML document,
  417. other than the characters
  418. $@\^`{}~
  419. must be represented by a single byte, and that byte must be the
  420. same byte that represents that character in ASCII.
  421. 2. No character may require more than 4 bytes to encode.
  422. 3. All characters encoded must have Unicode scalar values <=
  423. 0xFFFF, (i.e., characters that would be encoded by surrogates in
  424. UTF-16 are not allowed). Note that this restriction doesn't
  425. apply to the built-in support for UTF-8 and UTF-16.
  426. 4. No Unicode character may be encoded by more than one distinct
  427. sequence of bytes.
  428. */
  429. typedef struct {
  430. int map[256];
  431. void *data;
  432. int (XMLCALL *convert)(void *data, const char *s);
  433. void (XMLCALL *release)(void *data);
  434. } XML_Encoding;
  435. /* This is called for an encoding that is unknown to the parser.
  436. The encodingHandlerData argument is that which was passed as the
  437. second argument to XML_SetUnknownEncodingHandler.
  438. The name argument gives the name of the encoding as specified in
  439. the encoding declaration.
  440. If the callback can provide information about the encoding, it must
  441. fill in the XML_Encoding structure, and return XML_STATUS_OK.
  442. Otherwise it must return XML_STATUS_ERROR.
  443. If info does not describe a suitable encoding, then the parser will
  444. return an XML_UNKNOWN_ENCODING error.
  445. */
  446. typedef int (XMLCALL *XML_UnknownEncodingHandler) (
  447. void *encodingHandlerData,
  448. const XML_Char *name,
  449. XML_Encoding *info);
  450. XMLPARSEAPI(void)
  451. XML_SetElementHandler(XML_Parser parser,
  452. XML_StartElementHandler start,
  453. XML_EndElementHandler end);
  454. XMLPARSEAPI(void)
  455. XML_SetStartElementHandler(XML_Parser parser,
  456. XML_StartElementHandler handler);
  457. XMLPARSEAPI(void)
  458. XML_SetEndElementHandler(XML_Parser parser,
  459. XML_EndElementHandler handler);
  460. XMLPARSEAPI(void)
  461. XML_SetCharacterDataHandler(XML_Parser parser,
  462. XML_CharacterDataHandler handler);
  463. XMLPARSEAPI(void)
  464. XML_SetProcessingInstructionHandler(XML_Parser parser,
  465. XML_ProcessingInstructionHandler handler);
  466. XMLPARSEAPI(void)
  467. XML_SetCommentHandler(XML_Parser parser,
  468. XML_CommentHandler handler);
  469. XMLPARSEAPI(void)
  470. XML_SetCdataSectionHandler(XML_Parser parser,
  471. XML_StartCdataSectionHandler start,
  472. XML_EndCdataSectionHandler end);
  473. XMLPARSEAPI(void)
  474. XML_SetStartCdataSectionHandler(XML_Parser parser,
  475. XML_StartCdataSectionHandler start);
  476. XMLPARSEAPI(void)
  477. XML_SetEndCdataSectionHandler(XML_Parser parser,
  478. XML_EndCdataSectionHandler end);
  479. /* This sets the default handler and also inhibits expansion of
  480. internal entities. These entity references will be passed to the
  481. default handler, or to the skipped entity handler, if one is set.
  482. */
  483. XMLPARSEAPI(void)
  484. XML_SetDefaultHandler(XML_Parser parser,
  485. XML_DefaultHandler handler);
  486. /* This sets the default handler but does not inhibit expansion of
  487. internal entities. The entity reference will not be passed to the
  488. default handler.
  489. */
  490. XMLPARSEAPI(void)
  491. XML_SetDefaultHandlerExpand(XML_Parser parser,
  492. XML_DefaultHandler handler);
  493. XMLPARSEAPI(void)
  494. XML_SetDoctypeDeclHandler(XML_Parser parser,
  495. XML_StartDoctypeDeclHandler start,
  496. XML_EndDoctypeDeclHandler end);
  497. XMLPARSEAPI(void)
  498. XML_SetStartDoctypeDeclHandler(XML_Parser parser,
  499. XML_StartDoctypeDeclHandler start);
  500. XMLPARSEAPI(void)
  501. XML_SetEndDoctypeDeclHandler(XML_Parser parser,
  502. XML_EndDoctypeDeclHandler end);
  503. XMLPARSEAPI(void)
  504. XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
  505. XML_UnparsedEntityDeclHandler handler);
  506. XMLPARSEAPI(void)
  507. XML_SetNotationDeclHandler(XML_Parser parser,
  508. XML_NotationDeclHandler handler);
  509. XMLPARSEAPI(void)
  510. XML_SetNamespaceDeclHandler(XML_Parser parser,
  511. XML_StartNamespaceDeclHandler start,
  512. XML_EndNamespaceDeclHandler end);
  513. XMLPARSEAPI(void)
  514. XML_SetStartNamespaceDeclHandler(XML_Parser parser,
  515. XML_StartNamespaceDeclHandler start);
  516. XMLPARSEAPI(void)
  517. XML_SetEndNamespaceDeclHandler(XML_Parser parser,
  518. XML_EndNamespaceDeclHandler end);
  519. XMLPARSEAPI(void)
  520. XML_SetNotStandaloneHandler(XML_Parser parser,
  521. XML_NotStandaloneHandler handler);
  522. XMLPARSEAPI(void)
  523. XML_SetExternalEntityRefHandler(XML_Parser parser,
  524. XML_ExternalEntityRefHandler handler);
  525. /* If a non-NULL value for arg is specified here, then it will be
  526. passed as the first argument to the external entity ref handler
  527. instead of the parser object.
  528. */
  529. XMLPARSEAPI(void)
  530. XML_SetExternalEntityRefHandlerArg(XML_Parser parser,
  531. void *arg);
  532. XMLPARSEAPI(void)
  533. XML_SetSkippedEntityHandler(XML_Parser parser,
  534. XML_SkippedEntityHandler handler);
  535. XMLPARSEAPI(void)
  536. XML_SetUnknownEncodingHandler(XML_Parser parser,
  537. XML_UnknownEncodingHandler handler,
  538. void *encodingHandlerData);
  539. /* This can be called within a handler for a start element, end
  540. element, processing instruction or character data. It causes the
  541. corresponding markup to be passed to the default handler.
  542. */
  543. XMLPARSEAPI(void)
  544. XML_DefaultCurrent(XML_Parser parser);
  545. /* If do_nst is non-zero, and namespace processing is in effect, and
  546. a name has a prefix (i.e. an explicit namespace qualifier) then
  547. that name is returned as a triplet in a single string separated by
  548. the separator character specified when the parser was created: URI
  549. + sep + local_name + sep + prefix.
  550. If do_nst is zero, then namespace information is returned in the
  551. default manner (URI + sep + local_name) whether or not the name
  552. has a prefix.
  553. Note: Calling XML_SetReturnNSTriplet after XML_Parse or
  554. XML_ParseBuffer has no effect.
  555. */
  556. XMLPARSEAPI(void)
  557. XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
  558. /* This value is passed as the userData argument to callbacks. */
  559. XMLPARSEAPI(void)
  560. XML_SetUserData(XML_Parser parser, void *userData);
  561. /* Returns the last value set by XML_SetUserData or NULL. */
  562. #define XML_GetUserData(parser) (*(void **)(parser))
  563. /* This is equivalent to supplying an encoding argument to
  564. XML_ParserCreate. On success XML_SetEncoding returns non-zero,
  565. zero otherwise.
  566. Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
  567. has no effect and returns XML_STATUS_ERROR.
  568. */
  569. XMLPARSEAPI(enum XML_Status)
  570. XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
  571. /* If this function is called, then the parser will be passed as the
  572. first argument to callbacks instead of userData. The userData will
  573. still be accessible using XML_GetUserData.
  574. */
  575. XMLPARSEAPI(void)
  576. XML_UseParserAsHandlerArg(XML_Parser parser);
  577. /* If useDTD == XML_TRUE is passed to this function, then the parser
  578. will assume that there is an external subset, even if none is
  579. specified in the document. In such a case the parser will call the
  580. externalEntityRefHandler with a value of NULL for the systemId
  581. argument (the publicId and context arguments will be NULL as well).
  582. Note: For the purpose of checking WFC: Entity Declared, passing
  583. useDTD == XML_TRUE will make the parser behave as if the document
  584. had a DTD with an external subset.
  585. Note: If this function is called, then this must be done before
  586. the first call to XML_Parse or XML_ParseBuffer, since it will
  587. have no effect after that. Returns
  588. XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
  589. Note: If the document does not have a DOCTYPE declaration at all,
  590. then startDoctypeDeclHandler and endDoctypeDeclHandler will not
  591. be called, despite an external subset being parsed.
  592. Note: If XML_DTD is not defined when Expat is compiled, returns
  593. XML_ERROR_FEATURE_REQUIRES_XML_DTD.
  594. Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT.
  595. */
  596. XMLPARSEAPI(enum XML_Error)
  597. XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
  598. /* Sets the base to be used for resolving relative URIs in system
  599. identifiers in declarations. Resolving relative identifiers is
  600. left to the application: this value will be passed through as the
  601. base argument to the XML_ExternalEntityRefHandler,
  602. XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
  603. argument will be copied. Returns XML_STATUS_ERROR if out of memory,
  604. XML_STATUS_OK otherwise.
  605. */
  606. XMLPARSEAPI(enum XML_Status)
  607. XML_SetBase(XML_Parser parser, const XML_Char *base);
  608. XMLPARSEAPI(const XML_Char *)
  609. XML_GetBase(XML_Parser parser);
  610. /* Returns the number of the attribute/value pairs passed in last call
  611. to the XML_StartElementHandler that were specified in the start-tag
  612. rather than defaulted. Each attribute/value pair counts as 2; thus
  613. this correspondds to an index into the atts array passed to the
  614. XML_StartElementHandler. Returns -1 if parser == NULL.
  615. */
  616. XMLPARSEAPI(int)
  617. XML_GetSpecifiedAttributeCount(XML_Parser parser);
  618. /* Returns the index of the ID attribute passed in the last call to
  619. XML_StartElementHandler, or -1 if there is no ID attribute or
  620. parser == NULL. Each attribute/value pair counts as 2; thus this
  621. correspondds to an index into the atts array passed to the
  622. XML_StartElementHandler.
  623. */
  624. XMLPARSEAPI(int)
  625. XML_GetIdAttributeIndex(XML_Parser parser);
  626. #ifdef XML_ATTR_INFO
  627. /* Source file byte offsets for the start and end of attribute names and values.
  628. The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
  629. file an attribute value of "blah" will yield:
  630. info->valueEnd - info->valueStart = 4 bytes.
  631. */
  632. typedef struct {
  633. XML_Index nameStart; /* Offset to beginning of the attribute name. */
  634. XML_Index nameEnd; /* Offset after the attribute name's last byte. */
  635. XML_Index valueStart; /* Offset to beginning of the attribute value. */
  636. XML_Index valueEnd; /* Offset after the attribute value's last byte. */
  637. } XML_AttrInfo;
  638. /* Returns an array of XML_AttrInfo structures for the attribute/value pairs
  639. passed in last call to the XML_StartElementHandler that were specified
  640. in the start-tag rather than defaulted. Each attribute/value pair counts
  641. as 1; thus the number of entries in the array is
  642. XML_GetSpecifiedAttributeCount(parser) / 2.
  643. */
  644. XMLPARSEAPI(const XML_AttrInfo *)
  645. XML_GetAttributeInfo(XML_Parser parser);
  646. #endif
  647. /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
  648. detected. The last call to XML_Parse must have isFinal true; len
  649. may be zero for this call (or any other).
  650. Though the return values for these functions has always been
  651. described as a Boolean value, the implementation, at least for the
  652. 1.95.x series, has always returned exactly one of the XML_Status
  653. values.
  654. */
  655. XMLPARSEAPI(enum XML_Status)
  656. XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
  657. XMLPARSEAPI(void *)
  658. XML_GetBuffer(XML_Parser parser, int len);
  659. XMLPARSEAPI(enum XML_Status)
  660. XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
  661. /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
  662. Must be called from within a call-back handler, except when aborting
  663. (resumable = 0) an already suspended parser. Some call-backs may
  664. still follow because they would otherwise get lost. Examples:
  665. - endElementHandler() for empty elements when stopped in
  666. startElementHandler(),
  667. - endNameSpaceDeclHandler() when stopped in endElementHandler(),
  668. and possibly others.
  669. Can be called from most handlers, including DTD related call-backs,
  670. except when parsing an external parameter entity and resumable != 0.
  671. Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
  672. Possible error codes:
  673. - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
  674. - XML_ERROR_FINISHED: when the parser has already finished.
  675. - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
  676. When resumable != 0 (true) then parsing is suspended, that is,
  677. XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
  678. Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
  679. return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
  680. *Note*:
  681. This will be applied to the current parser instance only, that is, if
  682. there is a parent parser then it will continue parsing when the
  683. externalEntityRefHandler() returns. It is up to the implementation of
  684. the externalEntityRefHandler() to call XML_StopParser() on the parent
  685. parser (recursively), if one wants to stop parsing altogether.
  686. When suspended, parsing can be resumed by calling XML_ResumeParser().
  687. */
  688. XMLPARSEAPI(enum XML_Status)
  689. XML_StopParser(XML_Parser parser, XML_Bool resumable);
  690. /* Resumes parsing after it has been suspended with XML_StopParser().
  691. Must not be called from within a handler call-back. Returns same
  692. status codes as XML_Parse() or XML_ParseBuffer().
  693. Additional error code XML_ERROR_NOT_SUSPENDED possible.
  694. *Note*:
  695. This must be called on the most deeply nested child parser instance
  696. first, and on its parent parser only after the child parser has finished,
  697. to be applied recursively until the document entity's parser is restarted.
  698. That is, the parent parser will not resume by itself and it is up to the
  699. application to call XML_ResumeParser() on it at the appropriate moment.
  700. */
  701. XMLPARSEAPI(enum XML_Status)
  702. XML_ResumeParser(XML_Parser parser);
  703. enum XML_Parsing {
  704. XML_INITIALIZED,
  705. XML_PARSING,
  706. XML_FINISHED,
  707. XML_SUSPENDED
  708. };
  709. typedef struct {
  710. enum XML_Parsing parsing;
  711. XML_Bool finalBuffer;
  712. } XML_ParsingStatus;
  713. /* Returns status of parser with respect to being initialized, parsing,
  714. finished, or suspended and processing the final buffer.
  715. XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
  716. XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
  717. */
  718. XMLPARSEAPI(void)
  719. XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
  720. /* Creates an XML_Parser object that can parse an external general
  721. entity; context is a '\0'-terminated string specifying the parse
  722. context; encoding is a '\0'-terminated string giving the name of
  723. the externally specified encoding, or NULL if there is no
  724. externally specified encoding. The context string consists of a
  725. sequence of tokens separated by formfeeds (\f); a token consisting
  726. of a name specifies that the general entity of the name is open; a
  727. token of the form prefix=uri specifies the namespace for a
  728. particular prefix; a token of the form =uri specifies the default
  729. namespace. This can be called at any point after the first call to
  730. an ExternalEntityRefHandler so longer as the parser has not yet
  731. been freed. The new parser is completely independent and may
  732. safely be used in a separate thread. The handlers and userData are
  733. initialized from the parser argument. Returns NULL if out of memory.
  734. Otherwise returns a new XML_Parser object.
  735. */
  736. XMLPARSEAPI(XML_Parser)
  737. XML_ExternalEntityParserCreate(XML_Parser parser,
  738. const XML_Char *context,
  739. const XML_Char *encoding);
  740. enum XML_ParamEntityParsing {
  741. XML_PARAM_ENTITY_PARSING_NEVER,
  742. XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
  743. XML_PARAM_ENTITY_PARSING_ALWAYS
  744. };
  745. /* Controls parsing of parameter entities (including the external DTD
  746. subset). If parsing of parameter entities is enabled, then
  747. references to external parameter entities (including the external
  748. DTD subset) will be passed to the handler set with
  749. XML_SetExternalEntityRefHandler. The context passed will be 0.
  750. Unlike external general entities, external parameter entities can
  751. only be parsed synchronously. If the external parameter entity is
  752. to be parsed, it must be parsed during the call to the external
  753. entity ref handler: the complete sequence of
  754. XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
  755. XML_ParserFree calls must be made during this call. After
  756. XML_ExternalEntityParserCreate has been called to create the parser
  757. for the external parameter entity (context must be 0 for this
  758. call), it is illegal to make any calls on the old parser until
  759. XML_ParserFree has been called on the newly created parser.
  760. If the library has been compiled without support for parameter
  761. entity parsing (ie without XML_DTD being defined), then
  762. XML_SetParamEntityParsing will return 0 if parsing of parameter
  763. entities is requested; otherwise it will return non-zero.
  764. Note: If XML_SetParamEntityParsing is called after XML_Parse or
  765. XML_ParseBuffer, then it has no effect and will always return 0.
  766. Note: If parser == NULL, the function will do nothing and return 0.
  767. */
  768. XMLPARSEAPI(int)
  769. XML_SetParamEntityParsing(XML_Parser parser,
  770. enum XML_ParamEntityParsing parsing);
  771. /* Sets the hash salt to use for internal hash calculations.
  772. Helps in preventing DoS attacks based on predicting hash
  773. function behavior. This must be called before parsing is started.
  774. Returns 1 if successful, 0 when called after parsing has started.
  775. Note: If parser == NULL, the function will do nothing and return 0.
  776. */
  777. XMLPARSEAPI(int)
  778. XML_SetHashSalt(XML_Parser parser,
  779. unsigned long hash_salt);
  780. /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
  781. XML_GetErrorCode returns information about the error.
  782. */
  783. XMLPARSEAPI(enum XML_Error)
  784. XML_GetErrorCode(XML_Parser parser);
  785. /* These functions return information about the current parse
  786. location. They may be called from any callback called to report
  787. some parse event; in this case the location is the location of the
  788. first of the sequence of characters that generated the event. When
  789. called from callbacks generated by declarations in the document
  790. prologue, the location identified isn't as neatly defined, but will
  791. be within the relevant markup. When called outside of the callback
  792. functions, the position indicated will be just past the last parse
  793. event (regardless of whether there was an associated callback).
  794. They may also be called after returning from a call to XML_Parse
  795. or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then
  796. the location is the location of the character at which the error
  797. was detected; otherwise the location is the location of the last
  798. parse event, as described above.
  799. Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber
  800. return 0 to indicate an error.
  801. Note: XML_GetCurrentByteIndex returns -1 to indicate an error.
  802. */
  803. XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
  804. XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
  805. XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
  806. /* Return the number of bytes in the current event.
  807. Returns 0 if the event is in an internal entity.
  808. */
  809. XMLPARSEAPI(int)
  810. XML_GetCurrentByteCount(XML_Parser parser);
  811. /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
  812. the integer pointed to by offset to the offset within this buffer
  813. of the current parse position, and sets the integer pointed to by size
  814. to the size of this buffer (the number of input bytes). Otherwise
  815. returns a NULL pointer. Also returns a NULL pointer if a parse isn't
  816. active.
  817. NOTE: The character pointer returned should not be used outside
  818. the handler that makes the call.
  819. */
  820. XMLPARSEAPI(const char *)
  821. XML_GetInputContext(XML_Parser parser,
  822. int *offset,
  823. int *size);
  824. /* For backwards compatibility with previous versions. */
  825. #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
  826. #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
  827. #define XML_GetErrorByteIndex XML_GetCurrentByteIndex
  828. /* Frees the content model passed to the element declaration handler */
  829. XMLPARSEAPI(void)
  830. XML_FreeContentModel(XML_Parser parser, XML_Content *model);
  831. /* Exposing the memory handling functions used in Expat */
  832. XMLPARSEAPI(void *)
  833. XML_ATTR_MALLOC
  834. XML_ATTR_ALLOC_SIZE(2)
  835. XML_MemMalloc(XML_Parser parser, size_t size);
  836. XMLPARSEAPI(void *)
  837. XML_ATTR_ALLOC_SIZE(3)
  838. XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
  839. XMLPARSEAPI(void)
  840. XML_MemFree(XML_Parser parser, void *ptr);
  841. /* Frees memory used by the parser. */
  842. XMLPARSEAPI(void)
  843. XML_ParserFree(XML_Parser parser);
  844. /* Returns a string describing the error. */
  845. XMLPARSEAPI(const XML_LChar *)
  846. XML_ErrorString(enum XML_Error code);
  847. /* Return a string containing the version number of this expat */
  848. XMLPARSEAPI(const XML_LChar *)
  849. XML_ExpatVersion(void);
  850. typedef struct {
  851. int major;
  852. int minor;
  853. int micro;
  854. } XML_Expat_Version;
  855. /* Return an XML_Expat_Version structure containing numeric version
  856. number information for this version of expat.
  857. */
  858. XMLPARSEAPI(XML_Expat_Version)
  859. XML_ExpatVersionInfo(void);
  860. /* Added in Expat 1.95.5. */
  861. enum XML_FeatureEnum {
  862. XML_FEATURE_END = 0,
  863. XML_FEATURE_UNICODE,
  864. XML_FEATURE_UNICODE_WCHAR_T,
  865. XML_FEATURE_DTD,
  866. XML_FEATURE_CONTEXT_BYTES,
  867. XML_FEATURE_MIN_SIZE,
  868. XML_FEATURE_SIZEOF_XML_CHAR,
  869. XML_FEATURE_SIZEOF_XML_LCHAR,
  870. XML_FEATURE_NS,
  871. XML_FEATURE_LARGE_SIZE,
  872. XML_FEATURE_ATTR_INFO
  873. /* Additional features must be added to the end of this enum. */
  874. };
  875. typedef struct {
  876. enum XML_FeatureEnum feature;
  877. const XML_LChar *name;
  878. long int value;
  879. } XML_Feature;
  880. XMLPARSEAPI(const XML_Feature *)
  881. XML_GetFeatureList(void);
  882. /* Expat follows the semantic versioning convention.
  883. See http://semver.org.
  884. */
  885. #define XML_MAJOR_VERSION 2
  886. #define XML_MINOR_VERSION 2
  887. #define XML_MICRO_VERSION 1
  888. #ifdef __cplusplus
  889. }
  890. #endif
  891. #endif /* not Expat_INCLUDED */