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