-- 作者:JamesHou
-- 发布时间:9/19/2004 6:18:00 PM
--
xmlparse.h内容如下: 00001 /* 00002 externi knihovna 00003 00004 Hlavickovy soubor k externi knihovne extpatpp.lib 00005 00006 unknown, unknown 00007 */ 00008 00009 /* 00010 Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd 00011 See the file copying.txt for copying permission. 00012 */ 00013 00014 #ifndef XmlParse_INCLUDED 00015 #define XmlParse_INCLUDED 1 00016 00017 #ifdef __cplusplus 00018 extern "C" { 00019 #endif 00020 00021 #ifndef XMLPARSEAPI 00022 #define XMLPARSEAPI /* as nothing */ 00023 #endif 00024 00025 typedef void *XML_Parser; 00026 00027 #ifdef XML_UNICODE_WCHAR_T 00028 00029 /* XML_UNICODE_WCHAR_T will work only if sizeof(wchar_t) == 2 and wchar_t 00030 uses Unicode. */ 00031 /* Information is UTF-16 encoded as wchar_ts */ 00032 00033 #ifndef XML_UNICODE 00034 #define XML_UNICODE 00035 #endif 00036 00037 #include <stddef.h> 00038 typedef wchar_t XML_Char; 00039 typedef wchar_t XML_LChar; 00040 00041 #else /* not XML_UNICODE_WCHAR_T */ 00042 00043 #ifdef XML_UNICODE 00044 00045 /* Information is UTF-16 encoded as unsigned shorts */ 00046 typedef unsigned short XML_Char; 00047 typedef char XML_LChar; 00048 00049 #else /* not XML_UNICODE */ 00050 00051 /* Information is UTF-8 encoded. */ 00052 typedef char XML_Char; 00053 typedef char XML_LChar; 00054 00055 #endif /* not XML_UNICODE */ 00056 00057 #endif /* not XML_UNICODE_WCHAR_T */ 00058 00059 00060 /* Constructs a new parser; encoding is the encoding specified by the external 00061 protocol or null if there is none specified. */ 00062 00063 XML_Parser XMLPARSEAPI 00064 XML_ParserCreate(const XML_Char *encoding); 00065 00066 /* Constructs a new parser and namespace processor. Element type names 00067 and attribute names that belong to a namespace will be expanded; 00068 unprefixed attribute names are never expanded; unprefixed element type 00069 names are expanded only if there is a default namespace. The expanded 00070 name is the concatenation of the namespace URI, the namespace separator character, 00071 and the local part of the name. If the namespace separator is '\0' then 00072 the namespace URI and the local part will be concatenated without any 00073 separator. When a namespace is not declared, the name and prefix will be 00074 passed through without expansion. */ 00075 00076 XML_Parser XMLPARSEAPI 00077 XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); 00078 00079 00080 /* atts is array of name/value pairs, terminated by 0; 00081 names and values are 0 terminated. */ 00082 00083 typedef void (*XML_StartElementHandler)(void *userData, 00084 const XML_Char *name, 00085 const XML_Char **atts); 00086 00087 typedef void (*XML_EndElementHandler)(void *userData, 00088 const XML_Char *name); 00089 00090 /* s is not 0 terminated. */ 00091 typedef void (*XML_CharacterDataHandler)(void *userData, 00092 const XML_Char *s, 00093 int len); 00094 00095 /* target and data are 0 terminated */ 00096 typedef void (*XML_ProcessingInstructionHandler)(void *userData, 00097 const XML_Char *target, 00098 const XML_Char *data); 00099 00100 /* data is 0 terminated */ 00101 typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data); 00102 00103 typedef void (*XML_StartCdataSectionHandler)(void *userData); 00104 typedef void (*XML_EndCdataSectionHandler)(void *userData); 00105 00106 /* This is called for any characters in the XML document for 00107 which there is no applicable handler. This includes both 00108 characters that are part of markup which is of a kind that is 00109 not reported (comments, markup declarations), or characters 00110 that are part of a construct which could be reported but 00111 for which no handler has been supplied. The characters are passed 00112 exactly as they were in the XML document except that 00113 they will be encoded in UTF-8. Line boundaries are not normalized. 00114 Note that a byte order mark character is not passed to the default handler. 00115 There are no guarantees about how characters are divided between calls 00116 to the default handler: for example, a comment might be split between 00117 multiple calls. */ 00118 00119 typedef void (*XML_DefaultHandler)(void *userData, 00120 const XML_Char *s, 00121 int len); 00122 00123 /* This is called for the start of the DOCTYPE declaration when the 00124 name of the DOCTYPE is encountered. */ 00125 typedef void (*XML_StartDoctypeDeclHandler)(void *userData, 00126 const XML_Char *doctypeName); 00127 00128 /* This is called for the start of the DOCTYPE declaration when the 00129 closing > is encountered, but after processing any external subset. */ 00130 typedef void (*XML_EndDoctypeDeclHandler)(void *userData); 00131 00132 /* This is called for a declaration of an unparsed (NDATA) 00133 entity. The base argument is whatever was set by XML_SetBase. 00134 The entityName, systemId and notationName arguments will never be null. 00135 The other arguments may be. */ 00136 00137 typedef void (*XML_UnparsedEntityDeclHandler)(void *userData, 00138 const XML_Char *entityName, 00139 const XML_Char *base, 00140 const XML_Char *systemId, 00141 const XML_Char *publicId, 00142 const XML_Char *notationName); 00143 00144 /* This is called for a declaration of notation. 00145 The base argument is whatever was set by XML_SetBase. 00146 The notationName will never be null. The other arguments can be. */ 00147 00148 typedef void (*XML_NotationDeclHandler)(void *userData, 00149 const XML_Char *notationName, 00150 const XML_Char *base, 00151 const XML_Char *systemId, 00152 const XML_Char *publicId); 00153 00154 typedef void (*XML_ExternalParsedEntityDeclHandler)(void *userData, 00155 const XML_Char *entityName, 00156 const XML_Char *base, 00157 const XML_Char *systemId, 00158 const XML_Char *publicId); 00159 00160 typedef void (*XML_InternalParsedEntityDeclHandler)(void *userData, 00161 const XML_Char *entityName, 00162 const XML_Char *replacementText, 00163 int replacementTextLength); 00164 00165 /* When namespace processing is enabled, these are called once for 00166 each namespace declaration. The call to the start and end element 00167 handlers occur between the calls to the start and end namespace 00168 declaration handlers. For an xmlns attribute, prefix will be null. 00169 For an xmlns="" attribute, uri will be null. */ 00170 00171 typedef void (*XML_StartNamespaceDeclHandler)(void *userData, 00172 const XML_Char *prefix, 00173 const XML_Char *uri); 00174 00175 typedef void (*XML_EndNamespaceDeclHandler)(void *userData, 00176 const XML_Char *prefix); 00177 00178 /* This is called if the document is not standalone (it has an 00179 external subset or a reference to a parameter entity, but does not 00180 have standalone="yes"). If this handler returns 0, then processing 00181 will not continue, and the parser will return a 00182 XML_ERROR_NOT_STANDALONE error. */ 00183 00184 typedef int (*XML_NotStandaloneHandler)(void *userData); 00185 00186 /* This is called for a reference to an external parsed general entity. 00187 The referenced entity is not automatically parsed. 00188 The application can parse it immediately or later using 00189 XML_ExternalEntityParserCreate. 00190 The parser argument is the parser parsing the entity containing the reference; 00191 it can be passed as the parser argument to XML_ExternalEntityParserCreate. 00192 The systemId argument is the system identifier as specified in the entity declaration; 00193 it will not be null. 00194 The base argument is the system identifier that should be used as the base for 00195 resolving systemId if systemId was relative; this is set by XML_SetBase; 00196 it may be null. 00197 The publicId argument is the public identifier as specified in the entity declaration, 00198 or null if none was specified; the whitespace in the public identifier 00199 will have been normalized as required by the XML spec. 00200 The context argument specifies the parsing context in the format 00201 expected by the context argument to 00202 XML_ExternalEntityParserCreate; context is valid only until the handler 00203 returns, so if the referenced entity is to be parsed later, it must be copied. 00204 The handler should return 0 if processing should not continue because of 00205 a fatal error in the handling of the external entity. 00206 In this case the calling parser will return an XML_ERROR_EXTERNAL_ENTITY_HANDLING 00207 error. 00208 Note that unlike other handlers the first argument is the parser, not userData. */ 00209 00210 typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser, 00211 const XML_Char *context, 00212 const XML_Char *base, 00213 const XML_Char *systemId, 00214 const XML_Char *publicId); 00215 00216 /* This structure is filled in by the XML_UnknownEncodingHandler 00217 to provide information to the parser about encodings that are unknown 00218 to the parser. 00219 The map[b] member gives information about byte sequences 00220 whose first byte is b. 00221 If map[b] is c where c is >= 0, then b by itself encodes the Unicode scalar value c. 00222 If map[b] is -1, then the byte sequence is malformed. 00223 If map[b] is -n, where n >= 2, then b is the first byte of an n-byte 00224 sequence that encodes a single Unicode scalar value. 00225 The data member will be passed as the first argument to the convert function. 00226 The convert function is used to convert multibyte sequences; 00227 s will point to a n-byte sequence where map[(unsigned char)*s] == -n. 00228 The convert function must return the Unicode scalar value 00229 represented by this byte sequence or -1 if the byte sequence is malformed. 00230 The convert function may be null if the encoding is a single-byte encoding, 00231 that is if map[b] >= -1 for all bytes b. 00232 When the parser is finished with the encoding, then if release is not null, 00233 it will call release passing it the data member; 00234 once release has been called, the convert function will not be called again. 00235 00236 Expat places certain restrictions on the encodings that are supported 00237 using this mechanism. 00238 00239 1. Every ASCII character that can appear in a well-formed XML document, 00240 other than the characters 00241 00242 $@\^`{}~ 00243 00244 must be represented by a single byte, and that byte must be the 00245 same byte that represents that character in ASCII. 00246 00247 2. No character may require more than 4 bytes to encode. 00248 00249 3. All characters encoded must have Unicode scalar values <= 0xFFFF, 00250 (ie characters that would be encoded by surrogates in UTF-16 00251 are not allowed). Note that this restriction doesn't apply to 00252 the built-in support for UTF-8 and UTF-16. 00253 00254 4. No Unicode character may be encoded by more than one distinct sequence 00255 of bytes. */ 00256 00257 typedef struct { 00258 int map[256]; 00259 void *data; 00260 int (*convert)(void *data, const char *s); 00261 void (*release)(void *data); 00262 } XML_Encoding; 00263 00264 /* This is called for an encoding that is unknown to the parser. 00265 The encodingHandlerData argument is that which was passed as the 00266 second argument to XML_SetUnknownEncodingHandler. 00267 The name argument gives the name of the encoding as specified in 00268 the encoding declaration. 00269 If the callback can provide information about the encoding, 00270 it must fill in the XML_Encoding structure, and return 1. 00271 Otherwise it must return 0. 00272 If info does not describe a suitable encoding, 00273 then the parser will return an XML_UNKNOWN_ENCODING error. */ 00274 00275 typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData, 00276 const XML_Char *name, 00277 XML_Encoding *info); 00278 00279 void XMLPARSEAPI 00280 XML_SetElementHandler(XML_Parser parser, 00281 XML_StartElementHandler start, 00282 XML_EndElementHandler end); 00283 00284 void XMLPARSEAPI 00285 XML_SetCharacterDataHandler(XML_Parser parser, 00286 XML_CharacterDataHandler handler); 00287 00288 void XMLPARSEAPI 00289 XML_SetProcessingInstructionHandler(XML_Parser parser, 00290 XML_ProcessingInstructionHandler handler); 00291 void XMLPARSEAPI 00292 XML_SetCommentHandler(XML_Parser parser, 00293 XML_CommentHandler handler); 00294 00295 void XMLPARSEAPI 00296 XML_SetCdataSectionHandler(XML_Parser parser, 00297 XML_StartCdataSectionHandler start, 00298 XML_EndCdataSectionHandler end); 00299 00300 /* This sets the default handler and also inhibits expansion of internal entities. 00301 The entity reference will be passed to the default handler. */ 00302 00303 void XMLPARSEAPI 00304 XML_SetDefaultHandler(XML_Parser parser, 00305 XML_DefaultHandler handler); 00306 00307 /* This sets the default handler but does not inhibit expansion of internal entities. 00308 The entity reference will not be passed to the default handler. */ 00309 00310 void XMLPARSEAPI 00311 XML_SetDefaultHandlerExpand(XML_Parser parser, 00312 XML_DefaultHandler handler); 00313 00314 void XMLPARSEAPI 00315 XML_SetDoctypeDeclHandler(XML_Parser parser, 00316 XML_StartDoctypeDeclHandler start, 00317 XML_EndDoctypeDeclHandler end); 00318 00319 void XMLPARSEAPI 00320 XML_SetUnparsedEntityDeclHandler(XML_Parser parser, 00321 XML_UnparsedEntityDeclHandler handler); 00322 00323 void XMLPARSEAPI 00324 XML_SetNotationDeclHandler(XML_Parser parser, 00325 XML_NotationDeclHandler handler); 00326 00327 void XMLPARSEAPI 00328 XML_SetExternalParsedEntityDeclHandler(XML_Parser parser, 00329 XML_ExternalParsedEntityDeclHandler handler); 00330 00331 void XMLPARSEAPI 00332 XML_SetInternalParsedEntityDeclHandler(XML_Parser parser, 00333 XML_InternalParsedEntityDeclHandler handler); 00334 00335 void XMLPARSEAPI 00336 XML_SetNamespaceDeclHandler(XML_Parser parser, 00337 XML_StartNamespaceDeclHandler start, 00338 XML_EndNamespaceDeclHandler end); 00339 00340 void XMLPARSEAPI 00341 XML_SetNotStandaloneHandler(XML_Parser parser, 00342 XML_NotStandaloneHandler handler); 00343 00344 void XMLPARSEAPI 00345 XML_SetExternalEntityRefHandler(XML_Parser parser, 00346 XML_ExternalEntityRefHandler handler); 00347 00348 /* If a non-null value for arg is specified here, then it will be passed 00349 as the first argument to the external entity ref handler instead 00350 of the parser object. */ 00351 void XMLPARSEAPI 00352 XML_SetExternalEntityRefHandlerArg(XML_Parser, void *arg); 00353 00354 void XMLPARSEAPI 00355 XML_SetUnknownEncodingHandler(XML_Parser parser, 00356 XML_UnknownEncodingHandler handler, 00357 void *encodingHandlerData); 00358 00359 /* This can be called within a handler for a start element, end element, 00360 processing instruction or character data. It causes the corresponding 00361 markup to be passed to the default handler. */ 00362 void XMLPARSEAPI XML_DefaultCurrent(XML_Parser parser); 00363 00364 /* This value is passed as the userData argument to callbacks. */ 00365 void XMLPARSEAPI 00366 XML_SetUserData(XML_Parser parser, void *userData); 00367 00368 /* Returns the last value set by XML_SetUserData or null. */ 00369 #define XML_GetUserData(parser) (*(void **)(parser)) 00370 00371 /* This is equivalent to supplying an encoding argument 00372 to XML_ParserCreate. It must not be called after XML_Parse 00373 or XML_ParseBuffer. */ 00374 00375 int XMLPARSEAPI 00376 XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); 00377 00378 /* If this function is called, then the parser will be passed 00379 as the first argument to callbacks instead of userData. 00380 The userData will still be accessible using XML_GetUserData. */ 00381 00382 void XMLPARSEAPI 00383 XML_UseParserAsHandlerArg(XML_Parser parser); 00384 00385 /* Sets the base to be used for resolving relative URIs in system identifiers in 00386 declarations. Resolving relative identifiers is left to the application: 00387 this value will be passed through as the base argument to the 00388 XML_ExternalEntityRefHandler, XML_NotationDeclHandler 00389 and XML_UnparsedEntityDeclHandler. The base argument will be copied. 00390 Returns zero if out of memory, non-zero otherwise. */ 00391 00392 int XMLPARSEAPI 00393 XML_SetBase(XML_Parser parser, const XML_Char *base); 00394 00395 const XML_Char XMLPARSEAPI * 00396 XML_GetBase(XML_Parser parser); 00397 00398 /* Returns the number of the attribute/value pairs passed in last call 00399 to the XML_StartElementHandler that were specified in the start-tag 00400 rather than defaulted. Each attribute/value pair counts as 2; thus 00401 this correspondds to an index into the atts array passed to the 00402 XML_StartElementHandler. */ 00403 00404 int XMLPARSEAPI XML_GetSpecifiedAttributeCount(XML_Parser parser); 00405 00406 /* Returns the index of the ID attribute passed in the last call to 00407 XML_StartElementHandler, or -1 if there is no ID attribute. Each 00408 attribute/value pair counts as 2; thus this correspondds to an index 00409 into the atts array passed to the XML_StartElementHandler. */ 00410 int XMLPARSEAPI XML_GetIdAttributeIndex(XML_Parser parser); 00411 00412 /* Parses some input. Returns 0 if a fatal error is detected. 00413 The last call to XML_Parse must have isFinal true; 00414 len may be zero for this call (or any other). */ 00415 int XMLPARSEAPI 00416 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); 00417 00418 void XMLPARSEAPI * 00419 XML_GetBuffer(XML_Parser parser, int len); 00420 00421 int XMLPARSEAPI 00422 XML_ParseBuffer(XML_Parser parser, int len, int isFinal); 00423 00424 /* Creates an XML_Parser object that can parse an external general entity; 00425 context is a '\0'-terminated string specifying the parse context; 00426 encoding is a '\0'-terminated string giving the name of the externally specified encoding, 00427 or null if there is no externally specified encoding. 00428 The context string consists of a sequence of tokens separated by formfeeds (\f); 00429 a token consisting of a name specifies that the general entity of the name 00430 is open; a token of the form prefix=uri specifies the namespace for a particular 00431 prefix; a token of the form =uri specifies the default namespace. 00432 This can be called at any point after the first call to an ExternalEntityRefHandler 00433 so longer as the parser has not yet been freed. 00434 The new parser is completely independent and may safely be used in a separate thread. 00435 The handlers and userData are initialized from the parser argument. 00436 Returns 0 if out of memory. Otherwise returns a new XML_Parser object. */ 00437 XML_Parser XMLPARSEAPI 00438 XML_ExternalEntityParserCreate(XML_Parser parser, 00439 const XML_Char *context, 00440 const XML_Char *encoding); 00441 00442 enum XML_ParamEntityParsing { 00443 XML_PARAM_ENTITY_PARSING_NEVER, 00444 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, 00445 XML_PARAM_ENTITY_PARSING_ALWAYS 00446 }; 00447 00448 /* Controls parsing of parameter entities (including the external DTD 00449 subset). If parsing of parameter entities is enabled, then references 00450 to external parameter entities (including the external DTD subset) 00451 will be passed to the handler set with 00452 XML_SetExternalEntityRefHandler. The context passed will be 0. 00453 Unlike external general entities, external parameter entities can only 00454 be parsed synchronously. If the external parameter entity is to be 00455 parsed, it must be parsed during the call to the external entity ref 00456 handler: the complete sequence of XML_ExternalEntityParserCreate, 00457 XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during 00458 this call. After XML_ExternalEntityParserCreate has been called to 00459 create the parser for the external parameter entity (context must be 0 00460 for this call), it is illegal to make any calls on the old parser 00461 until XML_ParserFree has been called on the newly created parser. If 00462 the library has been compiled without support for parameter entity 00463 parsing (ie without XML_DTD being defined), then 00464 XML_SetParamEntityParsing will return 0 if parsing of parameter 00465 entities is requested; otherwise it will return non-zero. */ 00466 00467 int XMLPARSEAPI 00468 XML_SetParamEntityParsing(XML_Parser parser, 00469 enum XML_ParamEntityParsing parsing); 00470 00471 enum XML_Error { 00472 XML_ERROR_NONE, 00473 XML_ERROR_NO_MEMORY, 00474 XML_ERROR_SYNTAX, 00475 XML_ERROR_NO_ELEMENTS, 00476 XML_ERROR_INVALID_TOKEN, 00477 XML_ERROR_UNCLOSED_TOKEN, 00478 XML_ERROR_PARTIAL_CHAR, 00479 XML_ERROR_TAG_MISMATCH, 00480 XML_ERROR_DUPLICATE_ATTRIBUTE, 00481 XML_ERROR_JUNK_AFTER_DOC_ELEMENT, 00482 XML_ERROR_PARAM_ENTITY_REF, 00483 XML_ERROR_UNDEFINED_ENTITY, 00484 XML_ERROR_RECURSIVE_ENTITY_REF, 00485 XML_ERROR_ASYNC_ENTITY, 00486 XML_ERROR_BAD_CHAR_REF, 00487 XML_ERROR_BINARY_ENTITY_REF, 00488 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, 00489 XML_ERROR_MISPLACED_XML_PI, 00490 XML_ERROR_UNKNOWN_ENCODING, 00491 XML_ERROR_INCORRECT_ENCODING, 00492 XML_ERROR_UNCLOSED_CDATA_SECTION, 00493 XML_ERROR_EXTERNAL_ENTITY_HANDLING, 00494 XML_ERROR_NOT_STANDALONE 00495 }; 00496 00497 /* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode 00498 returns information about the error. */ 00499 00500 enum XML_Error XMLPARSEAPI XML_GetErrorCode(XML_Parser parser); 00501 00502 /* These functions return information about the current parse location. 00503 They may be called when XML_Parse or XML_ParseBuffer return 0; 00504 in this case the location is the location of the character at which 00505 the error was detected. 00506 They may also be called from any other callback called to report 00507 some parse event; in this the location is the location of the first 00508 of the sequence of characters that generated the event. */ 00509 00510 int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser); 00511 int XMLPARSEAPI XML_GetCurrentColumnNumber(XML_Parser parser); 00512 long XMLPARSEAPI XML_GetCurrentByteIndex(XML_Parser parser); 00513 00514 /* Return the number of bytes in the current event. 00515 Returns 0 if the event is in an internal entity. */ 00516 00517 int XMLPARSEAPI XML_GetCurrentByteCount(XML_Parser parser); 00518 00519 /* For backwards compatibility with previous versions. */ 00520 #define XML_GetErrorLineNumber XML_GetCurrentLineNumber 00521 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber 00522 #define XML_GetErrorByteIndex XML_GetCurrentByteIndex 00523 00524 /* Frees memory used by the parser. */ 00525 void XMLPARSEAPI 00526 XML_ParserFree(XML_Parser parser); 00527 00528 /* Returns a string describing the error. */ 00529 const XML_LChar XMLPARSEAPI *XML_ErrorString(int code); 00530 00531 #ifdef __cplusplus 00532 } 00533 #endif 00534 00535 #endif /* not XmlParse_INCLUDED */
|