Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

1015 řádky
39 KiB

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