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