blob: 06b5de0f44627bdf5e6dcac12cad0accbe343cfa [file] [log] [blame]
Martin v. Löwisfc03a942003-01-25 22:41:29 +00001/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
Martin v. Löwisb48d1982002-02-12 09:52:22 +00003*/
4
Thomas Wouters0e3f5912006-08-11 14:57:12 +00005#ifndef Expat_INCLUDED
6#define Expat_INCLUDED 1
Martin v. Löwisb48d1982002-02-12 09:52:22 +00007
Martin v. Löwisfc03a942003-01-25 22:41:29 +00008#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
Martin v. Löwisb48d1982002-02-12 09:52:22 +000017#include <stdlib.h>
Fred Drake31d485c2004-08-03 07:06:22 +000018#include "expat_external.h"
Martin v. Löwisb48d1982002-02-12 09:52:22 +000019
Thomas Wouters0e3f5912006-08-11 14:57:12 +000020#ifdef __cplusplus
21extern "C" {
22#endif
23
Martin v. Löwisfc03a942003-01-25 22:41:29 +000024struct XML_ParserStruct;
25typedef struct XML_ParserStruct *XML_Parser;
26
Martin v. Löwisfc03a942003-01-25 22:41:29 +000027/* Should this be defined using stdbool.h when C99 is available? */
28typedef unsigned char XML_Bool;
29#define XML_TRUE ((XML_Bool) 1)
30#define XML_FALSE ((XML_Bool) 0)
31
Fred Drakedab8b0a2003-02-07 02:15:56 +000032/* The XML_Status enum gives the possible return values for several
33 API functions. The preprocessor #defines are included so this
34 stanza can be added to code that still needs to support older
35 versions of Expat 1.95.x:
36
37 #ifndef XML_STATUS_OK
38 #define XML_STATUS_OK 1
39 #define XML_STATUS_ERROR 0
40 #endif
41
42 Otherwise, the #define hackery is quite ugly and would have been
43 dropped.
44*/
45enum XML_Status {
46 XML_STATUS_ERROR = 0,
47#define XML_STATUS_ERROR XML_STATUS_ERROR
Fred Drake31d485c2004-08-03 07:06:22 +000048 XML_STATUS_OK = 1,
Fred Drakedab8b0a2003-02-07 02:15:56 +000049#define XML_STATUS_OK XML_STATUS_OK
Georg Brandle810fe22006-02-19 15:28:47 +000050 XML_STATUS_SUSPENDED = 2
Fred Drake31d485c2004-08-03 07:06:22 +000051#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
Fred Drakedab8b0a2003-02-07 02:15:56 +000052};
53
Martin v. Löwisfc03a942003-01-25 22:41:29 +000054enum XML_Error {
55 XML_ERROR_NONE,
56 XML_ERROR_NO_MEMORY,
57 XML_ERROR_SYNTAX,
58 XML_ERROR_NO_ELEMENTS,
59 XML_ERROR_INVALID_TOKEN,
60 XML_ERROR_UNCLOSED_TOKEN,
61 XML_ERROR_PARTIAL_CHAR,
62 XML_ERROR_TAG_MISMATCH,
63 XML_ERROR_DUPLICATE_ATTRIBUTE,
64 XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
65 XML_ERROR_PARAM_ENTITY_REF,
66 XML_ERROR_UNDEFINED_ENTITY,
67 XML_ERROR_RECURSIVE_ENTITY_REF,
68 XML_ERROR_ASYNC_ENTITY,
69 XML_ERROR_BAD_CHAR_REF,
70 XML_ERROR_BINARY_ENTITY_REF,
71 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
72 XML_ERROR_MISPLACED_XML_PI,
73 XML_ERROR_UNKNOWN_ENCODING,
74 XML_ERROR_INCORRECT_ENCODING,
75 XML_ERROR_UNCLOSED_CDATA_SECTION,
76 XML_ERROR_EXTERNAL_ENTITY_HANDLING,
77 XML_ERROR_NOT_STANDALONE,
78 XML_ERROR_UNEXPECTED_STATE,
79 XML_ERROR_ENTITY_DECLARED_IN_PE,
80 XML_ERROR_FEATURE_REQUIRES_XML_DTD,
Fred Drake08317ae2003-10-21 15:38:55 +000081 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
Fred Drake31d485c2004-08-03 07:06:22 +000082 /* Added in 1.95.7. */
83 XML_ERROR_UNBOUND_PREFIX,
84 /* Added in 1.95.8. */
85 XML_ERROR_UNDECLARING_PREFIX,
86 XML_ERROR_INCOMPLETE_PE,
87 XML_ERROR_XML_DECL,
88 XML_ERROR_TEXT_DECL,
89 XML_ERROR_PUBLICID,
90 XML_ERROR_SUSPENDED,
91 XML_ERROR_NOT_SUSPENDED,
92 XML_ERROR_ABORTED,
93 XML_ERROR_FINISHED,
Thomas Wouters0e3f5912006-08-11 14:57:12 +000094 XML_ERROR_SUSPEND_PE,
95 /* Added in 2.0. */
96 XML_ERROR_RESERVED_PREFIX_XML,
97 XML_ERROR_RESERVED_PREFIX_XMLNS,
98 XML_ERROR_RESERVED_NAMESPACE_URI
Martin v. Löwisfc03a942003-01-25 22:41:29 +000099};
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000100
101enum XML_Content_Type {
102 XML_CTYPE_EMPTY = 1,
103 XML_CTYPE_ANY,
104 XML_CTYPE_MIXED,
105 XML_CTYPE_NAME,
106 XML_CTYPE_CHOICE,
107 XML_CTYPE_SEQ
108};
109
110enum XML_Content_Quant {
111 XML_CQUANT_NONE,
112 XML_CQUANT_OPT,
113 XML_CQUANT_REP,
114 XML_CQUANT_PLUS
115};
116
117/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
118 XML_CQUANT_NONE, and the other fields will be zero or NULL.
119 If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
120 numchildren will contain number of elements that may be mixed in
121 and children point to an array of XML_Content cells that will be
122 all of XML_CTYPE_NAME type with no quantification.
123
124 If type == XML_CTYPE_NAME, then the name points to the name, and
125 the numchildren field will be zero and children will be NULL. The
126 quant fields indicates any quantifiers placed on the name.
127
128 CHOICE and SEQ will have name NULL, the number of children in
129 numchildren and children will point, recursively, to an array
130 of XML_Content cells.
131
132 The EMPTY, ANY, and MIXED types will only occur at top level.
133*/
134
135typedef struct XML_cp XML_Content;
136
137struct XML_cp {
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000138 enum XML_Content_Type type;
139 enum XML_Content_Quant quant;
140 XML_Char * name;
141 unsigned int numchildren;
142 XML_Content * children;
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000143};
144
145
146/* This is called for an element declaration. See above for
147 description of the model argument. It's the caller's responsibility
148 to free model when finished with it.
149*/
Fred Drake08317ae2003-10-21 15:38:55 +0000150typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
151 const XML_Char *name,
152 XML_Content *model);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000153
154XMLPARSEAPI(void)
155XML_SetElementDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000156 XML_ElementDeclHandler eldecl);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000157
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000158/* The Attlist declaration handler is called for *each* attribute. So
159 a single Attlist declaration with multiple attributes declared will
160 generate multiple calls to this handler. The "default" parameter
161 may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
162 keyword. The "isrequired" parameter will be true and the default
163 value will be NULL in the case of "#REQUIRED". If "isrequired" is
164 true and default is non-NULL, then this is a "#FIXED" default.
165*/
Fred Drake08317ae2003-10-21 15:38:55 +0000166typedef void (XMLCALL *XML_AttlistDeclHandler) (
167 void *userData,
168 const XML_Char *elname,
169 const XML_Char *attname,
170 const XML_Char *att_type,
171 const XML_Char *dflt,
172 int isrequired);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000173
174XMLPARSEAPI(void)
175XML_SetAttlistDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000176 XML_AttlistDeclHandler attdecl);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000177
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000178/* The XML declaration handler is called for *both* XML declarations
179 and text declarations. The way to distinguish is that the version
180 parameter will be NULL for text declarations. The encoding
181 parameter may be NULL for XML declarations. The standalone
182 parameter will be -1, 0, or 1 indicating respectively that there
183 was no standalone parameter in the declaration, that it was given
184 as no, or that it was given as yes.
185*/
Fred Drake08317ae2003-10-21 15:38:55 +0000186typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData,
187 const XML_Char *version,
188 const XML_Char *encoding,
189 int standalone);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000190
191XMLPARSEAPI(void)
192XML_SetXmlDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000193 XML_XmlDeclHandler xmldecl);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000194
195
196typedef struct {
Fred Drake31d485c2004-08-03 07:06:22 +0000197 void *(*malloc_fcn)(size_t size);
198 void *(*realloc_fcn)(void *ptr, size_t size);
199 void (*free_fcn)(void *ptr);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000200} XML_Memory_Handling_Suite;
201
202/* Constructs a new parser; encoding is the encoding specified by the
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000203 external protocol or NULL if there is none specified.
204*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000205XMLPARSEAPI(XML_Parser)
206XML_ParserCreate(const XML_Char *encoding);
207
208/* Constructs a new parser and namespace processor. Element type
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000209 names and attribute names that belong to a namespace will be
210 expanded; unprefixed attribute names are never expanded; unprefixed
211 element type names are expanded only if there is a default
212 namespace. The expanded name is the concatenation of the namespace
213 URI, the namespace separator character, and the local part of the
214 name. If the namespace separator is '\0' then the namespace URI
215 and the local part will be concatenated without any separator.
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000216 It is a programming error to use the separator '\0' with namespace
217 triplets (see XML_SetReturnNSTriplet).
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000218*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000219XMLPARSEAPI(XML_Parser)
220XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
221
222
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000223/* Constructs a new parser using the memory management suite referred to
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000224 by memsuite. If memsuite is NULL, then use the standard library memory
225 suite. If namespaceSeparator is non-NULL it creates a parser with
226 namespace processing as described above. The character pointed at
227 will serve as the namespace separator.
228
229 All further memory operations used for the created parser will come from
230 the given suite.
231*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000232XMLPARSEAPI(XML_Parser)
233XML_ParserCreate_MM(const XML_Char *encoding,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000234 const XML_Memory_Handling_Suite *memsuite,
235 const XML_Char *namespaceSeparator);
236
237/* Prepare a parser object to be re-used. This is particularly
238 valuable when memory allocation overhead is disproportionatly high,
239 such as when a large number of small documnents need to be parsed.
240 All handlers are cleared from the parser, except for the
241 unknownEncodingHandler. The parser's external state is re-initialized
242 except for the values of ns and ns_triplets.
243
244 Added in Expat 1.95.3.
245*/
246XMLPARSEAPI(XML_Bool)
247XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000248
249/* atts is array of name/value pairs, terminated by 0;
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000250 names and values are 0 terminated.
251*/
Fred Drake08317ae2003-10-21 15:38:55 +0000252typedef void (XMLCALL *XML_StartElementHandler) (void *userData,
253 const XML_Char *name,
254 const XML_Char **atts);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000255
Fred Drake08317ae2003-10-21 15:38:55 +0000256typedef void (XMLCALL *XML_EndElementHandler) (void *userData,
257 const XML_Char *name);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000258
259
260/* s is not 0 terminated. */
Fred Drake08317ae2003-10-21 15:38:55 +0000261typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData,
262 const XML_Char *s,
263 int len);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000264
265/* target and data are 0 terminated */
Fred Drake08317ae2003-10-21 15:38:55 +0000266typedef void (XMLCALL *XML_ProcessingInstructionHandler) (
267 void *userData,
268 const XML_Char *target,
269 const XML_Char *data);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000270
271/* data is 0 terminated */
Fred Drake08317ae2003-10-21 15:38:55 +0000272typedef void (XMLCALL *XML_CommentHandler) (void *userData,
273 const XML_Char *data);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000274
Fred Drake08317ae2003-10-21 15:38:55 +0000275typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData);
276typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000277
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000278/* This is called for any characters in the XML document for which
279 there is no applicable handler. This includes both characters that
280 are part of markup which is of a kind that is not reported
281 (comments, markup declarations), or characters that are part of a
282 construct which could be reported but for which no handler has been
283 supplied. The characters are passed exactly as they were in the XML
284 document except that they will be encoded in UTF-8 or UTF-16.
285 Line boundaries are not normalized. Note that a byte order mark
286 character is not passed to the default handler. There are no
287 guarantees about how characters are divided between calls to the
288 default handler: for example, a comment might be split between
289 multiple calls.
290*/
Fred Drake08317ae2003-10-21 15:38:55 +0000291typedef void (XMLCALL *XML_DefaultHandler) (void *userData,
292 const XML_Char *s,
293 int len);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000294
295/* This is called for the start of the DOCTYPE declaration, before
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000296 any DTD or internal subset is parsed.
297*/
Fred Drake08317ae2003-10-21 15:38:55 +0000298typedef void (XMLCALL *XML_StartDoctypeDeclHandler) (
299 void *userData,
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000300 const XML_Char *doctypeName,
301 const XML_Char *sysid,
302 const XML_Char *pubid,
303 int has_internal_subset);
304
305/* This is called for the start of the DOCTYPE declaration when the
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000306 closing > is encountered, but after processing any external
307 subset.
308*/
Fred Drake08317ae2003-10-21 15:38:55 +0000309typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000310
311/* This is called for entity declarations. The is_parameter_entity
312 argument will be non-zero if the entity is a parameter entity, zero
313 otherwise.
314
315 For internal entities (<!ENTITY foo "bar">), value will
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000316 be non-NULL and systemId, publicID, and notationName will be NULL.
317 The value string is NOT nul-terminated; the length is provided in
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000318 the value_length argument. Since it is legal to have zero-length
319 values, do not use this argument to test for internal entities.
320
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000321 For external entities, value will be NULL and systemId will be
322 non-NULL. The publicId argument will be NULL unless a public
323 identifier was provided. The notationName argument will have a
324 non-NULL value only for unparsed entity declarations.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000325
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000326 Note that is_parameter_entity can't be changed to XML_Bool, since
327 that would break binary compatibility.
328*/
Fred Drake08317ae2003-10-21 15:38:55 +0000329typedef void (XMLCALL *XML_EntityDeclHandler) (
330 void *userData,
331 const XML_Char *entityName,
332 int is_parameter_entity,
333 const XML_Char *value,
334 int value_length,
335 const XML_Char *base,
336 const XML_Char *systemId,
337 const XML_Char *publicId,
338 const XML_Char *notationName);
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000339
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000340XMLPARSEAPI(void)
341XML_SetEntityDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000342 XML_EntityDeclHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000343
344/* OBSOLETE -- OBSOLETE -- OBSOLETE
345 This handler has been superceded by the EntityDeclHandler above.
346 It is provided here for backward compatibility.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000347
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000348 This is called for a declaration of an unparsed (NDATA) entity.
349 The base argument is whatever was set by XML_SetBase. The
350 entityName, systemId and notationName arguments will never be
351 NULL. The other arguments may be.
352*/
Fred Drake08317ae2003-10-21 15:38:55 +0000353typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) (
354 void *userData,
355 const XML_Char *entityName,
356 const XML_Char *base,
357 const XML_Char *systemId,
358 const XML_Char *publicId,
359 const XML_Char *notationName);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000360
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000361/* This is called for a declaration of notation. The base argument is
362 whatever was set by XML_SetBase. The notationName will never be
363 NULL. The other arguments can be.
364*/
Fred Drake08317ae2003-10-21 15:38:55 +0000365typedef void (XMLCALL *XML_NotationDeclHandler) (
366 void *userData,
367 const XML_Char *notationName,
368 const XML_Char *base,
369 const XML_Char *systemId,
370 const XML_Char *publicId);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000371
372/* When namespace processing is enabled, these are called once for
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000373 each namespace declaration. The call to the start and end element
374 handlers occur between the calls to the start and end namespace
375 declaration handlers. For an xmlns attribute, prefix will be
376 NULL. For an xmlns="" attribute, uri will be NULL.
377*/
Fred Drake08317ae2003-10-21 15:38:55 +0000378typedef void (XMLCALL *XML_StartNamespaceDeclHandler) (
379 void *userData,
380 const XML_Char *prefix,
381 const XML_Char *uri);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000382
Fred Drake08317ae2003-10-21 15:38:55 +0000383typedef void (XMLCALL *XML_EndNamespaceDeclHandler) (
384 void *userData,
385 const XML_Char *prefix);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000386
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000387/* This is called if the document is not standalone, that is, it has an
388 external subset or a reference to a parameter entity, but does not
389 have standalone="yes". If this handler returns XML_STATUS_ERROR,
390 then processing will not continue, and the parser will return a
391 XML_ERROR_NOT_STANDALONE error.
392 If parameter entity parsing is enabled, then in addition to the
393 conditions above this handler will only be called if the referenced
394 entity was actually read.
395*/
Fred Drake08317ae2003-10-21 15:38:55 +0000396typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000397
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000398/* This is called for a reference to an external parsed general
399 entity. The referenced entity is not automatically parsed. The
400 application can parse it immediately or later using
401 XML_ExternalEntityParserCreate.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000402
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000403 The parser argument is the parser parsing the entity containing the
404 reference; it can be passed as the parser argument to
405 XML_ExternalEntityParserCreate. The systemId argument is the
406 system identifier as specified in the entity declaration; it will
407 not be NULL.
408
409 The base argument is the system identifier that should be used as
410 the base for resolving systemId if systemId was relative; this is
411 set by XML_SetBase; it may be NULL.
412
413 The publicId argument is the public identifier as specified in the
414 entity declaration, or NULL if none was specified; the whitespace
415 in the public identifier will have been normalized as required by
416 the XML spec.
417
418 The context argument specifies the parsing context in the format
419 expected by the context argument to XML_ExternalEntityParserCreate;
420 context is valid only until the handler returns, so if the
421 referenced entity is to be parsed later, it must be copied.
422 context is NULL only when the entity is a parameter entity.
423
424 The handler should return XML_STATUS_ERROR if processing should not
425 continue because of a fatal error in the handling of the external
426 entity. In this case the calling parser will return an
427 XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
428
429 Note that unlike other handlers the first argument is the parser,
430 not userData.
431*/
Fred Drake08317ae2003-10-21 15:38:55 +0000432typedef int (XMLCALL *XML_ExternalEntityRefHandler) (
433 XML_Parser parser,
434 const XML_Char *context,
435 const XML_Char *base,
436 const XML_Char *systemId,
437 const XML_Char *publicId);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000438
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000439/* This is called in two situations:
440 1) An entity reference is encountered for which no declaration
441 has been read *and* this is not an error.
442 2) An internal entity reference is read, but not expanded, because
443 XML_SetDefaultHandler has been called.
444 Note: skipped parameter entities in declarations and skipped general
445 entities in attribute values cannot be reported, because
446 the event would be out of sync with the reporting of the
447 declarations or attribute values
448*/
Fred Drake08317ae2003-10-21 15:38:55 +0000449typedef void (XMLCALL *XML_SkippedEntityHandler) (
450 void *userData,
451 const XML_Char *entityName,
452 int is_parameter_entity);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000453
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000454/* This structure is filled in by the XML_UnknownEncodingHandler to
455 provide information to the parser about encodings that are unknown
456 to the parser.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000457
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000458 The map[b] member gives information about byte sequences whose
459 first byte is b.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000460
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000461 If map[b] is c where c is >= 0, then b by itself encodes the
462 Unicode scalar value c.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000463
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000464 If map[b] is -1, then the byte sequence is malformed.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000465
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000466 If map[b] is -n, where n >= 2, then b is the first byte of an
467 n-byte sequence that encodes a single Unicode scalar value.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000468
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000469 The data member will be passed as the first argument to the convert
470 function.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000471
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000472 The convert function is used to convert multibyte sequences; s will
473 point to a n-byte sequence where map[(unsigned char)*s] == -n. The
474 convert function must return the Unicode scalar value represented
475 by this byte sequence or -1 if the byte sequence is malformed.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000476
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000477 The convert function may be NULL if the encoding is a single-byte
478 encoding, that is if map[b] >= -1 for all bytes b.
479
480 When the parser is finished with the encoding, then if release is
481 not NULL, it will call release passing it the data member; once
482 release has been called, the convert function will not be called
483 again.
484
485 Expat places certain restrictions on the encodings that are supported
486 using this mechanism.
487
488 1. Every ASCII character that can appear in a well-formed XML document,
489 other than the characters
490
491 $@\^`{}~
492
493 must be represented by a single byte, and that byte must be the
494 same byte that represents that character in ASCII.
495
496 2. No character may require more than 4 bytes to encode.
497
498 3. All characters encoded must have Unicode scalar values <=
499 0xFFFF, (i.e., characters that would be encoded by surrogates in
500 UTF-16 are not allowed). Note that this restriction doesn't
501 apply to the built-in support for UTF-8 and UTF-16.
502
503 4. No Unicode character may be encoded by more than one distinct
504 sequence of bytes.
505*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000506typedef struct {
507 int map[256];
508 void *data;
Fred Drake08317ae2003-10-21 15:38:55 +0000509 int (XMLCALL *convert)(void *data, const char *s);
510 void (XMLCALL *release)(void *data);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000511} XML_Encoding;
512
513/* This is called for an encoding that is unknown to the parser.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000514
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000515 The encodingHandlerData argument is that which was passed as the
516 second argument to XML_SetUnknownEncodingHandler.
517
518 The name argument gives the name of the encoding as specified in
519 the encoding declaration.
520
521 If the callback can provide information about the encoding, it must
522 fill in the XML_Encoding structure, and return XML_STATUS_OK.
523 Otherwise it must return XML_STATUS_ERROR.
524
525 If info does not describe a suitable encoding, then the parser will
526 return an XML_UNKNOWN_ENCODING error.
527*/
Fred Drake08317ae2003-10-21 15:38:55 +0000528typedef int (XMLCALL *XML_UnknownEncodingHandler) (
529 void *encodingHandlerData,
530 const XML_Char *name,
531 XML_Encoding *info);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000532
533XMLPARSEAPI(void)
534XML_SetElementHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000535 XML_StartElementHandler start,
536 XML_EndElementHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000537
538XMLPARSEAPI(void)
Fred Drake31d485c2004-08-03 07:06:22 +0000539XML_SetStartElementHandler(XML_Parser parser,
540 XML_StartElementHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000541
542XMLPARSEAPI(void)
Fred Drake31d485c2004-08-03 07:06:22 +0000543XML_SetEndElementHandler(XML_Parser parser,
544 XML_EndElementHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000545
546XMLPARSEAPI(void)
547XML_SetCharacterDataHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000548 XML_CharacterDataHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000549
550XMLPARSEAPI(void)
551XML_SetProcessingInstructionHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000552 XML_ProcessingInstructionHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000553XMLPARSEAPI(void)
554XML_SetCommentHandler(XML_Parser parser,
555 XML_CommentHandler handler);
556
557XMLPARSEAPI(void)
558XML_SetCdataSectionHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000559 XML_StartCdataSectionHandler start,
560 XML_EndCdataSectionHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000561
562XMLPARSEAPI(void)
563XML_SetStartCdataSectionHandler(XML_Parser parser,
564 XML_StartCdataSectionHandler start);
565
566XMLPARSEAPI(void)
567XML_SetEndCdataSectionHandler(XML_Parser parser,
568 XML_EndCdataSectionHandler end);
569
570/* This sets the default handler and also inhibits expansion of
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000571 internal entities. These entity references will be passed to the
572 default handler, or to the skipped entity handler, if one is set.
573*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000574XMLPARSEAPI(void)
575XML_SetDefaultHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000576 XML_DefaultHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000577
578/* This sets the default handler but does not inhibit expansion of
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000579 internal entities. The entity reference will not be passed to the
580 default handler.
581*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000582XMLPARSEAPI(void)
583XML_SetDefaultHandlerExpand(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000584 XML_DefaultHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000585
586XMLPARSEAPI(void)
587XML_SetDoctypeDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000588 XML_StartDoctypeDeclHandler start,
589 XML_EndDoctypeDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000590
591XMLPARSEAPI(void)
592XML_SetStartDoctypeDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000593 XML_StartDoctypeDeclHandler start);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000594
595XMLPARSEAPI(void)
596XML_SetEndDoctypeDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000597 XML_EndDoctypeDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000598
599XMLPARSEAPI(void)
600XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000601 XML_UnparsedEntityDeclHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000602
603XMLPARSEAPI(void)
604XML_SetNotationDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000605 XML_NotationDeclHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000606
607XMLPARSEAPI(void)
608XML_SetNamespaceDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000609 XML_StartNamespaceDeclHandler start,
610 XML_EndNamespaceDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000611
612XMLPARSEAPI(void)
613XML_SetStartNamespaceDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000614 XML_StartNamespaceDeclHandler start);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000615
616XMLPARSEAPI(void)
617XML_SetEndNamespaceDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000618 XML_EndNamespaceDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000619
620XMLPARSEAPI(void)
621XML_SetNotStandaloneHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000622 XML_NotStandaloneHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000623
624XMLPARSEAPI(void)
625XML_SetExternalEntityRefHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000626 XML_ExternalEntityRefHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000627
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000628/* If a non-NULL value for arg is specified here, then it will be
629 passed as the first argument to the external entity ref handler
630 instead of the parser object.
631*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000632XMLPARSEAPI(void)
Fred Drake31d485c2004-08-03 07:06:22 +0000633XML_SetExternalEntityRefHandlerArg(XML_Parser parser,
634 void *arg);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000635
636XMLPARSEAPI(void)
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000637XML_SetSkippedEntityHandler(XML_Parser parser,
638 XML_SkippedEntityHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000639
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000640XMLPARSEAPI(void)
641XML_SetUnknownEncodingHandler(XML_Parser parser,
642 XML_UnknownEncodingHandler handler,
643 void *encodingHandlerData);
644
645/* This can be called within a handler for a start element, end
646 element, processing instruction or character data. It causes the
647 corresponding markup to be passed to the default handler.
648*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000649XMLPARSEAPI(void)
650XML_DefaultCurrent(XML_Parser parser);
651
652/* If do_nst is non-zero, and namespace processing is in effect, and
653 a name has a prefix (i.e. an explicit namespace qualifier) then
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000654 that name is returned as a triplet in a single string separated by
655 the separator character specified when the parser was created: URI
656 + sep + local_name + sep + prefix.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000657
658 If do_nst is zero, then namespace information is returned in the
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000659 default manner (URI + sep + local_name) whether or not the name
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000660 has a prefix.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000661
662 Note: Calling XML_SetReturnNSTriplet after XML_Parse or
663 XML_ParseBuffer has no effect.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000664*/
665
666XMLPARSEAPI(void)
667XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
668
669/* This value is passed as the userData argument to callbacks. */
670XMLPARSEAPI(void)
671XML_SetUserData(XML_Parser parser, void *userData);
672
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000673/* Returns the last value set by XML_SetUserData or NULL. */
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000674#define XML_GetUserData(parser) (*(void **)(parser))
675
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000676/* This is equivalent to supplying an encoding argument to
677 XML_ParserCreate. On success XML_SetEncoding returns non-zero,
678 zero otherwise.
679 Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
680 has no effect and returns XML_STATUS_ERROR.
681*/
682XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000683XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
684
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000685/* If this function is called, then the parser will be passed as the
686 first argument to callbacks instead of userData. The userData will
687 still be accessible using XML_GetUserData.
688*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000689XMLPARSEAPI(void)
690XML_UseParserAsHandlerArg(XML_Parser parser);
691
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000692/* If useDTD == XML_TRUE is passed to this function, then the parser
693 will assume that there is an external subset, even if none is
694 specified in the document. In such a case the parser will call the
695 externalEntityRefHandler with a value of NULL for the systemId
696 argument (the publicId and context arguments will be NULL as well).
Fred Drake31d485c2004-08-03 07:06:22 +0000697 Note: For the purpose of checking WFC: Entity Declared, passing
698 useDTD == XML_TRUE will make the parser behave as if the document
699 had a DTD with an external subset.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000700 Note: If this function is called, then this must be done before
701 the first call to XML_Parse or XML_ParseBuffer, since it will
702 have no effect after that. Returns
703 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
704 Note: If the document does not have a DOCTYPE declaration at all,
705 then startDoctypeDeclHandler and endDoctypeDeclHandler will not
706 be called, despite an external subset being parsed.
707 Note: If XML_DTD is not defined when Expat is compiled, returns
708 XML_ERROR_FEATURE_REQUIRES_XML_DTD.
709*/
710XMLPARSEAPI(enum XML_Error)
711XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000712
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000713
714/* Sets the base to be used for resolving relative URIs in system
715 identifiers in declarations. Resolving relative identifiers is
716 left to the application: this value will be passed through as the
717 base argument to the XML_ExternalEntityRefHandler,
718 XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
719 argument will be copied. Returns XML_STATUS_ERROR if out of memory,
720 XML_STATUS_OK otherwise.
721*/
722XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000723XML_SetBase(XML_Parser parser, const XML_Char *base);
724
725XMLPARSEAPI(const XML_Char *)
726XML_GetBase(XML_Parser parser);
727
728/* Returns the number of the attribute/value pairs passed in last call
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000729 to the XML_StartElementHandler that were specified in the start-tag
730 rather than defaulted. Each attribute/value pair counts as 2; thus
731 this correspondds to an index into the atts array passed to the
732 XML_StartElementHandler.
733*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000734XMLPARSEAPI(int)
735XML_GetSpecifiedAttributeCount(XML_Parser parser);
736
737/* Returns the index of the ID attribute passed in the last call to
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000738 XML_StartElementHandler, or -1 if there is no ID attribute. Each
739 attribute/value pair counts as 2; thus this correspondds to an
740 index into the atts array passed to the XML_StartElementHandler.
741*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000742XMLPARSEAPI(int)
743XML_GetIdAttributeIndex(XML_Parser parser);
744
Gregory P. Smith7c6309c2012-07-14 14:12:35 -0700745#ifdef XML_ATTR_INFO
746/* Source file byte offsets for the start and end of attribute names and values.
747 The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
748 file an attribute value of "blah" will yield:
749 info->valueEnd - info->valueStart = 4 bytes.
750*/
751typedef struct {
752 XML_Index nameStart; /* Offset to beginning of the attribute name. */
753 XML_Index nameEnd; /* Offset after the attribute name's last byte. */
754 XML_Index valueStart; /* Offset to beginning of the attribute value. */
755 XML_Index valueEnd; /* Offset after the attribute value's last byte. */
756} XML_AttrInfo;
757
758/* Returns an array of XML_AttrInfo structures for the attribute/value pairs
759 passed in last call to the XML_StartElementHandler that were specified
760 in the start-tag rather than defaulted. Each attribute/value pair counts
761 as 1; thus the number of entries in the array is
762 XML_GetSpecifiedAttributeCount(parser) / 2.
763*/
764XMLPARSEAPI(const XML_AttrInfo *)
765XML_GetAttributeInfo(XML_Parser parser);
766#endif
767
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000768/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
769 detected. The last call to XML_Parse must have isFinal true; len
770 may be zero for this call (or any other).
771
Fred Drakedab8b0a2003-02-07 02:15:56 +0000772 Though the return values for these functions has always been
773 described as a Boolean value, the implementation, at least for the
774 1.95.x series, has always returned exactly one of the XML_Status
775 values.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000776*/
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000777XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000778XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
779
780XMLPARSEAPI(void *)
781XML_GetBuffer(XML_Parser parser, int len);
782
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000783XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000784XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
785
Fred Drake31d485c2004-08-03 07:06:22 +0000786/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
787 Must be called from within a call-back handler, except when aborting
788 (resumable = 0) an already suspended parser. Some call-backs may
789 still follow because they would otherwise get lost. Examples:
790 - endElementHandler() for empty elements when stopped in
791 startElementHandler(),
792 - endNameSpaceDeclHandler() when stopped in endElementHandler(),
793 and possibly others.
794
795 Can be called from most handlers, including DTD related call-backs,
796 except when parsing an external parameter entity and resumable != 0.
797 Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
798 Possible error codes:
799 - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
800 - XML_ERROR_FINISHED: when the parser has already finished.
801 - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
802
803 When resumable != 0 (true) then parsing is suspended, that is,
804 XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
805 Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
806 return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
807
808 *Note*:
809 This will be applied to the current parser instance only, that is, if
810 there is a parent parser then it will continue parsing when the
811 externalEntityRefHandler() returns. It is up to the implementation of
812 the externalEntityRefHandler() to call XML_StopParser() on the parent
813 parser (recursively), if one wants to stop parsing altogether.
814
815 When suspended, parsing can be resumed by calling XML_ResumeParser().
816*/
817XMLPARSEAPI(enum XML_Status)
818XML_StopParser(XML_Parser parser, XML_Bool resumable);
819
820/* Resumes parsing after it has been suspended with XML_StopParser().
821 Must not be called from within a handler call-back. Returns same
822 status codes as XML_Parse() or XML_ParseBuffer().
823 Additional error code XML_ERROR_NOT_SUSPENDED possible.
824
825 *Note*:
826 This must be called on the most deeply nested child parser instance
827 first, and on its parent parser only after the child parser has finished,
828 to be applied recursively until the document entity's parser is restarted.
829 That is, the parent parser will not resume by itself and it is up to the
830 application to call XML_ResumeParser() on it at the appropriate moment.
831*/
832XMLPARSEAPI(enum XML_Status)
833XML_ResumeParser(XML_Parser parser);
834
835enum XML_Parsing {
836 XML_INITIALIZED,
837 XML_PARSING,
838 XML_FINISHED,
839 XML_SUSPENDED
840};
841
842typedef struct {
843 enum XML_Parsing parsing;
844 XML_Bool finalBuffer;
845} XML_ParsingStatus;
846
847/* Returns status of parser with respect to being initialized, parsing,
848 finished, or suspended and processing the final buffer.
849 XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
850 XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
851*/
852XMLPARSEAPI(void)
853XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
854
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000855/* Creates an XML_Parser object that can parse an external general
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000856 entity; context is a '\0'-terminated string specifying the parse
857 context; encoding is a '\0'-terminated string giving the name of
858 the externally specified encoding, or NULL if there is no
859 externally specified encoding. The context string consists of a
860 sequence of tokens separated by formfeeds (\f); a token consisting
861 of a name specifies that the general entity of the name is open; a
862 token of the form prefix=uri specifies the namespace for a
863 particular prefix; a token of the form =uri specifies the default
864 namespace. This can be called at any point after the first call to
865 an ExternalEntityRefHandler so longer as the parser has not yet
866 been freed. The new parser is completely independent and may
867 safely be used in a separate thread. The handlers and userData are
868 initialized from the parser argument. Returns NULL if out of memory.
869 Otherwise returns a new XML_Parser object.
870*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000871XMLPARSEAPI(XML_Parser)
872XML_ExternalEntityParserCreate(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000873 const XML_Char *context,
874 const XML_Char *encoding);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000875
876enum XML_ParamEntityParsing {
877 XML_PARAM_ENTITY_PARSING_NEVER,
878 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
879 XML_PARAM_ENTITY_PARSING_ALWAYS
880};
881
882/* Controls parsing of parameter entities (including the external DTD
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000883 subset). If parsing of parameter entities is enabled, then
884 references to external parameter entities (including the external
885 DTD subset) will be passed to the handler set with
886 XML_SetExternalEntityRefHandler. The context passed will be 0.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000887
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000888 Unlike external general entities, external parameter entities can
889 only be parsed synchronously. If the external parameter entity is
890 to be parsed, it must be parsed during the call to the external
891 entity ref handler: the complete sequence of
892 XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
893 XML_ParserFree calls must be made during this call. After
894 XML_ExternalEntityParserCreate has been called to create the parser
895 for the external parameter entity (context must be 0 for this
896 call), it is illegal to make any calls on the old parser until
897 XML_ParserFree has been called on the newly created parser.
898 If the library has been compiled without support for parameter
899 entity parsing (ie without XML_DTD being defined), then
900 XML_SetParamEntityParsing will return 0 if parsing of parameter
901 entities is requested; otherwise it will return non-zero.
902 Note: If XML_SetParamEntityParsing is called after XML_Parse or
903 XML_ParseBuffer, then it has no effect and will always return 0.
904*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000905XMLPARSEAPI(int)
906XML_SetParamEntityParsing(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000907 enum XML_ParamEntityParsing parsing);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000908
Gregory P. Smith8e91cf62012-03-14 14:26:55 -0700909/* Sets the hash salt to use for internal hash calculations.
910 Helps in preventing DoS attacks based on predicting hash
911 function behavior. This must be called before parsing is started.
912 Returns 1 if successful, 0 when called after parsing has started.
913*/
914XMLPARSEAPI(int)
915XML_SetHashSalt(XML_Parser parser,
916 unsigned long hash_salt);
917
Gregory P. Smith25227712012-03-14 18:10:37 -0700918#define XML_HAS_SET_HASH_SALT /* Python Only: Defined for pyexpat.c. */
919
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000920/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
921 XML_GetErrorCode returns information about the error.
922*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000923XMLPARSEAPI(enum XML_Error)
924XML_GetErrorCode(XML_Parser parser);
925
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000926/* These functions return information about the current parse
927 location. They may be called from any callback called to report
Fred Drake08317ae2003-10-21 15:38:55 +0000928 some parse event; in this case the location is the location of the
929 first of the sequence of characters that generated the event. When
930 called from callbacks generated by declarations in the document
931 prologue, the location identified isn't as neatly defined, but will
932 be within the relevant markup. When called outside of the callback
933 functions, the position indicated will be just past the last parse
934 event (regardless of whether there was an associated callback).
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000935
936 They may also be called after returning from a call to XML_Parse
937 or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then
938 the location is the location of the character at which the error
939 was detected; otherwise the location is the location of the last
940 parse event, as described above.
941*/
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000942XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
943XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
944XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000945
946/* Return the number of bytes in the current event.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000947 Returns 0 if the event is in an internal entity.
948*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000949XMLPARSEAPI(int)
950XML_GetCurrentByteCount(XML_Parser parser);
951
952/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
953 the integer pointed to by offset to the offset within this buffer
954 of the current parse position, and sets the integer pointed to by size
955 to the size of this buffer (the number of input bytes). Otherwise
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000956 returns a NULL pointer. Also returns a NULL pointer if a parse isn't
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000957 active.
958
959 NOTE: The character pointer returned should not be used outside
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000960 the handler that makes the call.
961*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000962XMLPARSEAPI(const char *)
963XML_GetInputContext(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000964 int *offset,
965 int *size);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000966
967/* For backwards compatibility with previous versions. */
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000968#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000969#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000970#define XML_GetErrorByteIndex XML_GetCurrentByteIndex
971
972/* Frees the content model passed to the element declaration handler */
973XMLPARSEAPI(void)
974XML_FreeContentModel(XML_Parser parser, XML_Content *model);
975
976/* Exposing the memory handling functions used in Expat */
977XMLPARSEAPI(void *)
978XML_MemMalloc(XML_Parser parser, size_t size);
979
980XMLPARSEAPI(void *)
981XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
982
983XMLPARSEAPI(void)
984XML_MemFree(XML_Parser parser, void *ptr);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000985
986/* Frees memory used by the parser. */
987XMLPARSEAPI(void)
988XML_ParserFree(XML_Parser parser);
989
990/* Returns a string describing the error. */
991XMLPARSEAPI(const XML_LChar *)
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000992XML_ErrorString(enum XML_Error code);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000993
994/* Return a string containing the version number of this expat */
995XMLPARSEAPI(const XML_LChar *)
996XML_ExpatVersion(void);
997
998typedef struct {
999 int major;
1000 int minor;
1001 int micro;
1002} XML_Expat_Version;
1003
1004/* Return an XML_Expat_Version structure containing numeric version
Martin v. Löwisfc03a942003-01-25 22:41:29 +00001005 number information for this version of expat.
1006*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +00001007XMLPARSEAPI(XML_Expat_Version)
1008XML_ExpatVersionInfo(void);
1009
Martin v. Löwisfc03a942003-01-25 22:41:29 +00001010/* Added in Expat 1.95.5. */
1011enum XML_FeatureEnum {
1012 XML_FEATURE_END = 0,
1013 XML_FEATURE_UNICODE,
1014 XML_FEATURE_UNICODE_WCHAR_T,
1015 XML_FEATURE_DTD,
1016 XML_FEATURE_CONTEXT_BYTES,
1017 XML_FEATURE_MIN_SIZE,
1018 XML_FEATURE_SIZEOF_XML_CHAR,
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001019 XML_FEATURE_SIZEOF_XML_LCHAR,
Gregory P. Smith7c6309c2012-07-14 14:12:35 -07001020 XML_FEATURE_NS,
1021 XML_FEATURE_LARGE_SIZE,
1022 XML_FEATURE_ATTR_INFO
Martin v. Löwisfc03a942003-01-25 22:41:29 +00001023 /* Additional features must be added to the end of this enum. */
1024};
Martin v. Löwis8fef47b2002-02-13 07:47:16 +00001025
Martin v. Löwisfc03a942003-01-25 22:41:29 +00001026typedef struct {
1027 enum XML_FeatureEnum feature;
1028 const XML_LChar *name;
1029 long int value;
1030} XML_Feature;
1031
1032XMLPARSEAPI(const XML_Feature *)
1033XML_GetFeatureList(void);
1034
1035
1036/* Expat follows the GNU/Linux convention of odd number minor version for
1037 beta/development releases and even number minor version for stable
1038 releases. Micro is bumped with each release, and set to 0 with each
1039 change to major or minor version.
1040*/
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001041#define XML_MAJOR_VERSION 2
Gregory P. Smith7c6309c2012-07-14 14:12:35 -07001042#define XML_MINOR_VERSION 1
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001043#define XML_MICRO_VERSION 0
Martin v. Löwisb48d1982002-02-12 09:52:22 +00001044
1045#ifdef __cplusplus
1046}
1047#endif
1048
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001049#endif /* not Expat_INCLUDED */