00001 /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd 00002 See the file COPYING for copying permission. 00003 */ 00004 00005 #ifndef XmlParse_INCLUDED 00006 #define XmlParse_INCLUDED 1 00007 00008 #ifdef __VMS 00009 /* 0 1 2 3 0 1 2 3 00010 1234567890123456789012345678901 1234567890123456789012345678901 */ 00011 #define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler 00012 #define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler 00013 #define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler 00014 #define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg 00015 #endif 00016 00017 #include <stdlib.h> 00018 #include "expat_external.h" 00019 00020 struct XML_ParserStruct; 00021 typedef struct XML_ParserStruct *XML_Parser; 00022 00023 /* Should this be defined using stdbool.h when C99 is available? */ 00024 typedef unsigned char XML_Bool; 00025 #define XML_TRUE ((XML_Bool) 1) 00026 #define XML_FALSE ((XML_Bool) 0) 00027 00028 /* The XML_Status enum gives the possible return values for several 00029 API functions. The preprocessor #defines are included so this 00030 stanza can be added to code that still needs to support older 00031 versions of Expat 1.95.x: 00032 00033 #ifndef XML_STATUS_OK 00034 #define XML_STATUS_OK 1 00035 #define XML_STATUS_ERROR 0 00036 #endif 00037 00038 Otherwise, the #define hackery is quite ugly and would have been 00039 dropped. 00040 */ 00041 enum XML_Status { 00042 XML_STATUS_ERROR = 0, 00043 #define XML_STATUS_ERROR XML_STATUS_ERROR 00044 XML_STATUS_OK = 1, 00045 #define XML_STATUS_OK XML_STATUS_OK 00046 XML_STATUS_SUSPENDED = 2, 00047 #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED 00048 }; 00049 00050 enum XML_Error { 00051 XML_ERROR_NONE, 00052 XML_ERROR_NO_MEMORY, 00053 XML_ERROR_SYNTAX, 00054 XML_ERROR_NO_ELEMENTS, 00055 XML_ERROR_INVALID_TOKEN, 00056 XML_ERROR_UNCLOSED_TOKEN, 00057 XML_ERROR_PARTIAL_CHAR, 00058 XML_ERROR_TAG_MISMATCH, 00059 XML_ERROR_DUPLICATE_ATTRIBUTE, 00060 XML_ERROR_JUNK_AFTER_DOC_ELEMENT, 00061 XML_ERROR_PARAM_ENTITY_REF, 00062 XML_ERROR_UNDEFINED_ENTITY, 00063 XML_ERROR_RECURSIVE_ENTITY_REF, 00064 XML_ERROR_ASYNC_ENTITY, 00065 XML_ERROR_BAD_CHAR_REF, 00066 XML_ERROR_BINARY_ENTITY_REF, 00067 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, 00068 XML_ERROR_MISPLACED_XML_PI, 00069 XML_ERROR_UNKNOWN_ENCODING, 00070 XML_ERROR_INCORRECT_ENCODING, 00071 XML_ERROR_UNCLOSED_CDATA_SECTION, 00072 XML_ERROR_EXTERNAL_ENTITY_HANDLING, 00073 XML_ERROR_NOT_STANDALONE, 00074 XML_ERROR_UNEXPECTED_STATE, 00075 XML_ERROR_ENTITY_DECLARED_IN_PE, 00076 XML_ERROR_FEATURE_REQUIRES_XML_DTD, 00077 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, 00078 /* Added in 1.95.7. */ 00079 XML_ERROR_UNBOUND_PREFIX, 00080 /* Added in 1.95.8. */ 00081 XML_ERROR_UNDECLARING_PREFIX, 00082 XML_ERROR_INCOMPLETE_PE, 00083 XML_ERROR_XML_DECL, 00084 XML_ERROR_TEXT_DECL, 00085 XML_ERROR_PUBLICID, 00086 XML_ERROR_SUSPENDED, 00087 XML_ERROR_NOT_SUSPENDED, 00088 XML_ERROR_ABORTED, 00089 XML_ERROR_FINISHED, 00090 XML_ERROR_SUSPEND_PE 00091 }; 00092 00093 enum XML_Content_Type { 00094 XML_CTYPE_EMPTY = 1, 00095 XML_CTYPE_ANY, 00096 XML_CTYPE_MIXED, 00097 XML_CTYPE_NAME, 00098 XML_CTYPE_CHOICE, 00099 XML_CTYPE_SEQ 00100 }; 00101 00102 enum XML_Content_Quant { 00103 XML_CQUANT_NONE, 00104 XML_CQUANT_OPT, 00105 XML_CQUANT_REP, 00106 XML_CQUANT_PLUS 00107 }; 00108 00109 /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be 00110 XML_CQUANT_NONE, and the other fields will be zero or NULL. 00111 If type == XML_CTYPE_MIXED, then quant will be NONE or REP and 00112 numchildren will contain number of elements that may be mixed in 00113 and children point to an array of XML_Content cells that will be 00114 all of XML_CTYPE_NAME type with no quantification. 00115 00116 If type == XML_CTYPE_NAME, then the name points to the name, and 00117 the numchildren field will be zero and children will be NULL. The 00118 quant fields indicates any quantifiers placed on the name. 00119 00120 CHOICE and SEQ will have name NULL, the number of children in 00121 numchildren and children will point, recursively, to an array 00122 of XML_Content cells. 00123 00124 The EMPTY, ANY, and MIXED types will only occur at top level. 00125 */ 00126 00127 typedef struct XML_cp XML_Content; 00128 00129 struct XML_cp { 00130 enum XML_Content_Type type; 00131 enum XML_Content_Quant quant; 00132 XML_Char * name; 00133 unsigned int numchildren; 00134 XML_Content * children; 00135 }; 00136 00137 00138 /* This is called for an element declaration. See above for 00139 description of the model argument. It's the caller's responsibility 00140 to free model when finished with it. 00141 */ 00142 typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, 00143 const XML_Char *name, 00144 XML_Content *model); 00145 00146 XMLPARSEAPI(void) 00147 XML_SetElementDeclHandler(XML_Parser parser, 00148 XML_ElementDeclHandler eldecl); 00149 00150 /* The Attlist declaration handler is called for *each* attribute. So 00151 a single Attlist declaration with multiple attributes declared will 00152 generate multiple calls to this handler. The "default" parameter 00153 may be NULL in the case of the "#IMPLIED" or "#REQUIRED" 00154 keyword. The "isrequired" parameter will be true and the default 00155 value will be NULL in the case of "#REQUIRED". If "isrequired" is 00156 true and default is non-NULL, then this is a "#FIXED" default. 00157 */ 00158 typedef void (XMLCALL *XML_AttlistDeclHandler) ( 00159 void *userData, 00160 const XML_Char *elname, 00161 const XML_Char *attname, 00162 const XML_Char *att_type, 00163 const XML_Char *dflt, 00164 int isrequired); 00165 00166 XMLPARSEAPI(void) 00167 XML_SetAttlistDeclHandler(XML_Parser parser, 00168 XML_AttlistDeclHandler attdecl); 00169 00170 /* The XML declaration handler is called for *both* XML declarations 00171 and text declarations. The way to distinguish is that the version 00172 parameter will be NULL for text declarations. The encoding 00173 parameter may be NULL for XML declarations. The standalone 00174 parameter will be -1, 0, or 1 indicating respectively that there 00175 was no standalone parameter in the declaration, that it was given 00176 as no, or that it was given as yes. 00177 */ 00178 typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, 00179 const XML_Char *version, 00180 const XML_Char *encoding, 00181 int standalone); 00182 00183 XMLPARSEAPI(void) 00184 XML_SetXmlDeclHandler(XML_Parser parser, 00185 XML_XmlDeclHandler xmldecl); 00186 00187 00188 typedef struct { 00189 void *(*malloc_fcn)(size_t size); 00190 void *(*realloc_fcn)(void *ptr, size_t size); 00191 void (*free_fcn)(void *ptr); 00192 } XML_Memory_Handling_Suite; 00193 00194 /* Constructs a new parser; encoding is the encoding specified by the 00195 external protocol or NULL if there is none specified. 00196 */ 00197 XMLPARSEAPI(XML_Parser) 00198 XML_ParserCreate(const XML_Char *encoding); 00199 00200 /* Constructs a new parser and namespace processor. Element type 00201 names and attribute names that belong to a namespace will be 00202 expanded; unprefixed attribute names are never expanded; unprefixed 00203 element type names are expanded only if there is a default 00204 namespace. The expanded name is the concatenation of the namespace 00205 URI, the namespace separator character, and the local part of the 00206 name. If the namespace separator is '\0' then the namespace URI 00207 and the local part will be concatenated without any separator. 00208 When a namespace is not declared, the name and prefix will be 00209 passed through without expansion. 00210 */ 00211 XMLPARSEAPI(XML_Parser) 00212 XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); 00213 00214 00215 /* Constructs a new parser using the memory management suite referred to 00216 by memsuite. If memsuite is NULL, then use the standard library memory 00217 suite. If namespaceSeparator is non-NULL it creates a parser with 00218 namespace processing as described above. The character pointed at 00219 will serve as the namespace separator. 00220 00221 All further memory operations used for the created parser will come from 00222 the given suite. 00223 */ 00224 XMLPARSEAPI(XML_Parser) 00225 XML_ParserCreate_MM(const XML_Char *encoding, 00226 const XML_Memory_Handling_Suite *memsuite, 00227 const XML_Char *namespaceSeparator); 00228 00229 /* Prepare a parser object to be re-used. This is particularly 00230 valuable when memory allocation overhead is disproportionatly high, 00231 such as when a large number of small documnents need to be parsed. 00232 All handlers are cleared from the parser, except for the 00233 unknownEncodingHandler. The parser's external state is re-initialized 00234 except for the values of ns and ns_triplets. 00235 00236 Added in Expat 1.95.3. 00237 */ 00238 XMLPARSEAPI(XML_Bool) 00239 XML_ParserReset(XML_Parser parser, const XML_Char *encoding); 00240 00241 /* atts is array of name/value pairs, terminated by 0; 00242 names and values are 0 terminated. 00243 */ 00244 typedef void (XMLCALL *XML_StartElementHandler) (void *userData, 00245 const XML_Char *name, 00246 const XML_Char **atts); 00247 00248 typedef void (XMLCALL *XML_EndElementHandler) (void *userData, 00249 const XML_Char *name); 00250 00251 00252 /* s is not 0 terminated. */ 00253 typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, 00254 const XML_Char *s, 00255 int len); 00256 00257 /* target and data are 0 terminated */ 00258 typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( 00259 void *userData, 00260 const XML_Char *target, 00261 const XML_Char *data); 00262 00263 /* data is 0 terminated */ 00264 typedef void (XMLCALL *XML_CommentHandler) (void *userData, 00265 const XML_Char *data); 00266 00267 typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); 00268 typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); 00269 00270 /* This is called for any characters in the XML document for which 00271 there is no applicable handler. This includes both characters that 00272 are part of markup which is of a kind that is not reported 00273 (comments, markup declarations), or characters that are part of a 00274 construct which could be reported but for which no handler has been 00275 supplied. The characters are passed exactly as they were in the XML 00276 document except that they will be encoded in UTF-8 or UTF-16. 00277 Line boundaries are not normalized. Note that a byte order mark 00278 character is not passed to the default handler. There are no 00279 guarantees about how characters are divided between calls to the 00280 default handler: for example, a comment might be split between 00281 multiple calls. 00282 */ 00283 typedef void (XMLCALL *XML_DefaultHandler) (void *userData, 00284 const XML_Char *s, 00285 int len); 00286 00287 /* This is called for the start of the DOCTYPE declaration, before 00288 any DTD or internal subset is parsed. 00289 */ 00290 typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( 00291 void *userData, 00292 const XML_Char *doctypeName, 00293 const XML_Char *sysid, 00294 const XML_Char *pubid, 00295 int has_internal_subset); 00296 00297 /* This is called for the start of the DOCTYPE declaration when the 00298 closing > is encountered, but after processing any external 00299 subset. 00300 */ 00301 typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); 00302 00303 /* This is called for entity declarations. The is_parameter_entity 00304 argument will be non-zero if the entity is a parameter entity, zero 00305 otherwise. 00306 00307 For internal entities (<!ENTITY foo "bar">), value will 00308 be non-NULL and systemId, publicID, and notationName will be NULL. 00309 The value string is NOT nul-terminated; the length is provided in 00310 the value_length argument. Since it is legal to have zero-length 00311 values, do not use this argument to test for internal entities. 00312 00313 For external entities, value will be NULL and systemId will be 00314 non-NULL. The publicId argument will be NULL unless a public 00315 identifier was provided. The notationName argument will have a 00316 non-NULL value only for unparsed entity declarations. 00317 00318 Note that is_parameter_entity can't be changed to XML_Bool, since 00319 that would break binary compatibility. 00320 */ 00321 typedef void (XMLCALL *XML_EntityDeclHandler) ( 00322 void *userData, 00323 const XML_Char *entityName, 00324 int is_parameter_entity, 00325 const XML_Char *value, 00326 int value_length, 00327 const XML_Char *base, 00328 const XML_Char *systemId, 00329 const XML_Char *publicId, 00330 const XML_Char *notationName); 00331 00332 XMLPARSEAPI(void) 00333 XML_SetEntityDeclHandler(XML_Parser parser, 00334 XML_EntityDeclHandler handler); 00335 00336 /* OBSOLETE -- OBSOLETE -- OBSOLETE 00337 This handler has been superceded by the EntityDeclHandler above. 00338 It is provided here for backward compatibility. 00339 00340 This is called for a declaration of an unparsed (NDATA) entity. 00341 The base argument is whatever was set by XML_SetBase. The 00342 entityName, systemId and notationName arguments will never be 00343 NULL. The other arguments may be. 00344 */ 00345 typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( 00346 void *userData, 00347 const XML_Char *entityName, 00348 const XML_Char *base, 00349 const XML_Char *systemId, 00350 const XML_Char *publicId, 00351 const XML_Char *notationName); 00352 00353 /* This is called for a declaration of notation. The base argument is 00354 whatever was set by XML_SetBase. The notationName will never be 00355 NULL. The other arguments can be. 00356 */ 00357 typedef void (XMLCALL *XML_NotationDeclHandler) ( 00358 void *userData, 00359 const XML_Char *notationName, 00360 const XML_Char *base, 00361 const XML_Char *systemId, 00362 const XML_Char *publicId); 00363 00364 /* When namespace processing is enabled, these are called once for 00365 each namespace declaration. The call to the start and end element 00366 handlers occur between the calls to the start and end namespace 00367 declaration handlers. For an xmlns attribute, prefix will be 00368 NULL. For an xmlns="" attribute, uri will be NULL. 00369 */ 00370 typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( 00371 void *userData, 00372 const XML_Char *prefix, 00373 const XML_Char *uri); 00374 00375 typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( 00376 void *userData, 00377 const XML_Char *prefix); 00378 00379 /* This is called if the document is not standalone, that is, it has an 00380 external subset or a reference to a parameter entity, but does not 00381 have standalone="yes". If this handler returns XML_STATUS_ERROR, 00382 then processing will not continue, and the parser will return a 00383 XML_ERROR_NOT_STANDALONE error. 00384 If parameter entity parsing is enabled, then in addition to the 00385 conditions above this handler will only be called if the referenced 00386 entity was actually read. 00387 */ 00388 typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); 00389 00390 /* This is called for a reference to an external parsed general 00391 entity. The referenced entity is not automatically parsed. The 00392 application can parse it immediately or later using 00393 XML_ExternalEntityParserCreate. 00394 00395 The parser argument is the parser parsing the entity containing the 00396 reference; it can be passed as the parser argument to 00397 XML_ExternalEntityParserCreate. The systemId argument is the 00398 system identifier as specified in the entity declaration; it will 00399 not be NULL. 00400 00401 The base argument is the system identifier that should be used as 00402 the base for resolving systemId if systemId was relative; this is 00403 set by XML_SetBase; it may be NULL. 00404 00405 The publicId argument is the public identifier as specified in the 00406 entity declaration, or NULL if none was specified; the whitespace 00407 in the public identifier will have been normalized as required by 00408 the XML spec. 00409 00410 The context argument specifies the parsing context in the format 00411 expected by the context argument to XML_ExternalEntityParserCreate; 00412 context is valid only until the handler returns, so if the 00413 referenced entity is to be parsed later, it must be copied. 00414 context is NULL only when the entity is a parameter entity. 00415 00416 The handler should return XML_STATUS_ERROR if processing should not 00417 continue because of a fatal error in the handling of the external 00418 entity. In this case the calling parser will return an 00419 XML_ERROR_EXTERNAL_ENTITY_HANDLING error. 00420 00421 Note that unlike other handlers the first argument is the parser, 00422 not userData. 00423 */ 00424 typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( 00425 XML_Parser parser, 00426 const XML_Char *context, 00427 const XML_Char *base, 00428 const XML_Char *systemId, 00429 const XML_Char *publicId); 00430 00431 /* This is called in two situations: 00432 1) An entity reference is encountered for which no declaration 00433 has been read *and* this is not an error. 00434 2) An internal entity reference is read, but not expanded, because 00435 XML_SetDefaultHandler has been called. 00436 Note: skipped parameter entities in declarations and skipped general 00437 entities in attribute values cannot be reported, because 00438 the event would be out of sync with the reporting of the 00439 declarations or attribute values 00440 */ 00441 typedef void (XMLCALL *XML_SkippedEntityHandler) ( 00442 void *userData, 00443 const XML_Char *entityName, 00444 int is_parameter_entity); 00445 00446 /* This structure is filled in by the XML_UnknownEncodingHandler to 00447 provide information to the parser about encodings that are unknown 00448 to the parser. 00449 00450 The map[b] member gives information about byte sequences whose 00451 first byte is b. 00452 00453 If map[b] is c where c is >= 0, then b by itself encodes the 00454 Unicode scalar value c. 00455 00456 If map[b] is -1, then the byte sequence is malformed. 00457 00458 If map[b] is -n, where n >= 2, then b is the first byte of an 00459 n-byte sequence that encodes a single Unicode scalar value. 00460 00461 The data member will be passed as the first argument to the convert 00462 function. 00463 00464 The convert function is used to convert multibyte sequences; s will 00465 point to a n-byte sequence where map[(unsigned char)*s] == -n. The 00466 convert function must return the Unicode scalar value represented 00467 by this byte sequence or -1 if the byte sequence is malformed. 00468 00469 The convert function may be NULL if the encoding is a single-byte 00470 encoding, that is if map[b] >= -1 for all bytes b. 00471 00472 When the parser is finished with the encoding, then if release is 00473 not NULL, it will call release passing it the data member; once 00474 release has been called, the convert function will not be called 00475 again. 00476 00477 Expat places certain restrictions on the encodings that are supported 00478 using this mechanism. 00479 00480 1. Every ASCII character that can appear in a well-formed XML document, 00481 other than the characters 00482 00483 $@\^`{}~ 00484 00485 must be represented by a single byte, and that byte must be the 00486 same byte that represents that character in ASCII. 00487 00488 2. No character may require more than 4 bytes to encode. 00489 00490 3. All characters encoded must have Unicode scalar values <= 00491 0xFFFF, (i.e., characters that would be encoded by surrogates in 00492 UTF-16 are not allowed). Note that this restriction doesn't 00493 apply to the built-in support for UTF-8 and UTF-16. 00494 00495 4. No Unicode character may be encoded by more than one distinct 00496 sequence of bytes. 00497 */ 00498 typedef struct { 00499 int map[256]; 00500 void *data; 00501 int (XMLCALL *convert)(void *data, const char *s); 00502 void (XMLCALL *release)(void *data); 00503 } XML_Encoding; 00504 00505 /* This is called for an encoding that is unknown to the parser. 00506 00507 The encodingHandlerData argument is that which was passed as the 00508 second argument to XML_SetUnknownEncodingHandler. 00509 00510 The name argument gives the name of the encoding as specified in 00511 the encoding declaration. 00512 00513 If the callback can provide information about the encoding, it must 00514 fill in the XML_Encoding structure, and return XML_STATUS_OK. 00515 Otherwise it must return XML_STATUS_ERROR. 00516 00517 If info does not describe a suitable encoding, then the parser will 00518 return an XML_UNKNOWN_ENCODING error. 00519 */ 00520 typedef int (XMLCALL *XML_UnknownEncodingHandler) ( 00521 void *encodingHandlerData, 00522 const XML_Char *name, 00523 XML_Encoding *info); 00524 00525 XMLPARSEAPI(void) 00526 XML_SetElementHandler(XML_Parser parser, 00527 XML_StartElementHandler start, 00528 XML_EndElementHandler end); 00529 00530 XMLPARSEAPI(void) 00531 XML_SetStartElementHandler(XML_Parser parser, 00532 XML_StartElementHandler handler); 00533 00534 XMLPARSEAPI(void) 00535 XML_SetEndElementHandler(XML_Parser parser, 00536 XML_EndElementHandler handler); 00537 00538 XMLPARSEAPI(void) 00539 XML_SetCharacterDataHandler(XML_Parser parser, 00540 XML_CharacterDataHandler handler); 00541 00542 XMLPARSEAPI(void) 00543 XML_SetProcessingInstructionHandler(XML_Parser parser, 00544 XML_ProcessingInstructionHandler handler); 00545 XMLPARSEAPI(void) 00546 XML_SetCommentHandler(XML_Parser parser, 00547 XML_CommentHandler handler); 00548 00549 XMLPARSEAPI(void) 00550 XML_SetCdataSectionHandler(XML_Parser parser, 00551 XML_StartCdataSectionHandler start, 00552 XML_EndCdataSectionHandler end); 00553 00554 XMLPARSEAPI(void) 00555 XML_SetStartCdataSectionHandler(XML_Parser parser, 00556 XML_StartCdataSectionHandler start); 00557 00558 XMLPARSEAPI(void) 00559 XML_SetEndCdataSectionHandler(XML_Parser parser, 00560 XML_EndCdataSectionHandler end); 00561 00562 /* This sets the default handler and also inhibits expansion of 00563 internal entities. These entity references will be passed to the 00564 default handler, or to the skipped entity handler, if one is set. 00565 */ 00566 XMLPARSEAPI(void) 00567 XML_SetDefaultHandler(XML_Parser parser, 00568 XML_DefaultHandler handler); 00569 00570 /* This sets the default handler but does not inhibit expansion of 00571 internal entities. The entity reference will not be passed to the 00572 default handler. 00573 */ 00574 XMLPARSEAPI(void) 00575 XML_SetDefaultHandlerExpand(XML_Parser parser, 00576 XML_DefaultHandler handler); 00577 00578 XMLPARSEAPI(void) 00579 XML_SetDoctypeDeclHandler(XML_Parser parser, 00580 XML_StartDoctypeDeclHandler start, 00581 XML_EndDoctypeDeclHandler end); 00582 00583 XMLPARSEAPI(void) 00584 XML_SetStartDoctypeDeclHandler(XML_Parser parser, 00585 XML_StartDoctypeDeclHandler start); 00586 00587 XMLPARSEAPI(void) 00588 XML_SetEndDoctypeDeclHandler(XML_Parser parser, 00589 XML_EndDoctypeDeclHandler end); 00590 00591 XMLPARSEAPI(void) 00592 XML_SetUnparsedEntityDeclHandler(XML_Parser parser, 00593 XML_UnparsedEntityDeclHandler handler); 00594 00595 XMLPARSEAPI(void) 00596 XML_SetNotationDeclHandler(XML_Parser parser, 00597 XML_NotationDeclHandler handler); 00598 00599 XMLPARSEAPI(void) 00600 XML_SetNamespaceDeclHandler(XML_Parser parser, 00601 XML_StartNamespaceDeclHandler start, 00602 XML_EndNamespaceDeclHandler end); 00603 00604 XMLPARSEAPI(void) 00605 XML_SetStartNamespaceDeclHandler(XML_Parser parser, 00606 XML_StartNamespaceDeclHandler start); 00607 00608 XMLPARSEAPI(void) 00609 XML_SetEndNamespaceDeclHandler(XML_Parser parser, 00610 XML_EndNamespaceDeclHandler end); 00611 00612 XMLPARSEAPI(void) 00613 XML_SetNotStandaloneHandler(XML_Parser parser, 00614 XML_NotStandaloneHandler handler); 00615 00616 XMLPARSEAPI(void) 00617 XML_SetExternalEntityRefHandler(XML_Parser parser, 00618 XML_ExternalEntityRefHandler handler); 00619 00620 /* If a non-NULL value for arg is specified here, then it will be 00621 passed as the first argument to the external entity ref handler 00622 instead of the parser object. 00623 */ 00624 XMLPARSEAPI(void) 00625 XML_SetExternalEntityRefHandlerArg(XML_Parser parser, 00626 void *arg); 00627 00628 XMLPARSEAPI(void) 00629 XML_SetSkippedEntityHandler(XML_Parser parser, 00630 XML_SkippedEntityHandler handler); 00631 00632 XMLPARSEAPI(void) 00633 XML_SetUnknownEncodingHandler(XML_Parser parser, 00634 XML_UnknownEncodingHandler handler, 00635 void *encodingHandlerData); 00636 00637 /* This can be called within a handler for a start element, end 00638 element, processing instruction or character data. It causes the 00639 corresponding markup to be passed to the default handler. 00640 */ 00641 XMLPARSEAPI(void) 00642 XML_DefaultCurrent(XML_Parser parser); 00643 00644 /* If do_nst is non-zero, and namespace processing is in effect, and 00645 a name has a prefix (i.e. an explicit namespace qualifier) then 00646 that name is returned as a triplet in a single string separated by 00647 the separator character specified when the parser was created: URI 00648 + sep + local_name + sep + prefix. 00649 00650 If do_nst is zero, then namespace information is returned in the 00651 default manner (URI + sep + local_name) whether or not the name 00652 has a prefix. 00653 00654 Note: Calling XML_SetReturnNSTriplet after XML_Parse or 00655 XML_ParseBuffer has no effect. 00656 */ 00657 00658 XMLPARSEAPI(void) 00659 XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); 00660 00661 /* This value is passed as the userData argument to callbacks. */ 00662 XMLPARSEAPI(void) 00663 XML_SetUserData(XML_Parser parser, void *userData); 00664 00665 /* Returns the last value set by XML_SetUserData or NULL. */ 00666 #define XML_GetUserData(parser) (*(void **)(parser)) 00667 00668 /* This is equivalent to supplying an encoding argument to 00669 XML_ParserCreate. On success XML_SetEncoding returns non-zero, 00670 zero otherwise. 00671 Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer 00672 has no effect and returns XML_STATUS_ERROR. 00673 */ 00674 XMLPARSEAPI(enum XML_Status) 00675 XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); 00676 00677 /* If this function is called, then the parser will be passed as the 00678 first argument to callbacks instead of userData. The userData will 00679 still be accessible using XML_GetUserData. 00680 */ 00681 XMLPARSEAPI(void) 00682 XML_UseParserAsHandlerArg(XML_Parser parser); 00683 00684 /* If useDTD == XML_TRUE is passed to this function, then the parser 00685 will assume that there is an external subset, even if none is 00686 specified in the document. In such a case the parser will call the 00687 externalEntityRefHandler with a value of NULL for the systemId 00688 argument (the publicId and context arguments will be NULL as well). 00689 Note: For the purpose of checking WFC: Entity Declared, passing 00690 useDTD == XML_TRUE will make the parser behave as if the document 00691 had a DTD with an external subset. 00692 Note: If this function is called, then this must be done before 00693 the first call to XML_Parse or XML_ParseBuffer, since it will 00694 have no effect after that. Returns 00695 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. 00696 Note: If the document does not have a DOCTYPE declaration at all, 00697 then startDoctypeDeclHandler and endDoctypeDeclHandler will not 00698 be called, despite an external subset being parsed. 00699 Note: If XML_DTD is not defined when Expat is compiled, returns 00700 XML_ERROR_FEATURE_REQUIRES_XML_DTD. 00701 */ 00702 XMLPARSEAPI(enum XML_Error) 00703 XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); 00704 00705 00706 /* Sets the base to be used for resolving relative URIs in system 00707 identifiers in declarations. Resolving relative identifiers is 00708 left to the application: this value will be passed through as the 00709 base argument to the XML_ExternalEntityRefHandler, 00710 XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base 00711 argument will be copied. Returns XML_STATUS_ERROR if out of memory, 00712 XML_STATUS_OK otherwise. 00713 */ 00714 XMLPARSEAPI(enum XML_Status) 00715 XML_SetBase(XML_Parser parser, const XML_Char *base); 00716 00717 XMLPARSEAPI(const XML_Char *) 00718 XML_GetBase(XML_Parser parser); 00719 00720 /* Returns the number of the attribute/value pairs passed in last call 00721 to the XML_StartElementHandler that were specified in the start-tag 00722 rather than defaulted. Each attribute/value pair counts as 2; thus 00723 this correspondds to an index into the atts array passed to the 00724 XML_StartElementHandler. 00725 */ 00726 XMLPARSEAPI(int) 00727 XML_GetSpecifiedAttributeCount(XML_Parser parser); 00728 00729 /* Returns the index of the ID attribute passed in the last call to 00730 XML_StartElementHandler, or -1 if there is no ID attribute. Each 00731 attribute/value pair counts as 2; thus this correspondds to an 00732 index into the atts array passed to the XML_StartElementHandler. 00733 */ 00734 XMLPARSEAPI(int) 00735 XML_GetIdAttributeIndex(XML_Parser parser); 00736 00737 /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is 00738 detected. The last call to XML_Parse must have isFinal true; len 00739 may be zero for this call (or any other). 00740 00741 Though the return values for these functions has always been 00742 described as a Boolean value, the implementation, at least for the 00743 1.95.x series, has always returned exactly one of the XML_Status 00744 values. 00745 */ 00746 XMLPARSEAPI(enum XML_Status) 00747 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); 00748 00749 XMLPARSEAPI(void *) 00750 XML_GetBuffer(XML_Parser parser, int len); 00751 00752 XMLPARSEAPI(enum XML_Status) 00753 XML_ParseBuffer(XML_Parser parser, int len, int isFinal); 00754 00755 /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. 00756 Must be called from within a call-back handler, except when aborting 00757 (resumable = 0) an already suspended parser. Some call-backs may 00758 still follow because they would otherwise get lost. Examples: 00759 - endElementHandler() for empty elements when stopped in 00760 startElementHandler(), 00761 - endNameSpaceDeclHandler() when stopped in endElementHandler(), 00762 and possibly others. 00763 00764 Can be called from most handlers, including DTD related call-backs, 00765 except when parsing an external parameter entity and resumable != 0. 00766 Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. 00767 Possible error codes: 00768 - XML_ERROR_SUSPENDED: when suspending an already suspended parser. 00769 - XML_ERROR_FINISHED: when the parser has already finished. 00770 - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. 00771 00772 When resumable != 0 (true) then parsing is suspended, that is, 00773 XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. 00774 Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() 00775 return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. 00776 00777 *Note*: 00778 This will be applied to the current parser instance only, that is, if 00779 there is a parent parser then it will continue parsing when the 00780 externalEntityRefHandler() returns. It is up to the implementation of 00781 the externalEntityRefHandler() to call XML_StopParser() on the parent 00782 parser (recursively), if one wants to stop parsing altogether. 00783 00784 When suspended, parsing can be resumed by calling XML_ResumeParser(). 00785 */ 00786 XMLPARSEAPI(enum XML_Status) 00787 XML_StopParser(XML_Parser parser, XML_Bool resumable); 00788 00789 /* Resumes parsing after it has been suspended with XML_StopParser(). 00790 Must not be called from within a handler call-back. Returns same 00791 status codes as XML_Parse() or XML_ParseBuffer(). 00792 Additional error code XML_ERROR_NOT_SUSPENDED possible. 00793 00794 *Note*: 00795 This must be called on the most deeply nested child parser instance 00796 first, and on its parent parser only after the child parser has finished, 00797 to be applied recursively until the document entity's parser is restarted. 00798 That is, the parent parser will not resume by itself and it is up to the 00799 application to call XML_ResumeParser() on it at the appropriate moment. 00800 */ 00801 XMLPARSEAPI(enum XML_Status) 00802 XML_ResumeParser(XML_Parser parser); 00803 00804 enum XML_Parsing { 00805 XML_INITIALIZED, 00806 XML_PARSING, 00807 XML_FINISHED, 00808 XML_SUSPENDED 00809 }; 00810 00811 typedef struct { 00812 enum XML_Parsing parsing; 00813 XML_Bool finalBuffer; 00814 } XML_ParsingStatus; 00815 00816 /* Returns status of parser with respect to being initialized, parsing, 00817 finished, or suspended and processing the final buffer. 00818 XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, 00819 XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED 00820 */ 00821 XMLPARSEAPI(void) 00822 XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); 00823 00824 /* Creates an XML_Parser object that can parse an external general 00825 entity; context is a '\0'-terminated string specifying the parse 00826 context; encoding is a '\0'-terminated string giving the name of 00827 the externally specified encoding, or NULL if there is no 00828 externally specified encoding. The context string consists of a 00829 sequence of tokens separated by formfeeds (\f); a token consisting 00830 of a name specifies that the general entity of the name is open; a 00831 token of the form prefix=uri specifies the namespace for a 00832 particular prefix; a token of the form =uri specifies the default 00833 namespace. This can be called at any point after the first call to 00834 an ExternalEntityRefHandler so longer as the parser has not yet 00835 been freed. The new parser is completely independent and may 00836 safely be used in a separate thread. The handlers and userData are 00837 initialized from the parser argument. Returns NULL if out of memory. 00838 Otherwise returns a new XML_Parser object. 00839 */ 00840 XMLPARSEAPI(XML_Parser) 00841 XML_ExternalEntityParserCreate(XML_Parser parser, 00842 const XML_Char *context, 00843 const XML_Char *encoding); 00844 00845 enum XML_ParamEntityParsing { 00846 XML_PARAM_ENTITY_PARSING_NEVER, 00847 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, 00848 XML_PARAM_ENTITY_PARSING_ALWAYS 00849 }; 00850 00851 /* Controls parsing of parameter entities (including the external DTD 00852 subset). If parsing of parameter entities is enabled, then 00853 references to external parameter entities (including the external 00854 DTD subset) will be passed to the handler set with 00855 XML_SetExternalEntityRefHandler. The context passed will be 0. 00856 00857 Unlike external general entities, external parameter entities can 00858 only be parsed synchronously. If the external parameter entity is 00859 to be parsed, it must be parsed during the call to the external 00860 entity ref handler: the complete sequence of 00861 XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and 00862 XML_ParserFree calls must be made during this call. After 00863 XML_ExternalEntityParserCreate has been called to create the parser 00864 for the external parameter entity (context must be 0 for this 00865 call), it is illegal to make any calls on the old parser until 00866 XML_ParserFree has been called on the newly created parser. 00867 If the library has been compiled without support for parameter 00868 entity parsing (ie without XML_DTD being defined), then 00869 XML_SetParamEntityParsing will return 0 if parsing of parameter 00870 entities is requested; otherwise it will return non-zero. 00871 Note: If XML_SetParamEntityParsing is called after XML_Parse or 00872 XML_ParseBuffer, then it has no effect and will always return 0. 00873 */ 00874 XMLPARSEAPI(int) 00875 XML_SetParamEntityParsing(XML_Parser parser, 00876 enum XML_ParamEntityParsing parsing); 00877 00878 /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then 00879 XML_GetErrorCode returns information about the error. 00880 */ 00881 XMLPARSEAPI(enum XML_Error) 00882 XML_GetErrorCode(XML_Parser parser); 00883 00884 /* These functions return information about the current parse 00885 location. They may be called from any callback called to report 00886 some parse event; in this case the location is the location of the 00887 first of the sequence of characters that generated the event. When 00888 called from callbacks generated by declarations in the document 00889 prologue, the location identified isn't as neatly defined, but will 00890 be within the relevant markup. When called outside of the callback 00891 functions, the position indicated will be just past the last parse 00892 event (regardless of whether there was an associated callback). 00893 00894 They may also be called after returning from a call to XML_Parse 00895 or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then 00896 the location is the location of the character at which the error 00897 was detected; otherwise the location is the location of the last 00898 parse event, as described above. 00899 */ 00900 XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser); 00901 XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser); 00902 XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser); 00903 00904 /* Return the number of bytes in the current event. 00905 Returns 0 if the event is in an internal entity. 00906 */ 00907 XMLPARSEAPI(int) 00908 XML_GetCurrentByteCount(XML_Parser parser); 00909 00910 /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets 00911 the integer pointed to by offset to the offset within this buffer 00912 of the current parse position, and sets the integer pointed to by size 00913 to the size of this buffer (the number of input bytes). Otherwise 00914 returns a NULL pointer. Also returns a NULL pointer if a parse isn't 00915 active. 00916 00917 NOTE: The character pointer returned should not be used outside 00918 the handler that makes the call. 00919 */ 00920 XMLPARSEAPI(const char *) 00921 XML_GetInputContext(XML_Parser parser, 00922 int *offset, 00923 int *size); 00924 00925 /* For backwards compatibility with previous versions. */ 00926 #define XML_GetErrorLineNumber XML_GetCurrentLineNumber 00927 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber 00928 #define XML_GetErrorByteIndex XML_GetCurrentByteIndex 00929 00930 /* Frees the content model passed to the element declaration handler */ 00931 XMLPARSEAPI(void) 00932 XML_FreeContentModel(XML_Parser parser, XML_Content *model); 00933 00934 /* Exposing the memory handling functions used in Expat */ 00935 XMLPARSEAPI(void *) 00936 XML_MemMalloc(XML_Parser parser, size_t size); 00937 00938 XMLPARSEAPI(void *) 00939 XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); 00940 00941 XMLPARSEAPI(void) 00942 XML_MemFree(XML_Parser parser, void *ptr); 00943 00944 /* Frees memory used by the parser. */ 00945 XMLPARSEAPI(void) 00946 XML_ParserFree(XML_Parser parser); 00947 00948 /* Returns a string describing the error. */ 00949 XMLPARSEAPI(const XML_LChar *) 00950 XML_ErrorString(enum XML_Error code); 00951 00952 /* Return a string containing the version number of this expat */ 00953 XMLPARSEAPI(const XML_LChar *) 00954 XML_ExpatVersion(void); 00955 00956 typedef struct { 00957 int major; 00958 int minor; 00959 int micro; 00960 } XML_Expat_Version; 00961 00962 /* Return an XML_Expat_Version structure containing numeric version 00963 number information for this version of expat. 00964 */ 00965 XMLPARSEAPI(XML_Expat_Version) 00966 XML_ExpatVersionInfo(void); 00967 00968 /* Added in Expat 1.95.5. */ 00969 enum XML_FeatureEnum { 00970 XML_FEATURE_END = 0, 00971 XML_FEATURE_UNICODE, 00972 XML_FEATURE_UNICODE_WCHAR_T, 00973 XML_FEATURE_DTD, 00974 XML_FEATURE_CONTEXT_BYTES, 00975 XML_FEATURE_MIN_SIZE, 00976 XML_FEATURE_SIZEOF_XML_CHAR, 00977 XML_FEATURE_SIZEOF_XML_LCHAR 00978 /* Additional features must be added to the end of this enum. */ 00979 }; 00980 00981 typedef struct { 00982 enum XML_FeatureEnum feature; 00983 const XML_LChar *name; 00984 long int value; 00985 } XML_Feature; 00986 00987 XMLPARSEAPI(const XML_Feature *) 00988 XML_GetFeatureList(void); 00989 00990 00991 /* Expat follows the GNU/Linux convention of odd number minor version for 00992 beta/development releases and even number minor version for stable 00993 releases. Micro is bumped with each release, and set to 0 with each 00994 change to major or minor version. 00995 */ 00996 #define XML_MAJOR_VERSION 1 00997 #define XML_MINOR_VERSION 95 00998 #define XML_MICRO_VERSION 8 00999 01000 #ifdef __cplusplus 01001 } 01002 #endif 01003 01004 #endif /* not XmlParse_INCLUDED */