expat.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. #include "cm_expat_mangle.h"
  2. /*
  3. Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
  4. See the file COPYING for copying permission.
  5. */
  6. #ifndef XmlParse_INCLUDED
  7. #define XmlParse_INCLUDED 1
  8. #include <stdlib.h>
  9. #include <cmexpat/expatDllConfig.h>
  10. #if defined(_WIN32) && !defined(CM_EXPAT_STATIC)
  11. # if defined(cmexpat_EXPORTS)
  12. # define XMLPARSEAPI(type) __declspec( dllexport ) type __cdecl
  13. # else
  14. # define XMLPARSEAPI(type) __declspec( dllimport ) type __cdecl
  15. # endif
  16. #else
  17. # define XMLPARSEAPI(type) type
  18. #endif
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef void *XML_Parser;
  23. /* Information is UTF-8 encoded. */
  24. typedef char XML_Char;
  25. typedef char XML_LChar;
  26. enum XML_Content_Type {
  27. XML_CTYPE_EMPTY = 1,
  28. XML_CTYPE_ANY,
  29. XML_CTYPE_MIXED,
  30. XML_CTYPE_NAME,
  31. XML_CTYPE_CHOICE,
  32. XML_CTYPE_SEQ
  33. };
  34. enum XML_Content_Quant {
  35. XML_CQUANT_NONE,
  36. XML_CQUANT_OPT,
  37. XML_CQUANT_REP,
  38. XML_CQUANT_PLUS
  39. };
  40. /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
  41. XML_CQUANT_NONE, and the other fields will be zero or NULL.
  42. If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
  43. numchildren will contain number of elements that may be mixed in
  44. and children point to an array of XML_Content cells that will be
  45. all of XML_CTYPE_NAME type with no quantification.
  46. If type == XML_CTYPE_NAME, then the name points to the name, and
  47. the numchildren field will be zero and children will be NULL. The
  48. quant fields indicates any quantifiers placed on the name.
  49. CHOICE and SEQ will have name NULL, the number of children in
  50. numchildren and children will point, recursively, to an array
  51. of XML_Content cells.
  52. The EMPTY, ANY, and MIXED types will only occur at top level.
  53. */
  54. typedef struct XML_cp XML_Content;
  55. struct XML_cp {
  56. enum XML_Content_Type type;
  57. enum XML_Content_Quant quant;
  58. XML_Char * name;
  59. unsigned int numchildren;
  60. XML_Content * children;
  61. };
  62. /* This is called for an element declaration. See above for
  63. description of the model argument. It's the caller's responsibility
  64. to free model when finished with it.
  65. */
  66. typedef void (*XML_ElementDeclHandler) (void *userData,
  67. const XML_Char *name,
  68. XML_Content *model);
  69. XMLPARSEAPI(void)
  70. XML_SetElementDeclHandler(XML_Parser parser,
  71. XML_ElementDeclHandler eldecl);
  72. /*
  73. The Attlist declaration handler is called for *each* attribute. So
  74. a single Attlist declaration with multiple attributes declared will
  75. generate multiple calls to this handler. The "default" parameter
  76. may be NULL in the case of the "#IMPLIED" or "#REQUIRED" keyword.
  77. The "isrequired" parameter will be true and the default value will
  78. be NULL in the case of "#REQUIRED". If "isrequired" is true and
  79. default is non-NULL, then this is a "#FIXED" default.
  80. */
  81. typedef void (*XML_AttlistDeclHandler) (void *userData,
  82. const XML_Char *elname,
  83. const XML_Char *attname,
  84. const XML_Char *att_type,
  85. const XML_Char *dflt,
  86. int isrequired);
  87. XMLPARSEAPI(void)
  88. XML_SetAttlistDeclHandler(XML_Parser parser,
  89. XML_AttlistDeclHandler attdecl);
  90. /* The XML declaration handler is called for *both* XML declarations and
  91. text declarations. The way to distinguish is that the version parameter
  92. will be null for text declarations. The encoding parameter may be null
  93. for XML declarations. The standalone parameter will be -1, 0, or 1
  94. indicating respectively that there was no standalone parameter in
  95. the declaration, that it was given as no, or that it was given as yes.
  96. */
  97. typedef void (*XML_XmlDeclHandler) (void *userData,
  98. const XML_Char *version,
  99. const XML_Char *encoding,
  100. int standalone);
  101. XMLPARSEAPI(void)
  102. XML_SetXmlDeclHandler(XML_Parser parser,
  103. XML_XmlDeclHandler xmldecl);
  104. typedef struct {
  105. void *(*malloc_fcn)(size_t size);
  106. void *(*realloc_fcn)(void *ptr, size_t size);
  107. void (*free_fcn)(void *ptr);
  108. } XML_Memory_Handling_Suite;
  109. /* Constructs a new parser; encoding is the encoding specified by the
  110. external protocol or null if there is none specified. */
  111. XMLPARSEAPI(XML_Parser)
  112. XML_ParserCreate(const XML_Char *encoding);
  113. /* Constructs a new parser and namespace processor. Element type
  114. names and attribute names that belong to a namespace will be expanded;
  115. unprefixed attribute names are never expanded; unprefixed element type
  116. names are expanded only if there is a default namespace. The expanded
  117. name is the concatenation of the namespace URI, the namespace
  118. separator character, and the local part of the name. If the namespace
  119. separator is '\0' then the namespace URI and the local part will be
  120. concatenated without any separator. When a namespace is not declared,
  121. the name and prefix will be passed through without expansion. */
  122. XMLPARSEAPI(XML_Parser)
  123. XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
  124. /* Constructs a new parser using the memory management suit referred to
  125. by memsuite. If memsuite is NULL, then use the standard library memory
  126. suite. If namespaceSeparator is non-NULL it creates a parser with
  127. namespace processing as described above. The character pointed at
  128. will serve as the namespace separator.
  129. All further memory operations used for the created parser will come from
  130. the given suite.
  131. */
  132. XMLPARSEAPI(XML_Parser)
  133. XML_ParserCreate_MM(const XML_Char *encoding,
  134. const XML_Memory_Handling_Suite *memsuite,
  135. const XML_Char *namespaceSeparator);
  136. /* atts is array of name/value pairs, terminated by 0;
  137. names and values are 0 terminated. */
  138. typedef void (*XML_StartElementHandler)(void *userData,
  139. const XML_Char *name,
  140. const XML_Char **atts);
  141. typedef void (*XML_EndElementHandler)(void *userData,
  142. const XML_Char *name);
  143. /* s is not 0 terminated. */
  144. typedef void (*XML_CharacterDataHandler)(void *userData,
  145. const XML_Char *s,
  146. int len);
  147. /* target and data are 0 terminated */
  148. typedef void (*XML_ProcessingInstructionHandler)(void *userData,
  149. const XML_Char *target,
  150. const XML_Char *data);
  151. /* data is 0 terminated */
  152. typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data);
  153. typedef void (*XML_StartCdataSectionHandler)(void *userData);
  154. typedef void (*XML_EndCdataSectionHandler)(void *userData);
  155. /* This is called for any characters in the XML document for
  156. which there is no applicable handler. This includes both
  157. characters that are part of markup which is of a kind that is
  158. not reported (comments, markup declarations), or characters
  159. that are part of a construct which could be reported but
  160. for which no handler has been supplied. The characters are passed
  161. exactly as they were in the XML document except that
  162. they will be encoded in UTF-8. Line boundaries are not normalized.
  163. Note that a byte order mark character is not passed to the default handler.
  164. There are no guarantees about how characters are divided between calls
  165. to the default handler: for example, a comment might be split between
  166. multiple calls. */
  167. typedef void (*XML_DefaultHandler)(void *userData,
  168. const XML_Char *s,
  169. int len);
  170. /* This is called for the start of the DOCTYPE declaration, before
  171. any DTD or internal subset is parsed. */
  172. typedef void (*XML_StartDoctypeDeclHandler)(void *userData,
  173. const XML_Char *doctypeName,
  174. const XML_Char *sysid,
  175. const XML_Char *pubid,
  176. int has_internal_subset);
  177. /* This is called for the start of the DOCTYPE declaration when the
  178. closing > is encountered, but after processing any external subset. */
  179. typedef void (*XML_EndDoctypeDeclHandler)(void *userData);
  180. /* This is called for entity declarations. The is_parameter_entity
  181. argument will be non-zero if the entity is a parameter entity, zero
  182. otherwise.
  183. For internal entities (<!ENTITY foo "bar">), value will
  184. be non-null and systemId, publicID, and notationName will be null.
  185. The value string is NOT null terminated; the length is provided in
  186. the value_length argument. Since it is legal to have zero-length
  187. values, do not use this argument to test for internal entities.
  188. For external entities, value will be null and systemId will be non-null.
  189. The publicId argument will be null unless a public identifier was
  190. provided. The notationName argument will have a non-null value only
  191. for unparsed entity declarations.
  192. */
  193. typedef void (*XML_EntityDeclHandler) (void *userData,
  194. const XML_Char *entityName,
  195. int is_parameter_entity,
  196. const XML_Char *value,
  197. int value_length,
  198. const XML_Char *base,
  199. const XML_Char *systemId,
  200. const XML_Char *publicId,
  201. const XML_Char *notationName);
  202. XMLPARSEAPI(void)
  203. XML_SetEntityDeclHandler(XML_Parser parser,
  204. XML_EntityDeclHandler handler);
  205. /* OBSOLETE -- OBSOLETE -- OBSOLETE
  206. This handler has been superceded by the EntityDeclHandler above.
  207. It is provided here for backward compatibility.
  208. This is called for a declaration of an unparsed (NDATA)
  209. entity. The base argument is whatever was set by XML_SetBase.
  210. The entityName, systemId and notationName arguments will never be null.
  211. The other arguments may be. */
  212. typedef void (*XML_UnparsedEntityDeclHandler)(void *userData,
  213. const XML_Char *entityName,
  214. const XML_Char *base,
  215. const XML_Char *systemId,
  216. const XML_Char *publicId,
  217. const XML_Char *notationName);
  218. /* This is called for a declaration of notation.
  219. The base argument is whatever was set by XML_SetBase.
  220. The notationName will never be null. The other arguments can be. */
  221. typedef void (*XML_NotationDeclHandler)(void *userData,
  222. const XML_Char *notationName,
  223. const XML_Char *base,
  224. const XML_Char *systemId,
  225. const XML_Char *publicId);
  226. /* When namespace processing is enabled, these are called once for
  227. each namespace declaration. The call to the start and end element
  228. handlers occur between the calls to the start and end namespace
  229. declaration handlers. For an xmlns attribute, prefix will be null.
  230. For an xmlns="" attribute, uri will be null. */
  231. typedef void (*XML_StartNamespaceDeclHandler)(void *userData,
  232. const XML_Char *prefix,
  233. const XML_Char *uri);
  234. typedef void (*XML_EndNamespaceDeclHandler)(void *userData,
  235. const XML_Char *prefix);
  236. /* This is called if the document is not standalone (it has an
  237. external subset or a reference to a parameter entity, but does not
  238. have standalone="yes"). If this handler returns 0, then processing
  239. will not continue, and the parser will return a
  240. XML_ERROR_NOT_STANDALONE error. */
  241. typedef int (*XML_NotStandaloneHandler)(void *userData);
  242. /* This is called for a reference to an external parsed general entity.
  243. The referenced entity is not automatically parsed.
  244. The application can parse it immediately or later using
  245. XML_ExternalEntityParserCreate.
  246. The parser argument is the parser parsing the entity containing the reference;
  247. it can be passed as the parser argument to XML_ExternalEntityParserCreate.
  248. The systemId argument is the system identifier as specified in the entity
  249. declaration; it will not be null.
  250. The base argument is the system identifier that should be used as the base for
  251. resolving systemId if systemId was relative; this is set by XML_SetBase;
  252. it may be null.
  253. The publicId argument is the public identifier as specified in the entity
  254. declaration, or null if none was specified; the whitespace in the public
  255. identifier will have been normalized as required by the XML spec.
  256. The context argument specifies the parsing context in the format
  257. expected by the context argument to
  258. XML_ExternalEntityParserCreate; context is valid only until the handler
  259. returns, so if the referenced entity is to be parsed later, it must be copied.
  260. The handler should return 0 if processing should not continue because of
  261. a fatal error in the handling of the external entity.
  262. In this case the calling parser will return an
  263. XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
  264. Note that unlike other handlers the first argument is the parser, not
  265. userData. */
  266. typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser,
  267. const XML_Char *context,
  268. const XML_Char *base,
  269. const XML_Char *systemId,
  270. const XML_Char *publicId);
  271. /* This structure is filled in by the XML_UnknownEncodingHandler
  272. to provide information to the parser about encodings that are unknown
  273. to the parser.
  274. The map[b] member gives information about byte sequences
  275. whose first byte is b.
  276. If map[b] is c where c is >= 0, then b by itself encodes the Unicode scalar
  277. value c.
  278. If map[b] is -1, then the byte sequence is malformed.
  279. If map[b] is -n, where n >= 2, then b is the first byte of an n-byte
  280. sequence that encodes a single Unicode scalar value.
  281. The data member will be passed as the first argument to the convert function.
  282. The convert function is used to convert multibyte sequences;
  283. s will point to a n-byte sequence where map[(unsigned char)*s] == -n.
  284. The convert function must return the Unicode scalar value
  285. represented by this byte sequence or -1 if the byte sequence is malformed.
  286. The convert function may be null if the encoding is a single-byte encoding,
  287. that is if map[b] >= -1 for all bytes b.
  288. When the parser is finished with the encoding, then if release is not null,
  289. it will call release passing it the data member;
  290. once release has been called, the convert function will not be called again.
  291. Expat places certain restrictions on the encodings that are supported
  292. using this mechanism.
  293. 1. Every ASCII character that can appear in a well-formed XML document,
  294. other than the characters
  295. $@\^`{}~
  296. must be represented by a single byte, and that byte must be the
  297. same byte that represents that character in ASCII.
  298. 2. No character may require more than 4 bytes to encode.
  299. 3. All characters encoded must have Unicode scalar values <= 0xFFFF, (i.e.,
  300. characters that would be encoded by surrogates in UTF-16 are not
  301. allowed). Note that this restriction doesn't apply to the built-in
  302. support for UTF-8 and UTF-16.
  303. 4. No Unicode character may be encoded by more than one distinct sequence
  304. of bytes. */
  305. typedef struct {
  306. int map[256];
  307. void *data;
  308. int (*convert)(void *data, const char *s);
  309. void (*release)(void *data);
  310. } XML_Encoding;
  311. /* This is called for an encoding that is unknown to the parser.
  312. The encodingHandlerData argument is that which was passed as the
  313. second argument to XML_SetUnknownEncodingHandler.
  314. The name argument gives the name of the encoding as specified in
  315. the encoding declaration.
  316. If the callback can provide information about the encoding,
  317. it must fill in the XML_Encoding structure, and return 1.
  318. Otherwise it must return 0.
  319. If info does not describe a suitable encoding,
  320. then the parser will return an XML_UNKNOWN_ENCODING error. */
  321. typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData,
  322. const XML_Char *name,
  323. XML_Encoding *info);
  324. XMLPARSEAPI(void)
  325. XML_SetElementHandler(XML_Parser parser,
  326. XML_StartElementHandler start,
  327. XML_EndElementHandler end);
  328. XMLPARSEAPI(void)
  329. XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler);
  330. XMLPARSEAPI(void)
  331. XML_SetEndElementHandler(XML_Parser, XML_EndElementHandler);
  332. XMLPARSEAPI(void)
  333. XML_SetCharacterDataHandler(XML_Parser parser,
  334. XML_CharacterDataHandler handler);
  335. XMLPARSEAPI(void)
  336. XML_SetProcessingInstructionHandler(XML_Parser parser,
  337. XML_ProcessingInstructionHandler handler);
  338. XMLPARSEAPI(void)
  339. XML_SetCommentHandler(XML_Parser parser,
  340. XML_CommentHandler handler);
  341. XMLPARSEAPI(void)
  342. XML_SetCdataSectionHandler(XML_Parser parser,
  343. XML_StartCdataSectionHandler start,
  344. XML_EndCdataSectionHandler end);
  345. XMLPARSEAPI(void)
  346. XML_SetStartCdataSectionHandler(XML_Parser parser,
  347. XML_StartCdataSectionHandler start);
  348. XMLPARSEAPI(void)
  349. XML_SetEndCdataSectionHandler(XML_Parser parser,
  350. XML_EndCdataSectionHandler end);
  351. /* This sets the default handler and also inhibits expansion of
  352. internal entities. The entity reference will be passed to the default
  353. handler. */
  354. XMLPARSEAPI(void)
  355. XML_SetDefaultHandler(XML_Parser parser,
  356. XML_DefaultHandler handler);
  357. /* This sets the default handler but does not inhibit expansion of
  358. internal entities. The entity reference will not be passed to the
  359. default handler. */
  360. XMLPARSEAPI(void)
  361. XML_SetDefaultHandlerExpand(XML_Parser parser,
  362. XML_DefaultHandler handler);
  363. XMLPARSEAPI(void)
  364. XML_SetDoctypeDeclHandler(XML_Parser parser,
  365. XML_StartDoctypeDeclHandler start,
  366. XML_EndDoctypeDeclHandler end);
  367. XMLPARSEAPI(void)
  368. XML_SetStartDoctypeDeclHandler(XML_Parser parser,
  369. XML_StartDoctypeDeclHandler start);
  370. XMLPARSEAPI(void)
  371. XML_SetEndDoctypeDeclHandler(XML_Parser parser,
  372. XML_EndDoctypeDeclHandler end);
  373. XMLPARSEAPI(void)
  374. XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
  375. XML_UnparsedEntityDeclHandler handler);
  376. XMLPARSEAPI(void)
  377. XML_SetNotationDeclHandler(XML_Parser parser,
  378. XML_NotationDeclHandler handler);
  379. XMLPARSEAPI(void)
  380. XML_SetNamespaceDeclHandler(XML_Parser parser,
  381. XML_StartNamespaceDeclHandler start,
  382. XML_EndNamespaceDeclHandler end);
  383. XMLPARSEAPI(void)
  384. XML_SetStartNamespaceDeclHandler(XML_Parser parser,
  385. XML_StartNamespaceDeclHandler start);
  386. XMLPARSEAPI(void)
  387. XML_SetEndNamespaceDeclHandler(XML_Parser parser,
  388. XML_EndNamespaceDeclHandler end);
  389. XMLPARSEAPI(void)
  390. XML_SetNotStandaloneHandler(XML_Parser parser,
  391. XML_NotStandaloneHandler handler);
  392. XMLPARSEAPI(void)
  393. XML_SetExternalEntityRefHandler(XML_Parser parser,
  394. XML_ExternalEntityRefHandler handler);
  395. /* If a non-null value for arg is specified here, then it will be passed
  396. as the first argument to the external entity ref handler instead
  397. of the parser object. */
  398. XMLPARSEAPI(void)
  399. XML_SetExternalEntityRefHandlerArg(XML_Parser, void *arg);
  400. XMLPARSEAPI(void)
  401. XML_SetUnknownEncodingHandler(XML_Parser parser,
  402. XML_UnknownEncodingHandler handler,
  403. void *encodingHandlerData);
  404. /* This can be called within a handler for a start element, end element,
  405. processing instruction or character data. It causes the corresponding
  406. markup to be passed to the default handler. */
  407. XMLPARSEAPI(void)
  408. XML_DefaultCurrent(XML_Parser parser);
  409. /* If do_nst is non-zero, and namespace processing is in effect, and
  410. a name has a prefix (i.e. an explicit namespace qualifier) then
  411. that name is returned as a triplet in a single
  412. string separated by the separator character specified when the parser
  413. was created: URI + sep + local_name + sep + prefix.
  414. If do_nst is zero, then namespace information is returned in the
  415. default manner (URI + sep + local_name) whether or not the names
  416. has a prefix.
  417. */
  418. XMLPARSEAPI(void)
  419. XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
  420. /* This value is passed as the userData argument to callbacks. */
  421. XMLPARSEAPI(void)
  422. XML_SetUserData(XML_Parser parser, void *userData);
  423. /* Returns the last value set by XML_SetUserData or null. */
  424. #define XML_GetUserData(parser) (*(void **)(parser))
  425. /* This is equivalent to supplying an encoding argument
  426. to XML_ParserCreate. It must not be called after XML_Parse
  427. or XML_ParseBuffer. */
  428. XMLPARSEAPI(int)
  429. XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
  430. /* If this function is called, then the parser will be passed
  431. as the first argument to callbacks instead of userData.
  432. The userData will still be accessible using XML_GetUserData. */
  433. XMLPARSEAPI(void)
  434. XML_UseParserAsHandlerArg(XML_Parser parser);
  435. /* Sets the base to be used for resolving relative URIs in system
  436. identifiers in declarations. Resolving relative identifiers is left
  437. to the application: this value will be passed through as the base
  438. argument to the XML_ExternalEntityRefHandler, XML_NotationDeclHandler
  439. and XML_UnparsedEntityDeclHandler. The base argument will be copied.
  440. Returns zero if out of memory, non-zero otherwise. */
  441. XMLPARSEAPI(int)
  442. XML_SetBase(XML_Parser parser, const XML_Char *base);
  443. XMLPARSEAPI(const XML_Char *)
  444. XML_GetBase(XML_Parser parser);
  445. /* Returns the number of the attribute/value pairs passed in last call
  446. to the XML_StartElementHandler that were specified in the start-tag
  447. rather than defaulted. Each attribute/value pair counts as 2; thus
  448. this correspondds to an index into the atts array passed to the
  449. XML_StartElementHandler. */
  450. XMLPARSEAPI(int)
  451. XML_GetSpecifiedAttributeCount(XML_Parser parser);
  452. /* Returns the index of the ID attribute passed in the last call to
  453. XML_StartElementHandler, or -1 if there is no ID attribute. Each
  454. attribute/value pair counts as 2; thus this correspondds to an index
  455. into the atts array passed to the XML_StartElementHandler. */
  456. XMLPARSEAPI(int)
  457. XML_GetIdAttributeIndex(XML_Parser parser);
  458. /* Parses some input. Returns 0 if a fatal error is detected.
  459. The last call to XML_Parse must have isFinal true;
  460. len may be zero for this call (or any other). */
  461. XMLPARSEAPI(int)
  462. XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
  463. XMLPARSEAPI(void *)
  464. XML_GetBuffer(XML_Parser parser, int len);
  465. XMLPARSEAPI(int)
  466. XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
  467. /* Creates an XML_Parser object that can parse an external general
  468. entity; context is a '\0'-terminated string specifying the parse
  469. context; encoding is a '\0'-terminated string giving the name of the
  470. externally specified encoding, or null if there is no externally
  471. specified encoding. The context string consists of a sequence of
  472. tokens separated by formfeeds (\f); a token consisting of a name
  473. specifies that the general entity of the name is open; a token of the
  474. form prefix=uri specifies the namespace for a particular prefix; a
  475. token of the form =uri specifies the default namespace. This can be
  476. called at any point after the first call to an
  477. ExternalEntityRefHandler so longer as the parser has not yet been
  478. freed. The new parser is completely independent and may safely be
  479. used in a separate thread. The handlers and userData are initialized
  480. from the parser argument. Returns 0 if out of memory. Otherwise
  481. returns a new XML_Parser object. */
  482. XMLPARSEAPI(XML_Parser)
  483. XML_ExternalEntityParserCreate(XML_Parser parser,
  484. const XML_Char *context,
  485. const XML_Char *encoding);
  486. enum XML_ParamEntityParsing {
  487. XML_PARAM_ENTITY_PARSING_NEVER,
  488. XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
  489. XML_PARAM_ENTITY_PARSING_ALWAYS
  490. };
  491. /* Controls parsing of parameter entities (including the external DTD
  492. subset). If parsing of parameter entities is enabled, then references
  493. to external parameter entities (including the external DTD subset)
  494. will be passed to the handler set with
  495. XML_SetExternalEntityRefHandler. The context passed will be 0.
  496. Unlike external general entities, external parameter entities can only
  497. be parsed synchronously. If the external parameter entity is to be
  498. parsed, it must be parsed during the call to the external entity ref
  499. handler: the complete sequence of XML_ExternalEntityParserCreate,
  500. XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during
  501. this call. After XML_ExternalEntityParserCreate has been called to
  502. create the parser for the external parameter entity (context must be 0
  503. for this call), it is illegal to make any calls on the old parser
  504. until XML_ParserFree has been called on the newly created parser. If
  505. the library has been compiled without support for parameter entity
  506. parsing (ie without XML_DTD being defined), then
  507. XML_SetParamEntityParsing will return 0 if parsing of parameter
  508. entities is requested; otherwise it will return non-zero. */
  509. XMLPARSEAPI(int)
  510. XML_SetParamEntityParsing(XML_Parser parser,
  511. enum XML_ParamEntityParsing parsing);
  512. enum XML_Error {
  513. XML_ERROR_NONE,
  514. XML_ERROR_NO_MEMORY,
  515. XML_ERROR_SYNTAX,
  516. XML_ERROR_NO_ELEMENTS,
  517. XML_ERROR_INVALID_TOKEN,
  518. XML_ERROR_UNCLOSED_TOKEN,
  519. XML_ERROR_PARTIAL_CHAR,
  520. XML_ERROR_TAG_MISMATCH,
  521. XML_ERROR_DUPLICATE_ATTRIBUTE,
  522. XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
  523. XML_ERROR_PARAM_ENTITY_REF,
  524. XML_ERROR_UNDEFINED_ENTITY,
  525. XML_ERROR_RECURSIVE_ENTITY_REF,
  526. XML_ERROR_ASYNC_ENTITY,
  527. XML_ERROR_BAD_CHAR_REF,
  528. XML_ERROR_BINARY_ENTITY_REF,
  529. XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
  530. XML_ERROR_MISPLACED_XML_PI,
  531. XML_ERROR_UNKNOWN_ENCODING,
  532. XML_ERROR_INCORRECT_ENCODING,
  533. XML_ERROR_UNCLOSED_CDATA_SECTION,
  534. XML_ERROR_EXTERNAL_ENTITY_HANDLING,
  535. XML_ERROR_NOT_STANDALONE,
  536. XML_ERROR_UNEXPECTED_STATE
  537. };
  538. /* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
  539. returns information about the error. */
  540. XMLPARSEAPI(enum XML_Error)
  541. XML_GetErrorCode(XML_Parser parser);
  542. /* These functions return information about the current parse location.
  543. They may be called when XML_Parse or XML_ParseBuffer return 0;
  544. in this case the location is the location of the character at which
  545. the error was detected.
  546. They may also be called from any other callback called to report
  547. some parse event; in this the location is the location of the first
  548. of the sequence of characters that generated the event. */
  549. XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser);
  550. XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser);
  551. XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser);
  552. /* Return the number of bytes in the current event.
  553. Returns 0 if the event is in an internal entity. */
  554. XMLPARSEAPI(int)
  555. XML_GetCurrentByteCount(XML_Parser parser);
  556. /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
  557. the integer pointed to by offset to the offset within this buffer
  558. of the current parse position, and sets the integer pointed to by size
  559. to the size of this buffer (the number of input bytes). Otherwise
  560. returns a null pointer. Also returns a null pointer if a parse isn't
  561. active.
  562. NOTE: The character pointer returned should not be used outside
  563. the handler that makes the call. */
  564. XMLPARSEAPI(const char *)
  565. XML_GetInputContext(XML_Parser parser,
  566. int *offset,
  567. int *size);
  568. /* For backwards compatibility with previous versions. */
  569. #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
  570. #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
  571. #define XML_GetErrorByteIndex XML_GetCurrentByteIndex
  572. /* Frees memory used by the parser. */
  573. XMLPARSEAPI(void)
  574. XML_ParserFree(XML_Parser parser);
  575. /* Returns a string describing the error. */
  576. XMLPARSEAPI(const XML_LChar *)
  577. XML_ErrorString(int code);
  578. /* Return a string containing the version number of this expat */
  579. XMLPARSEAPI(const XML_LChar *)
  580. XML_ExpatVersion(void);
  581. typedef struct {
  582. int major;
  583. int minor;
  584. int micro;
  585. } XML_Expat_Version;
  586. /* Return an XML_Expat_Version structure containing numeric version
  587. number information for this version of expat */
  588. XMLPARSEAPI(XML_Expat_Version)
  589. XML_ExpatVersionInfo(void);
  590. #define XML_MAJOR_VERSION 1
  591. #define XML_MINOR_VERSION 95
  592. #define XML_MICRO_VERSION 2
  593. #ifdef __cplusplus
  594. }
  595. #endif
  596. #endif /* not XmlParse_INCLUDED */