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