michael@0: /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd michael@0: See the file COPYING for copying permission. michael@0: */ michael@0: michael@0: #ifndef Expat_INCLUDED michael@0: #define Expat_INCLUDED 1 michael@0: michael@0: #ifdef __VMS michael@0: /* 0 1 2 3 0 1 2 3 michael@0: 1234567890123456789012345678901 1234567890123456789012345678901 */ michael@0: #define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler michael@0: #define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler michael@0: #define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler michael@0: #define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg michael@0: #endif michael@0: michael@0: #include michael@0: #include "expat_external.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: struct XML_ParserStruct; michael@0: typedef struct XML_ParserStruct *XML_Parser; michael@0: michael@0: /* Should this be defined using stdbool.h when C99 is available? */ michael@0: typedef unsigned char XML_Bool; michael@0: #define XML_TRUE ((XML_Bool) 1) michael@0: #define XML_FALSE ((XML_Bool) 0) michael@0: michael@0: /* The XML_Status enum gives the possible return values for several michael@0: API functions. The preprocessor #defines are included so this michael@0: stanza can be added to code that still needs to support older michael@0: versions of Expat 1.95.x: michael@0: michael@0: #ifndef XML_STATUS_OK michael@0: #define XML_STATUS_OK 1 michael@0: #define XML_STATUS_ERROR 0 michael@0: #endif michael@0: michael@0: Otherwise, the #define hackery is quite ugly and would have been michael@0: dropped. michael@0: */ michael@0: enum XML_Status { michael@0: XML_STATUS_ERROR = 0, michael@0: #define XML_STATUS_ERROR XML_STATUS_ERROR michael@0: XML_STATUS_OK = 1, michael@0: #define XML_STATUS_OK XML_STATUS_OK michael@0: XML_STATUS_SUSPENDED = 2 michael@0: #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED michael@0: }; michael@0: michael@0: enum XML_Error { michael@0: XML_ERROR_NONE, michael@0: XML_ERROR_NO_MEMORY, michael@0: XML_ERROR_SYNTAX, michael@0: XML_ERROR_NO_ELEMENTS, michael@0: XML_ERROR_INVALID_TOKEN, michael@0: XML_ERROR_UNCLOSED_TOKEN, michael@0: XML_ERROR_PARTIAL_CHAR, michael@0: XML_ERROR_TAG_MISMATCH, michael@0: XML_ERROR_DUPLICATE_ATTRIBUTE, michael@0: XML_ERROR_JUNK_AFTER_DOC_ELEMENT, michael@0: XML_ERROR_PARAM_ENTITY_REF, michael@0: XML_ERROR_UNDEFINED_ENTITY, michael@0: XML_ERROR_RECURSIVE_ENTITY_REF, michael@0: XML_ERROR_ASYNC_ENTITY, michael@0: XML_ERROR_BAD_CHAR_REF, michael@0: XML_ERROR_BINARY_ENTITY_REF, michael@0: XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, michael@0: XML_ERROR_MISPLACED_XML_PI, michael@0: XML_ERROR_UNKNOWN_ENCODING, michael@0: XML_ERROR_INCORRECT_ENCODING, michael@0: XML_ERROR_UNCLOSED_CDATA_SECTION, michael@0: XML_ERROR_EXTERNAL_ENTITY_HANDLING, michael@0: XML_ERROR_NOT_STANDALONE, michael@0: XML_ERROR_UNEXPECTED_STATE, michael@0: XML_ERROR_ENTITY_DECLARED_IN_PE, michael@0: XML_ERROR_FEATURE_REQUIRES_XML_DTD, michael@0: XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, michael@0: /* Added in 1.95.7. */ michael@0: XML_ERROR_UNBOUND_PREFIX, michael@0: /* Added in 1.95.8. */ michael@0: XML_ERROR_UNDECLARING_PREFIX, michael@0: XML_ERROR_INCOMPLETE_PE, michael@0: XML_ERROR_XML_DECL, michael@0: XML_ERROR_TEXT_DECL, michael@0: XML_ERROR_PUBLICID, michael@0: XML_ERROR_SUSPENDED, michael@0: XML_ERROR_NOT_SUSPENDED, michael@0: XML_ERROR_ABORTED, michael@0: XML_ERROR_FINISHED, michael@0: XML_ERROR_SUSPEND_PE, michael@0: /* Added in 2.0. */ michael@0: XML_ERROR_RESERVED_PREFIX_XML, michael@0: XML_ERROR_RESERVED_PREFIX_XMLNS, michael@0: XML_ERROR_RESERVED_NAMESPACE_URI michael@0: }; michael@0: michael@0: enum XML_Content_Type { michael@0: XML_CTYPE_EMPTY = 1, michael@0: XML_CTYPE_ANY, michael@0: XML_CTYPE_MIXED, michael@0: XML_CTYPE_NAME, michael@0: XML_CTYPE_CHOICE, michael@0: XML_CTYPE_SEQ michael@0: }; michael@0: michael@0: enum XML_Content_Quant { michael@0: XML_CQUANT_NONE, michael@0: XML_CQUANT_OPT, michael@0: XML_CQUANT_REP, michael@0: XML_CQUANT_PLUS michael@0: }; michael@0: michael@0: /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be michael@0: XML_CQUANT_NONE, and the other fields will be zero or NULL. michael@0: If type == XML_CTYPE_MIXED, then quant will be NONE or REP and michael@0: numchildren will contain number of elements that may be mixed in michael@0: and children point to an array of XML_Content cells that will be michael@0: all of XML_CTYPE_NAME type with no quantification. michael@0: michael@0: If type == XML_CTYPE_NAME, then the name points to the name, and michael@0: the numchildren field will be zero and children will be NULL. The michael@0: quant fields indicates any quantifiers placed on the name. michael@0: michael@0: CHOICE and SEQ will have name NULL, the number of children in michael@0: numchildren and children will point, recursively, to an array michael@0: of XML_Content cells. michael@0: michael@0: The EMPTY, ANY, and MIXED types will only occur at top level. michael@0: */ michael@0: michael@0: typedef struct XML_cp XML_Content; michael@0: michael@0: struct XML_cp { michael@0: enum XML_Content_Type type; michael@0: enum XML_Content_Quant quant; michael@0: XML_Char * name; michael@0: unsigned int numchildren; michael@0: XML_Content * children; michael@0: }; michael@0: michael@0: michael@0: /* This is called for an element declaration. See above for michael@0: description of the model argument. It's the caller's responsibility michael@0: to free model when finished with it. michael@0: */ michael@0: typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, michael@0: const XML_Char *name, michael@0: XML_Content *model); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetElementDeclHandler(XML_Parser parser, michael@0: XML_ElementDeclHandler eldecl); michael@0: michael@0: /* The Attlist declaration handler is called for *each* attribute. So michael@0: a single Attlist declaration with multiple attributes declared will michael@0: generate multiple calls to this handler. The "default" parameter michael@0: may be NULL in the case of the "#IMPLIED" or "#REQUIRED" michael@0: keyword. The "isrequired" parameter will be true and the default michael@0: value will be NULL in the case of "#REQUIRED". If "isrequired" is michael@0: true and default is non-NULL, then this is a "#FIXED" default. michael@0: */ michael@0: typedef void (XMLCALL *XML_AttlistDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *elname, michael@0: const XML_Char *attname, michael@0: const XML_Char *att_type, michael@0: const XML_Char *dflt, michael@0: int isrequired); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetAttlistDeclHandler(XML_Parser parser, michael@0: XML_AttlistDeclHandler attdecl); michael@0: michael@0: /* The XML declaration handler is called for *both* XML declarations michael@0: and text declarations. The way to distinguish is that the version michael@0: parameter will be NULL for text declarations. The encoding michael@0: parameter may be NULL for XML declarations. The standalone michael@0: parameter will be -1, 0, or 1 indicating respectively that there michael@0: was no standalone parameter in the declaration, that it was given michael@0: as no, or that it was given as yes. michael@0: */ michael@0: typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, michael@0: const XML_Char *version, michael@0: const XML_Char *encoding, michael@0: int standalone); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetXmlDeclHandler(XML_Parser parser, michael@0: XML_XmlDeclHandler xmldecl); michael@0: michael@0: michael@0: typedef struct { michael@0: void *(*malloc_fcn)(size_t size); michael@0: void *(*realloc_fcn)(void *ptr, size_t size); michael@0: void (*free_fcn)(void *ptr); michael@0: } XML_Memory_Handling_Suite; michael@0: michael@0: /* Constructs a new parser; encoding is the encoding specified by the michael@0: external protocol or NULL if there is none specified. michael@0: */ michael@0: XMLPARSEAPI(XML_Parser) michael@0: XML_ParserCreate(const XML_Char *encoding); michael@0: michael@0: /* Constructs a new parser and namespace processor. Element type michael@0: names and attribute names that belong to a namespace will be michael@0: expanded; unprefixed attribute names are never expanded; unprefixed michael@0: element type names are expanded only if there is a default michael@0: namespace. The expanded name is the concatenation of the namespace michael@0: URI, the namespace separator character, and the local part of the michael@0: name. If the namespace separator is '\0' then the namespace URI michael@0: and the local part will be concatenated without any separator. michael@0: It is a programming error to use the separator '\0' with namespace michael@0: triplets (see XML_SetReturnNSTriplet). michael@0: */ michael@0: XMLPARSEAPI(XML_Parser) michael@0: XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); michael@0: michael@0: michael@0: /* Constructs a new parser using the memory management suite referred to michael@0: by memsuite. If memsuite is NULL, then use the standard library memory michael@0: suite. If namespaceSeparator is non-NULL it creates a parser with michael@0: namespace processing as described above. The character pointed at michael@0: will serve as the namespace separator. michael@0: michael@0: All further memory operations used for the created parser will come from michael@0: the given suite. michael@0: */ michael@0: XMLPARSEAPI(XML_Parser) michael@0: XML_ParserCreate_MM(const XML_Char *encoding, michael@0: const XML_Memory_Handling_Suite *memsuite, michael@0: const XML_Char *namespaceSeparator); michael@0: michael@0: /* Prepare a parser object to be re-used. This is particularly michael@0: valuable when memory allocation overhead is disproportionatly high, michael@0: such as when a large number of small documnents need to be parsed. michael@0: All handlers are cleared from the parser, except for the michael@0: unknownEncodingHandler. The parser's external state is re-initialized michael@0: except for the values of ns and ns_triplets. michael@0: michael@0: Added in Expat 1.95.3. michael@0: */ michael@0: XMLPARSEAPI(XML_Bool) michael@0: XML_ParserReset(XML_Parser parser, const XML_Char *encoding); michael@0: michael@0: /* atts is array of name/value pairs, terminated by 0; michael@0: names and values are 0 terminated. michael@0: */ michael@0: typedef void (XMLCALL *XML_StartElementHandler) (void *userData, michael@0: const XML_Char *name, michael@0: const XML_Char **atts); michael@0: michael@0: typedef void (XMLCALL *XML_EndElementHandler) (void *userData, michael@0: const XML_Char *name); michael@0: michael@0: michael@0: /* s is not 0 terminated. */ michael@0: typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, michael@0: const XML_Char *s, michael@0: int len); michael@0: michael@0: /* target and data are 0 terminated */ michael@0: typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( michael@0: void *userData, michael@0: const XML_Char *target, michael@0: const XML_Char *data); michael@0: michael@0: /* data is 0 terminated */ michael@0: typedef void (XMLCALL *XML_CommentHandler) (void *userData, michael@0: const XML_Char *data); michael@0: michael@0: typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); michael@0: typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); michael@0: michael@0: /* This is called for any characters in the XML document for which michael@0: there is no applicable handler. This includes both characters that michael@0: are part of markup which is of a kind that is not reported michael@0: (comments, markup declarations), or characters that are part of a michael@0: construct which could be reported but for which no handler has been michael@0: supplied. The characters are passed exactly as they were in the XML michael@0: document except that they will be encoded in UTF-8 or UTF-16. michael@0: Line boundaries are not normalized. Note that a byte order mark michael@0: character is not passed to the default handler. There are no michael@0: guarantees about how characters are divided between calls to the michael@0: default handler: for example, a comment might be split between michael@0: multiple calls. michael@0: */ michael@0: typedef void (XMLCALL *XML_DefaultHandler) (void *userData, michael@0: const XML_Char *s, michael@0: int len); michael@0: michael@0: /* This is called for the start of the DOCTYPE declaration, before michael@0: any DTD or internal subset is parsed. michael@0: */ michael@0: typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *doctypeName, michael@0: const XML_Char *sysid, michael@0: const XML_Char *pubid, michael@0: int has_internal_subset); michael@0: michael@0: /* This is called for the start of the DOCTYPE declaration when the michael@0: closing > is encountered, but after processing any external michael@0: subset. michael@0: */ michael@0: typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); michael@0: michael@0: /* This is called for entity declarations. The is_parameter_entity michael@0: argument will be non-zero if the entity is a parameter entity, zero michael@0: otherwise. michael@0: michael@0: For internal entities (), value will michael@0: be non-NULL and systemId, publicID, and notationName will be NULL. michael@0: The value string is NOT nul-terminated; the length is provided in michael@0: the value_length argument. Since it is legal to have zero-length michael@0: values, do not use this argument to test for internal entities. michael@0: michael@0: For external entities, value will be NULL and systemId will be michael@0: non-NULL. The publicId argument will be NULL unless a public michael@0: identifier was provided. The notationName argument will have a michael@0: non-NULL value only for unparsed entity declarations. michael@0: michael@0: Note that is_parameter_entity can't be changed to XML_Bool, since michael@0: that would break binary compatibility. michael@0: */ michael@0: typedef void (XMLCALL *XML_EntityDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *entityName, michael@0: int is_parameter_entity, michael@0: const XML_Char *value, michael@0: int value_length, michael@0: const XML_Char *base, michael@0: const XML_Char *systemId, michael@0: const XML_Char *publicId, michael@0: const XML_Char *notationName); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetEntityDeclHandler(XML_Parser parser, michael@0: XML_EntityDeclHandler handler); michael@0: michael@0: /* OBSOLETE -- OBSOLETE -- OBSOLETE michael@0: This handler has been superseded by the EntityDeclHandler above. michael@0: It is provided here for backward compatibility. michael@0: michael@0: This is called for a declaration of an unparsed (NDATA) entity. michael@0: The base argument is whatever was set by XML_SetBase. The michael@0: entityName, systemId and notationName arguments will never be michael@0: NULL. The other arguments may be. michael@0: */ michael@0: typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *entityName, michael@0: const XML_Char *base, michael@0: const XML_Char *systemId, michael@0: const XML_Char *publicId, michael@0: const XML_Char *notationName); michael@0: michael@0: /* This is called for a declaration of notation. The base argument is michael@0: whatever was set by XML_SetBase. The notationName will never be michael@0: NULL. The other arguments can be. michael@0: */ michael@0: typedef void (XMLCALL *XML_NotationDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *notationName, michael@0: const XML_Char *base, michael@0: const XML_Char *systemId, michael@0: const XML_Char *publicId); michael@0: michael@0: /* When namespace processing is enabled, these are called once for michael@0: each namespace declaration. The call to the start and end element michael@0: handlers occur between the calls to the start and end namespace michael@0: declaration handlers. For an xmlns attribute, prefix will be michael@0: NULL. For an xmlns="" attribute, uri will be NULL. michael@0: */ michael@0: typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *prefix, michael@0: const XML_Char *uri); michael@0: michael@0: typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( michael@0: void *userData, michael@0: const XML_Char *prefix); michael@0: michael@0: /* This is called if the document is not standalone, that is, it has an michael@0: external subset or a reference to a parameter entity, but does not michael@0: have standalone="yes". If this handler returns XML_STATUS_ERROR, michael@0: then processing will not continue, and the parser will return a michael@0: XML_ERROR_NOT_STANDALONE error. michael@0: If parameter entity parsing is enabled, then in addition to the michael@0: conditions above this handler will only be called if the referenced michael@0: entity was actually read. michael@0: */ michael@0: typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); michael@0: michael@0: /* This is called for a reference to an external parsed general michael@0: entity. The referenced entity is not automatically parsed. The michael@0: application can parse it immediately or later using michael@0: XML_ExternalEntityParserCreate. michael@0: michael@0: The parser argument is the parser parsing the entity containing the michael@0: reference; it can be passed as the parser argument to michael@0: XML_ExternalEntityParserCreate. The systemId argument is the michael@0: system identifier as specified in the entity declaration; it will michael@0: not be NULL. michael@0: michael@0: The base argument is the system identifier that should be used as michael@0: the base for resolving systemId if systemId was relative; this is michael@0: set by XML_SetBase; it may be NULL. michael@0: michael@0: The publicId argument is the public identifier as specified in the michael@0: entity declaration, or NULL if none was specified; the whitespace michael@0: in the public identifier will have been normalized as required by michael@0: the XML spec. michael@0: michael@0: The context argument specifies the parsing context in the format michael@0: expected by the context argument to XML_ExternalEntityParserCreate; michael@0: context is valid only until the handler returns, so if the michael@0: referenced entity is to be parsed later, it must be copied. michael@0: context is NULL only when the entity is a parameter entity. michael@0: michael@0: The handler should return XML_STATUS_ERROR if processing should not michael@0: continue because of a fatal error in the handling of the external michael@0: entity. In this case the calling parser will return an michael@0: XML_ERROR_EXTERNAL_ENTITY_HANDLING error. michael@0: michael@0: Note that unlike other handlers the first argument is the parser, michael@0: not userData. michael@0: */ michael@0: typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( michael@0: XML_Parser parser, michael@0: const XML_Char *context, michael@0: const XML_Char *base, michael@0: const XML_Char *systemId, michael@0: const XML_Char *publicId); michael@0: michael@0: /* This is called in two situations: michael@0: 1) An entity reference is encountered for which no declaration michael@0: has been read *and* this is not an error. michael@0: 2) An internal entity reference is read, but not expanded, because michael@0: XML_SetDefaultHandler has been called. michael@0: Note: skipped parameter entities in declarations and skipped general michael@0: entities in attribute values cannot be reported, because michael@0: the event would be out of sync with the reporting of the michael@0: declarations or attribute values michael@0: */ michael@0: typedef void (XMLCALL *XML_SkippedEntityHandler) ( michael@0: void *userData, michael@0: const XML_Char *entityName, michael@0: int is_parameter_entity); michael@0: michael@0: /* This structure is filled in by the XML_UnknownEncodingHandler to michael@0: provide information to the parser about encodings that are unknown michael@0: to the parser. michael@0: michael@0: The map[b] member gives information about byte sequences whose michael@0: first byte is b. michael@0: michael@0: If map[b] is c where c is >= 0, then b by itself encodes the michael@0: Unicode scalar value c. michael@0: michael@0: If map[b] is -1, then the byte sequence is malformed. michael@0: michael@0: If map[b] is -n, where n >= 2, then b is the first byte of an michael@0: n-byte sequence that encodes a single Unicode scalar value. michael@0: michael@0: The data member will be passed as the first argument to the convert michael@0: function. michael@0: michael@0: The convert function is used to convert multibyte sequences; s will michael@0: point to a n-byte sequence where map[(unsigned char)*s] == -n. The michael@0: convert function must return the Unicode scalar value represented michael@0: by this byte sequence or -1 if the byte sequence is malformed. michael@0: michael@0: The convert function may be NULL if the encoding is a single-byte michael@0: encoding, that is if map[b] >= -1 for all bytes b. michael@0: michael@0: When the parser is finished with the encoding, then if release is michael@0: not NULL, it will call release passing it the data member; once michael@0: release has been called, the convert function will not be called michael@0: again. michael@0: michael@0: Expat places certain restrictions on the encodings that are supported michael@0: using this mechanism. michael@0: michael@0: 1. Every ASCII character that can appear in a well-formed XML document, michael@0: other than the characters michael@0: michael@0: $@\^`{}~ michael@0: michael@0: must be represented by a single byte, and that byte must be the michael@0: same byte that represents that character in ASCII. michael@0: michael@0: 2. No character may require more than 4 bytes to encode. michael@0: michael@0: 3. All characters encoded must have Unicode scalar values <= michael@0: 0xFFFF, (i.e., characters that would be encoded by surrogates in michael@0: UTF-16 are not allowed). Note that this restriction doesn't michael@0: apply to the built-in support for UTF-8 and UTF-16. michael@0: michael@0: 4. No Unicode character may be encoded by more than one distinct michael@0: sequence of bytes. michael@0: */ michael@0: typedef struct { michael@0: int map[256]; michael@0: void *data; michael@0: int (XMLCALL *convert)(void *data, const char *s); michael@0: void (XMLCALL *release)(void *data); michael@0: } XML_Encoding; michael@0: michael@0: /* This is called for an encoding that is unknown to the parser. michael@0: michael@0: The encodingHandlerData argument is that which was passed as the michael@0: second argument to XML_SetUnknownEncodingHandler. michael@0: michael@0: The name argument gives the name of the encoding as specified in michael@0: the encoding declaration. michael@0: michael@0: If the callback can provide information about the encoding, it must michael@0: fill in the XML_Encoding structure, and return XML_STATUS_OK. michael@0: Otherwise it must return XML_STATUS_ERROR. michael@0: michael@0: If info does not describe a suitable encoding, then the parser will michael@0: return an XML_UNKNOWN_ENCODING error. michael@0: */ michael@0: typedef int (XMLCALL *XML_UnknownEncodingHandler) ( michael@0: void *encodingHandlerData, michael@0: const XML_Char *name, michael@0: XML_Encoding *info); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetElementHandler(XML_Parser parser, michael@0: XML_StartElementHandler start, michael@0: XML_EndElementHandler end); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetStartElementHandler(XML_Parser parser, michael@0: XML_StartElementHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetEndElementHandler(XML_Parser parser, michael@0: XML_EndElementHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetCharacterDataHandler(XML_Parser parser, michael@0: XML_CharacterDataHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetProcessingInstructionHandler(XML_Parser parser, michael@0: XML_ProcessingInstructionHandler handler); michael@0: XMLPARSEAPI(void) michael@0: XML_SetCommentHandler(XML_Parser parser, michael@0: XML_CommentHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetCdataSectionHandler(XML_Parser parser, michael@0: XML_StartCdataSectionHandler start, michael@0: XML_EndCdataSectionHandler end); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetStartCdataSectionHandler(XML_Parser parser, michael@0: XML_StartCdataSectionHandler start); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetEndCdataSectionHandler(XML_Parser parser, michael@0: XML_EndCdataSectionHandler end); michael@0: michael@0: /* This sets the default handler and also inhibits expansion of michael@0: internal entities. These entity references will be passed to the michael@0: default handler, or to the skipped entity handler, if one is set. michael@0: */ michael@0: XMLPARSEAPI(void) michael@0: XML_SetDefaultHandler(XML_Parser parser, michael@0: XML_DefaultHandler handler); michael@0: michael@0: /* This sets the default handler but does not inhibit expansion of michael@0: internal entities. The entity reference will not be passed to the michael@0: default handler. michael@0: */ michael@0: XMLPARSEAPI(void) michael@0: XML_SetDefaultHandlerExpand(XML_Parser parser, michael@0: XML_DefaultHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetDoctypeDeclHandler(XML_Parser parser, michael@0: XML_StartDoctypeDeclHandler start, michael@0: XML_EndDoctypeDeclHandler end); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetStartDoctypeDeclHandler(XML_Parser parser, michael@0: XML_StartDoctypeDeclHandler start); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetEndDoctypeDeclHandler(XML_Parser parser, michael@0: XML_EndDoctypeDeclHandler end); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetUnparsedEntityDeclHandler(XML_Parser parser, michael@0: XML_UnparsedEntityDeclHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetNotationDeclHandler(XML_Parser parser, michael@0: XML_NotationDeclHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetNamespaceDeclHandler(XML_Parser parser, michael@0: XML_StartNamespaceDeclHandler start, michael@0: XML_EndNamespaceDeclHandler end); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetStartNamespaceDeclHandler(XML_Parser parser, michael@0: XML_StartNamespaceDeclHandler start); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetEndNamespaceDeclHandler(XML_Parser parser, michael@0: XML_EndNamespaceDeclHandler end); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetNotStandaloneHandler(XML_Parser parser, michael@0: XML_NotStandaloneHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetExternalEntityRefHandler(XML_Parser parser, michael@0: XML_ExternalEntityRefHandler handler); michael@0: michael@0: /* If a non-NULL value for arg is specified here, then it will be michael@0: passed as the first argument to the external entity ref handler michael@0: instead of the parser object. michael@0: */ michael@0: XMLPARSEAPI(void) michael@0: XML_SetExternalEntityRefHandlerArg(XML_Parser parser, michael@0: void *arg); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetSkippedEntityHandler(XML_Parser parser, michael@0: XML_SkippedEntityHandler handler); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetUnknownEncodingHandler(XML_Parser parser, michael@0: XML_UnknownEncodingHandler handler, michael@0: void *encodingHandlerData); michael@0: michael@0: /* This can be called within a handler for a start element, end michael@0: element, processing instruction or character data. It causes the michael@0: corresponding markup to be passed to the default handler. michael@0: */ michael@0: XMLPARSEAPI(void) michael@0: XML_DefaultCurrent(XML_Parser parser); michael@0: michael@0: /* If do_nst is non-zero, and namespace processing is in effect, and michael@0: a name has a prefix (i.e. an explicit namespace qualifier) then michael@0: that name is returned as a triplet in a single string separated by michael@0: the separator character specified when the parser was created: URI michael@0: + sep + local_name + sep + prefix. michael@0: michael@0: If do_nst is zero, then namespace information is returned in the michael@0: default manner (URI + sep + local_name) whether or not the name michael@0: has a prefix. michael@0: michael@0: Note: Calling XML_SetReturnNSTriplet after XML_Parse or michael@0: XML_ParseBuffer has no effect. michael@0: */ michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); michael@0: michael@0: /* This value is passed as the userData argument to callbacks. */ michael@0: XMLPARSEAPI(void) michael@0: XML_SetUserData(XML_Parser parser, void *userData); michael@0: michael@0: /* Returns the last value set by XML_SetUserData or NULL. */ michael@0: #define XML_GetUserData(parser) (*(void **)(parser)) michael@0: michael@0: /* This is equivalent to supplying an encoding argument to michael@0: XML_ParserCreate. On success XML_SetEncoding returns non-zero, michael@0: zero otherwise. michael@0: Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer michael@0: has no effect and returns XML_STATUS_ERROR. michael@0: */ michael@0: XMLPARSEAPI(enum XML_Status) michael@0: XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); michael@0: michael@0: /* If this function is called, then the parser will be passed as the michael@0: first argument to callbacks instead of userData. The userData will michael@0: still be accessible using XML_GetUserData. michael@0: */ michael@0: XMLPARSEAPI(void) michael@0: XML_UseParserAsHandlerArg(XML_Parser parser); michael@0: michael@0: /* If useDTD == XML_TRUE is passed to this function, then the parser michael@0: will assume that there is an external subset, even if none is michael@0: specified in the document. In such a case the parser will call the michael@0: externalEntityRefHandler with a value of NULL for the systemId michael@0: argument (the publicId and context arguments will be NULL as well). michael@0: Note: For the purpose of checking WFC: Entity Declared, passing michael@0: useDTD == XML_TRUE will make the parser behave as if the document michael@0: had a DTD with an external subset. michael@0: Note: If this function is called, then this must be done before michael@0: the first call to XML_Parse or XML_ParseBuffer, since it will michael@0: have no effect after that. Returns michael@0: XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. michael@0: Note: If the document does not have a DOCTYPE declaration at all, michael@0: then startDoctypeDeclHandler and endDoctypeDeclHandler will not michael@0: be called, despite an external subset being parsed. michael@0: Note: If XML_DTD is not defined when Expat is compiled, returns michael@0: XML_ERROR_FEATURE_REQUIRES_XML_DTD. michael@0: */ michael@0: XMLPARSEAPI(enum XML_Error) michael@0: XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); michael@0: michael@0: michael@0: /* Sets the base to be used for resolving relative URIs in system michael@0: identifiers in declarations. Resolving relative identifiers is michael@0: left to the application: this value will be passed through as the michael@0: base argument to the XML_ExternalEntityRefHandler, michael@0: XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base michael@0: argument will be copied. Returns XML_STATUS_ERROR if out of memory, michael@0: XML_STATUS_OK otherwise. michael@0: */ michael@0: XMLPARSEAPI(enum XML_Status) michael@0: XML_SetBase(XML_Parser parser, const XML_Char *base); michael@0: michael@0: XMLPARSEAPI(const XML_Char *) michael@0: XML_GetBase(XML_Parser parser); michael@0: michael@0: /* Returns the number of the attribute/value pairs passed in last call michael@0: to the XML_StartElementHandler that were specified in the start-tag michael@0: rather than defaulted. Each attribute/value pair counts as 2; thus michael@0: this correspondds to an index into the atts array passed to the michael@0: XML_StartElementHandler. michael@0: */ michael@0: XMLPARSEAPI(int) michael@0: XML_GetSpecifiedAttributeCount(XML_Parser parser); michael@0: michael@0: /* Returns the index of the ID attribute passed in the last call to michael@0: XML_StartElementHandler, or -1 if there is no ID attribute. Each michael@0: attribute/value pair counts as 2; thus this correspondds to an michael@0: index into the atts array passed to the XML_StartElementHandler. michael@0: */ michael@0: XMLPARSEAPI(int) michael@0: XML_GetIdAttributeIndex(XML_Parser parser); michael@0: michael@0: /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is michael@0: detected. The last call to XML_Parse must have isFinal true; len michael@0: may be zero for this call (or any other). michael@0: michael@0: Though the return values for these functions has always been michael@0: described as a Boolean value, the implementation, at least for the michael@0: 1.95.x series, has always returned exactly one of the XML_Status michael@0: values. michael@0: */ michael@0: XMLPARSEAPI(enum XML_Status) michael@0: XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); michael@0: michael@0: XMLPARSEAPI(void *) michael@0: XML_GetBuffer(XML_Parser parser, int len); michael@0: michael@0: XMLPARSEAPI(enum XML_Status) michael@0: XML_ParseBuffer(XML_Parser parser, int len, int isFinal); michael@0: michael@0: /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. michael@0: Must be called from within a call-back handler, except when aborting michael@0: (resumable = 0) an already suspended parser. Some call-backs may michael@0: still follow because they would otherwise get lost. Examples: michael@0: - endElementHandler() for empty elements when stopped in michael@0: startElementHandler(), michael@0: - endNameSpaceDeclHandler() when stopped in endElementHandler(), michael@0: and possibly others. michael@0: michael@0: Can be called from most handlers, including DTD related call-backs, michael@0: except when parsing an external parameter entity and resumable != 0. michael@0: Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. michael@0: Possible error codes: michael@0: - XML_ERROR_SUSPENDED: when suspending an already suspended parser. michael@0: - XML_ERROR_FINISHED: when the parser has already finished. michael@0: - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. michael@0: michael@0: When resumable != 0 (true) then parsing is suspended, that is, michael@0: XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. michael@0: Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() michael@0: return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. michael@0: michael@0: *Note*: michael@0: This will be applied to the current parser instance only, that is, if michael@0: there is a parent parser then it will continue parsing when the michael@0: externalEntityRefHandler() returns. It is up to the implementation of michael@0: the externalEntityRefHandler() to call XML_StopParser() on the parent michael@0: parser (recursively), if one wants to stop parsing altogether. michael@0: michael@0: When suspended, parsing can be resumed by calling XML_ResumeParser(). michael@0: */ michael@0: XMLPARSEAPI(enum XML_Status) michael@0: XML_StopParser(XML_Parser parser, XML_Bool resumable); michael@0: michael@0: /* Resumes parsing after it has been suspended with XML_StopParser(). michael@0: Must not be called from within a handler call-back. Returns same michael@0: status codes as XML_Parse() or XML_ParseBuffer(). michael@0: Additional error code XML_ERROR_NOT_SUSPENDED possible. michael@0: michael@0: *Note*: michael@0: This must be called on the most deeply nested child parser instance michael@0: first, and on its parent parser only after the child parser has finished, michael@0: to be applied recursively until the document entity's parser is restarted. michael@0: That is, the parent parser will not resume by itself and it is up to the michael@0: application to call XML_ResumeParser() on it at the appropriate moment. michael@0: */ michael@0: XMLPARSEAPI(enum XML_Status) michael@0: XML_ResumeParser(XML_Parser parser); michael@0: michael@0: enum XML_Parsing { michael@0: XML_INITIALIZED, michael@0: XML_PARSING, michael@0: XML_FINISHED, michael@0: XML_SUSPENDED michael@0: }; michael@0: michael@0: typedef struct { michael@0: enum XML_Parsing parsing; michael@0: XML_Bool finalBuffer; michael@0: } XML_ParsingStatus; michael@0: michael@0: /* Returns status of parser with respect to being initialized, parsing, michael@0: finished, or suspended and processing the final buffer. michael@0: XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, michael@0: XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED michael@0: */ michael@0: XMLPARSEAPI(void) michael@0: XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); michael@0: michael@0: /* Creates an XML_Parser object that can parse an external general michael@0: entity; context is a '\0'-terminated string specifying the parse michael@0: context; encoding is a '\0'-terminated string giving the name of michael@0: the externally specified encoding, or NULL if there is no michael@0: externally specified encoding. The context string consists of a michael@0: sequence of tokens separated by formfeeds (\f); a token consisting michael@0: of a name specifies that the general entity of the name is open; a michael@0: token of the form prefix=uri specifies the namespace for a michael@0: particular prefix; a token of the form =uri specifies the default michael@0: namespace. This can be called at any point after the first call to michael@0: an ExternalEntityRefHandler so longer as the parser has not yet michael@0: been freed. The new parser is completely independent and may michael@0: safely be used in a separate thread. The handlers and userData are michael@0: initialized from the parser argument. Returns NULL if out of memory. michael@0: Otherwise returns a new XML_Parser object. michael@0: */ michael@0: XMLPARSEAPI(XML_Parser) michael@0: XML_ExternalEntityParserCreate(XML_Parser parser, michael@0: const XML_Char *context, michael@0: const XML_Char *encoding); michael@0: michael@0: enum XML_ParamEntityParsing { michael@0: XML_PARAM_ENTITY_PARSING_NEVER, michael@0: XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, michael@0: XML_PARAM_ENTITY_PARSING_ALWAYS michael@0: }; michael@0: michael@0: /* Controls parsing of parameter entities (including the external DTD michael@0: subset). If parsing of parameter entities is enabled, then michael@0: references to external parameter entities (including the external michael@0: DTD subset) will be passed to the handler set with michael@0: XML_SetExternalEntityRefHandler. The context passed will be 0. michael@0: michael@0: Unlike external general entities, external parameter entities can michael@0: only be parsed synchronously. If the external parameter entity is michael@0: to be parsed, it must be parsed during the call to the external michael@0: entity ref handler: the complete sequence of michael@0: XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and michael@0: XML_ParserFree calls must be made during this call. After michael@0: XML_ExternalEntityParserCreate has been called to create the parser michael@0: for the external parameter entity (context must be 0 for this michael@0: call), it is illegal to make any calls on the old parser until michael@0: XML_ParserFree has been called on the newly created parser. michael@0: If the library has been compiled without support for parameter michael@0: entity parsing (ie without XML_DTD being defined), then michael@0: XML_SetParamEntityParsing will return 0 if parsing of parameter michael@0: entities is requested; otherwise it will return non-zero. michael@0: Note: If XML_SetParamEntityParsing is called after XML_Parse or michael@0: XML_ParseBuffer, then it has no effect and will always return 0. michael@0: */ michael@0: XMLPARSEAPI(int) michael@0: XML_SetParamEntityParsing(XML_Parser parser, michael@0: enum XML_ParamEntityParsing parsing); michael@0: michael@0: /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then michael@0: XML_GetErrorCode returns information about the error. michael@0: */ michael@0: XMLPARSEAPI(enum XML_Error) michael@0: XML_GetErrorCode(XML_Parser parser); michael@0: michael@0: /* These functions return information about the current parse michael@0: location. They may be called from any callback called to report michael@0: some parse event; in this case the location is the location of the michael@0: first of the sequence of characters that generated the event. When michael@0: called from callbacks generated by declarations in the document michael@0: prologue, the location identified isn't as neatly defined, but will michael@0: be within the relevant markup. When called outside of the callback michael@0: functions, the position indicated will be just past the last parse michael@0: event (regardless of whether there was an associated callback). michael@0: michael@0: They may also be called after returning from a call to XML_Parse michael@0: or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then michael@0: the location is the location of the character at which the error michael@0: was detected; otherwise the location is the location of the last michael@0: parse event, as described above. michael@0: */ michael@0: XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); michael@0: XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); michael@0: XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); michael@0: michael@0: /* Return the number of bytes in the current event. michael@0: Returns 0 if the event is in an internal entity. michael@0: */ michael@0: XMLPARSEAPI(int) michael@0: XML_GetCurrentByteCount(XML_Parser parser); michael@0: michael@0: /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets michael@0: the integer pointed to by offset to the offset within this buffer michael@0: of the current parse position, and sets the integer pointed to by size michael@0: to the size of this buffer (the number of input bytes). Otherwise michael@0: returns a NULL pointer. Also returns a NULL pointer if a parse isn't michael@0: active. michael@0: michael@0: NOTE: The character pointer returned should not be used outside michael@0: the handler that makes the call. michael@0: */ michael@0: XMLPARSEAPI(const char *) michael@0: XML_GetInputContext(XML_Parser parser, michael@0: int *offset, michael@0: int *size); michael@0: michael@0: /* For backwards compatibility with previous versions. */ michael@0: #define XML_GetErrorLineNumber XML_GetCurrentLineNumber michael@0: #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber michael@0: #define XML_GetErrorByteIndex XML_GetCurrentByteIndex michael@0: michael@0: /* Frees the content model passed to the element declaration handler */ michael@0: XMLPARSEAPI(void) michael@0: XML_FreeContentModel(XML_Parser parser, XML_Content *model); michael@0: michael@0: /* Exposing the memory handling functions used in Expat */ michael@0: XMLPARSEAPI(void *) michael@0: XML_MemMalloc(XML_Parser parser, size_t size); michael@0: michael@0: XMLPARSEAPI(void *) michael@0: XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); michael@0: michael@0: XMLPARSEAPI(void) michael@0: XML_MemFree(XML_Parser parser, void *ptr); michael@0: michael@0: /* Frees memory used by the parser. */ michael@0: XMLPARSEAPI(void) michael@0: XML_ParserFree(XML_Parser parser); michael@0: michael@0: /* Returns a string describing the error. */ michael@0: XMLPARSEAPI(const XML_LChar *) michael@0: XML_ErrorString(enum XML_Error code); michael@0: michael@0: /* Return a string containing the version number of this expat */ michael@0: XMLPARSEAPI(const XML_LChar *) michael@0: XML_ExpatVersion(void); michael@0: michael@0: typedef struct { michael@0: int major; michael@0: int minor; michael@0: int micro; michael@0: } XML_Expat_Version; michael@0: michael@0: /* Return an XML_Expat_Version structure containing numeric version michael@0: number information for this version of expat. michael@0: */ michael@0: XMLPARSEAPI(XML_Expat_Version) michael@0: XML_ExpatVersionInfo(void); michael@0: michael@0: /* Added in Expat 1.95.5. */ michael@0: enum XML_FeatureEnum { michael@0: XML_FEATURE_END = 0, michael@0: XML_FEATURE_UNICODE, michael@0: XML_FEATURE_UNICODE_WCHAR_T, michael@0: XML_FEATURE_DTD, michael@0: XML_FEATURE_CONTEXT_BYTES, michael@0: XML_FEATURE_MIN_SIZE, michael@0: XML_FEATURE_SIZEOF_XML_CHAR, michael@0: XML_FEATURE_SIZEOF_XML_LCHAR, michael@0: XML_FEATURE_NS michael@0: /* Additional features must be added to the end of this enum. */ michael@0: }; michael@0: michael@0: typedef struct { michael@0: enum XML_FeatureEnum feature; michael@0: const XML_LChar *name; michael@0: long int value; michael@0: } XML_Feature; michael@0: michael@0: XMLPARSEAPI(const XML_Feature *) michael@0: XML_GetFeatureList(void); michael@0: michael@0: michael@0: /* Expat follows the GNU/Linux convention of odd number minor version for michael@0: beta/development releases and even number minor version for stable michael@0: releases. Micro is bumped with each release, and set to 0 with each michael@0: change to major or minor version. michael@0: */ michael@0: #define XML_MAJOR_VERSION 2 michael@0: #define XML_MINOR_VERSION 0 michael@0: #define XML_MICRO_VERSION 0 michael@0: michael@0: /* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */ michael@0: XMLPARSEAPI(const XML_Char*) michael@0: MOZ_XML_GetMismatchedTag(XML_Parser parser); michael@0: /* END MOZILLA CHANGE */ michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif /* not Expat_INCLUDED */