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