blob: ecba92e3d2aeb0c059606cc4dd9cafa7113c9a86 [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
5#ifndef XmlParse_INCLUDED
6#define XmlParse_INCLUDED 1
7
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
Martin v. Löwisfc03a942003-01-25 22:41:29 +000020struct XML_ParserStruct;
21typedef struct XML_ParserStruct *XML_Parser;
22
Martin v. Löwisfc03a942003-01-25 22:41:29 +000023/* Should this be defined using stdbool.h when C99 is available? */
24typedef unsigned char XML_Bool;
25#define XML_TRUE ((XML_Bool) 1)
26#define XML_FALSE ((XML_Bool) 0)
27
Fred Drakedab8b0a2003-02-07 02:15:56 +000028/* The XML_Status enum gives the possible return values for several
29 API functions. The preprocessor #defines are included so this
30 stanza can be added to code that still needs to support older
31 versions of Expat 1.95.x:
32
33 #ifndef XML_STATUS_OK
34 #define XML_STATUS_OK 1
35 #define XML_STATUS_ERROR 0
36 #endif
37
38 Otherwise, the #define hackery is quite ugly and would have been
39 dropped.
40*/
41enum XML_Status {
42 XML_STATUS_ERROR = 0,
43#define XML_STATUS_ERROR XML_STATUS_ERROR
Fred Drake31d485c2004-08-03 07:06:22 +000044 XML_STATUS_OK = 1,
Fred Drakedab8b0a2003-02-07 02:15:56 +000045#define XML_STATUS_OK XML_STATUS_OK
Georg Brandle810fe22006-02-19 15:28:47 +000046 XML_STATUS_SUSPENDED = 2
Fred Drake31d485c2004-08-03 07:06:22 +000047#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
Fred Drakedab8b0a2003-02-07 02:15:56 +000048};
49
Martin v. Löwisfc03a942003-01-25 22:41:29 +000050enum XML_Error {
51 XML_ERROR_NONE,
52 XML_ERROR_NO_MEMORY,
53 XML_ERROR_SYNTAX,
54 XML_ERROR_NO_ELEMENTS,
55 XML_ERROR_INVALID_TOKEN,
56 XML_ERROR_UNCLOSED_TOKEN,
57 XML_ERROR_PARTIAL_CHAR,
58 XML_ERROR_TAG_MISMATCH,
59 XML_ERROR_DUPLICATE_ATTRIBUTE,
60 XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
61 XML_ERROR_PARAM_ENTITY_REF,
62 XML_ERROR_UNDEFINED_ENTITY,
63 XML_ERROR_RECURSIVE_ENTITY_REF,
64 XML_ERROR_ASYNC_ENTITY,
65 XML_ERROR_BAD_CHAR_REF,
66 XML_ERROR_BINARY_ENTITY_REF,
67 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
68 XML_ERROR_MISPLACED_XML_PI,
69 XML_ERROR_UNKNOWN_ENCODING,
70 XML_ERROR_INCORRECT_ENCODING,
71 XML_ERROR_UNCLOSED_CDATA_SECTION,
72 XML_ERROR_EXTERNAL_ENTITY_HANDLING,
73 XML_ERROR_NOT_STANDALONE,
74 XML_ERROR_UNEXPECTED_STATE,
75 XML_ERROR_ENTITY_DECLARED_IN_PE,
76 XML_ERROR_FEATURE_REQUIRES_XML_DTD,
Fred Drake08317ae2003-10-21 15:38:55 +000077 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
Fred Drake31d485c2004-08-03 07:06:22 +000078 /* Added in 1.95.7. */
79 XML_ERROR_UNBOUND_PREFIX,
80 /* Added in 1.95.8. */
81 XML_ERROR_UNDECLARING_PREFIX,
82 XML_ERROR_INCOMPLETE_PE,
83 XML_ERROR_XML_DECL,
84 XML_ERROR_TEXT_DECL,
85 XML_ERROR_PUBLICID,
86 XML_ERROR_SUSPENDED,
87 XML_ERROR_NOT_SUSPENDED,
88 XML_ERROR_ABORTED,
89 XML_ERROR_FINISHED,
90 XML_ERROR_SUSPEND_PE
Martin v. Löwisfc03a942003-01-25 22:41:29 +000091};
Martin v. Löwisb48d1982002-02-12 09:52:22 +000092
93enum XML_Content_Type {
94 XML_CTYPE_EMPTY = 1,
95 XML_CTYPE_ANY,
96 XML_CTYPE_MIXED,
97 XML_CTYPE_NAME,
98 XML_CTYPE_CHOICE,
99 XML_CTYPE_SEQ
100};
101
102enum XML_Content_Quant {
103 XML_CQUANT_NONE,
104 XML_CQUANT_OPT,
105 XML_CQUANT_REP,
106 XML_CQUANT_PLUS
107};
108
109/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
110 XML_CQUANT_NONE, and the other fields will be zero or NULL.
111 If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
112 numchildren will contain number of elements that may be mixed in
113 and children point to an array of XML_Content cells that will be
114 all of XML_CTYPE_NAME type with no quantification.
115
116 If type == XML_CTYPE_NAME, then the name points to the name, and
117 the numchildren field will be zero and children will be NULL. The
118 quant fields indicates any quantifiers placed on the name.
119
120 CHOICE and SEQ will have name NULL, the number of children in
121 numchildren and children will point, recursively, to an array
122 of XML_Content cells.
123
124 The EMPTY, ANY, and MIXED types will only occur at top level.
125*/
126
127typedef struct XML_cp XML_Content;
128
129struct XML_cp {
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000130 enum XML_Content_Type type;
131 enum XML_Content_Quant quant;
132 XML_Char * name;
133 unsigned int numchildren;
134 XML_Content * children;
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000135};
136
137
138/* This is called for an element declaration. See above for
139 description of the model argument. It's the caller's responsibility
140 to free model when finished with it.
141*/
Fred Drake08317ae2003-10-21 15:38:55 +0000142typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
143 const XML_Char *name,
144 XML_Content *model);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000145
146XMLPARSEAPI(void)
147XML_SetElementDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000148 XML_ElementDeclHandler eldecl);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000149
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000150/* The Attlist declaration handler is called for *each* attribute. So
151 a single Attlist declaration with multiple attributes declared will
152 generate multiple calls to this handler. The "default" parameter
153 may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
154 keyword. The "isrequired" parameter will be true and the default
155 value will be NULL in the case of "#REQUIRED". If "isrequired" is
156 true and default is non-NULL, then this is a "#FIXED" default.
157*/
Fred Drake08317ae2003-10-21 15:38:55 +0000158typedef void (XMLCALL *XML_AttlistDeclHandler) (
159 void *userData,
160 const XML_Char *elname,
161 const XML_Char *attname,
162 const XML_Char *att_type,
163 const XML_Char *dflt,
164 int isrequired);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000165
166XMLPARSEAPI(void)
167XML_SetAttlistDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000168 XML_AttlistDeclHandler attdecl);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000169
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000170/* The XML declaration handler is called for *both* XML declarations
171 and text declarations. The way to distinguish is that the version
172 parameter will be NULL for text declarations. The encoding
173 parameter may be NULL for XML declarations. The standalone
174 parameter will be -1, 0, or 1 indicating respectively that there
175 was no standalone parameter in the declaration, that it was given
176 as no, or that it was given as yes.
177*/
Fred Drake08317ae2003-10-21 15:38:55 +0000178typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData,
179 const XML_Char *version,
180 const XML_Char *encoding,
181 int standalone);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000182
183XMLPARSEAPI(void)
184XML_SetXmlDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000185 XML_XmlDeclHandler xmldecl);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000186
187
188typedef struct {
Fred Drake31d485c2004-08-03 07:06:22 +0000189 void *(*malloc_fcn)(size_t size);
190 void *(*realloc_fcn)(void *ptr, size_t size);
191 void (*free_fcn)(void *ptr);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000192} XML_Memory_Handling_Suite;
193
194/* Constructs a new parser; encoding is the encoding specified by the
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000195 external protocol or NULL if there is none specified.
196*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000197XMLPARSEAPI(XML_Parser)
198XML_ParserCreate(const XML_Char *encoding);
199
200/* Constructs a new parser and namespace processor. Element type
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000201 names and attribute names that belong to a namespace will be
202 expanded; unprefixed attribute names are never expanded; unprefixed
203 element type names are expanded only if there is a default
204 namespace. The expanded name is the concatenation of the namespace
205 URI, the namespace separator character, and the local part of the
206 name. If the namespace separator is '\0' then the namespace URI
207 and the local part will be concatenated without any separator.
208 When a namespace is not declared, the name and prefix will be
209 passed through without expansion.
210*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000211XMLPARSEAPI(XML_Parser)
212XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
213
214
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000215/* Constructs a new parser using the memory management suite referred to
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000216 by memsuite. If memsuite is NULL, then use the standard library memory
217 suite. If namespaceSeparator is non-NULL it creates a parser with
218 namespace processing as described above. The character pointed at
219 will serve as the namespace separator.
220
221 All further memory operations used for the created parser will come from
222 the given suite.
223*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000224XMLPARSEAPI(XML_Parser)
225XML_ParserCreate_MM(const XML_Char *encoding,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000226 const XML_Memory_Handling_Suite *memsuite,
227 const XML_Char *namespaceSeparator);
228
229/* Prepare a parser object to be re-used. This is particularly
230 valuable when memory allocation overhead is disproportionatly high,
231 such as when a large number of small documnents need to be parsed.
232 All handlers are cleared from the parser, except for the
233 unknownEncodingHandler. The parser's external state is re-initialized
234 except for the values of ns and ns_triplets.
235
236 Added in Expat 1.95.3.
237*/
238XMLPARSEAPI(XML_Bool)
239XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000240
241/* atts is array of name/value pairs, terminated by 0;
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000242 names and values are 0 terminated.
243*/
Fred Drake08317ae2003-10-21 15:38:55 +0000244typedef void (XMLCALL *XML_StartElementHandler) (void *userData,
245 const XML_Char *name,
246 const XML_Char **atts);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000247
Fred Drake08317ae2003-10-21 15:38:55 +0000248typedef void (XMLCALL *XML_EndElementHandler) (void *userData,
249 const XML_Char *name);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000250
251
252/* s is not 0 terminated. */
Fred Drake08317ae2003-10-21 15:38:55 +0000253typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData,
254 const XML_Char *s,
255 int len);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000256
257/* target and data are 0 terminated */
Fred Drake08317ae2003-10-21 15:38:55 +0000258typedef void (XMLCALL *XML_ProcessingInstructionHandler) (
259 void *userData,
260 const XML_Char *target,
261 const XML_Char *data);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000262
263/* data is 0 terminated */
Fred Drake08317ae2003-10-21 15:38:55 +0000264typedef void (XMLCALL *XML_CommentHandler) (void *userData,
265 const XML_Char *data);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000266
Fred Drake08317ae2003-10-21 15:38:55 +0000267typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData);
268typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000269
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000270/* This is called for any characters in the XML document for which
271 there is no applicable handler. This includes both characters that
272 are part of markup which is of a kind that is not reported
273 (comments, markup declarations), or characters that are part of a
274 construct which could be reported but for which no handler has been
275 supplied. The characters are passed exactly as they were in the XML
276 document except that they will be encoded in UTF-8 or UTF-16.
277 Line boundaries are not normalized. Note that a byte order mark
278 character is not passed to the default handler. There are no
279 guarantees about how characters are divided between calls to the
280 default handler: for example, a comment might be split between
281 multiple calls.
282*/
Fred Drake08317ae2003-10-21 15:38:55 +0000283typedef void (XMLCALL *XML_DefaultHandler) (void *userData,
284 const XML_Char *s,
285 int len);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000286
287/* This is called for the start of the DOCTYPE declaration, before
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000288 any DTD or internal subset is parsed.
289*/
Fred Drake08317ae2003-10-21 15:38:55 +0000290typedef void (XMLCALL *XML_StartDoctypeDeclHandler) (
291 void *userData,
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000292 const XML_Char *doctypeName,
293 const XML_Char *sysid,
294 const XML_Char *pubid,
295 int has_internal_subset);
296
297/* This is called for the start of the DOCTYPE declaration when the
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000298 closing > is encountered, but after processing any external
299 subset.
300*/
Fred Drake08317ae2003-10-21 15:38:55 +0000301typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000302
303/* This is called for entity declarations. The is_parameter_entity
304 argument will be non-zero if the entity is a parameter entity, zero
305 otherwise.
306
307 For internal entities (<!ENTITY foo "bar">), value will
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000308 be non-NULL and systemId, publicID, and notationName will be NULL.
309 The value string is NOT nul-terminated; the length is provided in
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000310 the value_length argument. Since it is legal to have zero-length
311 values, do not use this argument to test for internal entities.
312
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000313 For external entities, value will be NULL and systemId will be
314 non-NULL. The publicId argument will be NULL unless a public
315 identifier was provided. The notationName argument will have a
316 non-NULL value only for unparsed entity declarations.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000317
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000318 Note that is_parameter_entity can't be changed to XML_Bool, since
319 that would break binary compatibility.
320*/
Fred Drake08317ae2003-10-21 15:38:55 +0000321typedef void (XMLCALL *XML_EntityDeclHandler) (
322 void *userData,
323 const XML_Char *entityName,
324 int is_parameter_entity,
325 const XML_Char *value,
326 int value_length,
327 const XML_Char *base,
328 const XML_Char *systemId,
329 const XML_Char *publicId,
330 const XML_Char *notationName);
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000331
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000332XMLPARSEAPI(void)
333XML_SetEntityDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000334 XML_EntityDeclHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000335
336/* OBSOLETE -- OBSOLETE -- OBSOLETE
337 This handler has been superceded by the EntityDeclHandler above.
338 It is provided here for backward compatibility.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000339
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000340 This is called for a declaration of an unparsed (NDATA) entity.
341 The base argument is whatever was set by XML_SetBase. The
342 entityName, systemId and notationName arguments will never be
343 NULL. The other arguments may be.
344*/
Fred Drake08317ae2003-10-21 15:38:55 +0000345typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) (
346 void *userData,
347 const XML_Char *entityName,
348 const XML_Char *base,
349 const XML_Char *systemId,
350 const XML_Char *publicId,
351 const XML_Char *notationName);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000352
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000353/* This is called for a declaration of notation. The base argument is
354 whatever was set by XML_SetBase. The notationName will never be
355 NULL. The other arguments can be.
356*/
Fred Drake08317ae2003-10-21 15:38:55 +0000357typedef void (XMLCALL *XML_NotationDeclHandler) (
358 void *userData,
359 const XML_Char *notationName,
360 const XML_Char *base,
361 const XML_Char *systemId,
362 const XML_Char *publicId);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000363
364/* When namespace processing is enabled, these are called once for
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000365 each namespace declaration. The call to the start and end element
366 handlers occur between the calls to the start and end namespace
367 declaration handlers. For an xmlns attribute, prefix will be
368 NULL. For an xmlns="" attribute, uri will be NULL.
369*/
Fred Drake08317ae2003-10-21 15:38:55 +0000370typedef void (XMLCALL *XML_StartNamespaceDeclHandler) (
371 void *userData,
372 const XML_Char *prefix,
373 const XML_Char *uri);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000374
Fred Drake08317ae2003-10-21 15:38:55 +0000375typedef void (XMLCALL *XML_EndNamespaceDeclHandler) (
376 void *userData,
377 const XML_Char *prefix);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000378
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000379/* This is called if the document is not standalone, that is, it has an
380 external subset or a reference to a parameter entity, but does not
381 have standalone="yes". If this handler returns XML_STATUS_ERROR,
382 then processing will not continue, and the parser will return a
383 XML_ERROR_NOT_STANDALONE error.
384 If parameter entity parsing is enabled, then in addition to the
385 conditions above this handler will only be called if the referenced
386 entity was actually read.
387*/
Fred Drake08317ae2003-10-21 15:38:55 +0000388typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000389
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000390/* This is called for a reference to an external parsed general
391 entity. The referenced entity is not automatically parsed. The
392 application can parse it immediately or later using
393 XML_ExternalEntityParserCreate.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000394
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000395 The parser argument is the parser parsing the entity containing the
396 reference; it can be passed as the parser argument to
397 XML_ExternalEntityParserCreate. The systemId argument is the
398 system identifier as specified in the entity declaration; it will
399 not be NULL.
400
401 The base argument is the system identifier that should be used as
402 the base for resolving systemId if systemId was relative; this is
403 set by XML_SetBase; it may be NULL.
404
405 The publicId argument is the public identifier as specified in the
406 entity declaration, or NULL if none was specified; the whitespace
407 in the public identifier will have been normalized as required by
408 the XML spec.
409
410 The context argument specifies the parsing context in the format
411 expected by the context argument to XML_ExternalEntityParserCreate;
412 context is valid only until the handler returns, so if the
413 referenced entity is to be parsed later, it must be copied.
414 context is NULL only when the entity is a parameter entity.
415
416 The handler should return XML_STATUS_ERROR if processing should not
417 continue because of a fatal error in the handling of the external
418 entity. In this case the calling parser will return an
419 XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
420
421 Note that unlike other handlers the first argument is the parser,
422 not userData.
423*/
Fred Drake08317ae2003-10-21 15:38:55 +0000424typedef int (XMLCALL *XML_ExternalEntityRefHandler) (
425 XML_Parser parser,
426 const XML_Char *context,
427 const XML_Char *base,
428 const XML_Char *systemId,
429 const XML_Char *publicId);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000430
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000431/* This is called in two situations:
432 1) An entity reference is encountered for which no declaration
433 has been read *and* this is not an error.
434 2) An internal entity reference is read, but not expanded, because
435 XML_SetDefaultHandler has been called.
436 Note: skipped parameter entities in declarations and skipped general
437 entities in attribute values cannot be reported, because
438 the event would be out of sync with the reporting of the
439 declarations or attribute values
440*/
Fred Drake08317ae2003-10-21 15:38:55 +0000441typedef void (XMLCALL *XML_SkippedEntityHandler) (
442 void *userData,
443 const XML_Char *entityName,
444 int is_parameter_entity);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000445
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000446/* This structure is filled in by the XML_UnknownEncodingHandler to
447 provide information to the parser about encodings that are unknown
448 to the parser.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000449
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000450 The map[b] member gives information about byte sequences whose
451 first byte is b.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000452
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000453 If map[b] is c where c is >= 0, then b by itself encodes the
454 Unicode scalar value c.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000455
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000456 If map[b] is -1, then the byte sequence is malformed.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000457
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000458 If map[b] is -n, where n >= 2, then b is the first byte of an
459 n-byte sequence that encodes a single Unicode scalar value.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000460
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000461 The data member will be passed as the first argument to the convert
462 function.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000463
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000464 The convert function is used to convert multibyte sequences; s will
465 point to a n-byte sequence where map[(unsigned char)*s] == -n. The
466 convert function must return the Unicode scalar value represented
467 by this byte sequence or -1 if the byte sequence is malformed.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000468
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000469 The convert function may be NULL if the encoding is a single-byte
470 encoding, that is if map[b] >= -1 for all bytes b.
471
472 When the parser is finished with the encoding, then if release is
473 not NULL, it will call release passing it the data member; once
474 release has been called, the convert function will not be called
475 again.
476
477 Expat places certain restrictions on the encodings that are supported
478 using this mechanism.
479
480 1. Every ASCII character that can appear in a well-formed XML document,
481 other than the characters
482
483 $@\^`{}~
484
485 must be represented by a single byte, and that byte must be the
486 same byte that represents that character in ASCII.
487
488 2. No character may require more than 4 bytes to encode.
489
490 3. All characters encoded must have Unicode scalar values <=
491 0xFFFF, (i.e., characters that would be encoded by surrogates in
492 UTF-16 are not allowed). Note that this restriction doesn't
493 apply to the built-in support for UTF-8 and UTF-16.
494
495 4. No Unicode character may be encoded by more than one distinct
496 sequence of bytes.
497*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000498typedef struct {
499 int map[256];
500 void *data;
Fred Drake08317ae2003-10-21 15:38:55 +0000501 int (XMLCALL *convert)(void *data, const char *s);
502 void (XMLCALL *release)(void *data);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000503} XML_Encoding;
504
505/* This is called for an encoding that is unknown to the parser.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000506
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000507 The encodingHandlerData argument is that which was passed as the
508 second argument to XML_SetUnknownEncodingHandler.
509
510 The name argument gives the name of the encoding as specified in
511 the encoding declaration.
512
513 If the callback can provide information about the encoding, it must
514 fill in the XML_Encoding structure, and return XML_STATUS_OK.
515 Otherwise it must return XML_STATUS_ERROR.
516
517 If info does not describe a suitable encoding, then the parser will
518 return an XML_UNKNOWN_ENCODING error.
519*/
Fred Drake08317ae2003-10-21 15:38:55 +0000520typedef int (XMLCALL *XML_UnknownEncodingHandler) (
521 void *encodingHandlerData,
522 const XML_Char *name,
523 XML_Encoding *info);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000524
525XMLPARSEAPI(void)
526XML_SetElementHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000527 XML_StartElementHandler start,
528 XML_EndElementHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000529
530XMLPARSEAPI(void)
Fred Drake31d485c2004-08-03 07:06:22 +0000531XML_SetStartElementHandler(XML_Parser parser,
532 XML_StartElementHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000533
534XMLPARSEAPI(void)
Fred Drake31d485c2004-08-03 07:06:22 +0000535XML_SetEndElementHandler(XML_Parser parser,
536 XML_EndElementHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000537
538XMLPARSEAPI(void)
539XML_SetCharacterDataHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000540 XML_CharacterDataHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000541
542XMLPARSEAPI(void)
543XML_SetProcessingInstructionHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000544 XML_ProcessingInstructionHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000545XMLPARSEAPI(void)
546XML_SetCommentHandler(XML_Parser parser,
547 XML_CommentHandler handler);
548
549XMLPARSEAPI(void)
550XML_SetCdataSectionHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000551 XML_StartCdataSectionHandler start,
552 XML_EndCdataSectionHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000553
554XMLPARSEAPI(void)
555XML_SetStartCdataSectionHandler(XML_Parser parser,
556 XML_StartCdataSectionHandler start);
557
558XMLPARSEAPI(void)
559XML_SetEndCdataSectionHandler(XML_Parser parser,
560 XML_EndCdataSectionHandler end);
561
562/* This sets the default handler and also inhibits expansion of
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000563 internal entities. These entity references will be passed to the
564 default handler, or to the skipped entity handler, if one is set.
565*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000566XMLPARSEAPI(void)
567XML_SetDefaultHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000568 XML_DefaultHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000569
570/* This sets the default handler but does not inhibit expansion of
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000571 internal entities. The entity reference will not be passed to the
572 default handler.
573*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000574XMLPARSEAPI(void)
575XML_SetDefaultHandlerExpand(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
578XMLPARSEAPI(void)
579XML_SetDoctypeDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000580 XML_StartDoctypeDeclHandler start,
581 XML_EndDoctypeDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000582
583XMLPARSEAPI(void)
584XML_SetStartDoctypeDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000585 XML_StartDoctypeDeclHandler start);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000586
587XMLPARSEAPI(void)
588XML_SetEndDoctypeDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000589 XML_EndDoctypeDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000590
591XMLPARSEAPI(void)
592XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000593 XML_UnparsedEntityDeclHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000594
595XMLPARSEAPI(void)
596XML_SetNotationDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000597 XML_NotationDeclHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000598
599XMLPARSEAPI(void)
600XML_SetNamespaceDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000601 XML_StartNamespaceDeclHandler start,
602 XML_EndNamespaceDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000603
604XMLPARSEAPI(void)
605XML_SetStartNamespaceDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000606 XML_StartNamespaceDeclHandler start);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000607
608XMLPARSEAPI(void)
609XML_SetEndNamespaceDeclHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000610 XML_EndNamespaceDeclHandler end);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000611
612XMLPARSEAPI(void)
613XML_SetNotStandaloneHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000614 XML_NotStandaloneHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000615
616XMLPARSEAPI(void)
617XML_SetExternalEntityRefHandler(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000618 XML_ExternalEntityRefHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000619
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000620/* If a non-NULL value for arg is specified here, then it will be
621 passed as the first argument to the external entity ref handler
622 instead of the parser object.
623*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000624XMLPARSEAPI(void)
Fred Drake31d485c2004-08-03 07:06:22 +0000625XML_SetExternalEntityRefHandlerArg(XML_Parser parser,
626 void *arg);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000627
628XMLPARSEAPI(void)
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000629XML_SetSkippedEntityHandler(XML_Parser parser,
630 XML_SkippedEntityHandler handler);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000631
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000632XMLPARSEAPI(void)
633XML_SetUnknownEncodingHandler(XML_Parser parser,
634 XML_UnknownEncodingHandler handler,
635 void *encodingHandlerData);
636
637/* This can be called within a handler for a start element, end
638 element, processing instruction or character data. It causes the
639 corresponding markup to be passed to the default handler.
640*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000641XMLPARSEAPI(void)
642XML_DefaultCurrent(XML_Parser parser);
643
644/* If do_nst is non-zero, and namespace processing is in effect, and
645 a name has a prefix (i.e. an explicit namespace qualifier) then
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000646 that name is returned as a triplet in a single string separated by
647 the separator character specified when the parser was created: URI
648 + sep + local_name + sep + prefix.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000649
650 If do_nst is zero, then namespace information is returned in the
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000651 default manner (URI + sep + local_name) whether or not the name
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000652 has a prefix.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000653
654 Note: Calling XML_SetReturnNSTriplet after XML_Parse or
655 XML_ParseBuffer has no effect.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000656*/
657
658XMLPARSEAPI(void)
659XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
660
661/* This value is passed as the userData argument to callbacks. */
662XMLPARSEAPI(void)
663XML_SetUserData(XML_Parser parser, void *userData);
664
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000665/* Returns the last value set by XML_SetUserData or NULL. */
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000666#define XML_GetUserData(parser) (*(void **)(parser))
667
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000668/* This is equivalent to supplying an encoding argument to
669 XML_ParserCreate. On success XML_SetEncoding returns non-zero,
670 zero otherwise.
671 Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
672 has no effect and returns XML_STATUS_ERROR.
673*/
674XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000675XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
676
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000677/* If this function is called, then the parser will be passed as the
678 first argument to callbacks instead of userData. The userData will
679 still be accessible using XML_GetUserData.
680*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000681XMLPARSEAPI(void)
682XML_UseParserAsHandlerArg(XML_Parser parser);
683
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000684/* If useDTD == XML_TRUE is passed to this function, then the parser
685 will assume that there is an external subset, even if none is
686 specified in the document. In such a case the parser will call the
687 externalEntityRefHandler with a value of NULL for the systemId
688 argument (the publicId and context arguments will be NULL as well).
Fred Drake31d485c2004-08-03 07:06:22 +0000689 Note: For the purpose of checking WFC: Entity Declared, passing
690 useDTD == XML_TRUE will make the parser behave as if the document
691 had a DTD with an external subset.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000692 Note: If this function is called, then this must be done before
693 the first call to XML_Parse or XML_ParseBuffer, since it will
694 have no effect after that. Returns
695 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
696 Note: If the document does not have a DOCTYPE declaration at all,
697 then startDoctypeDeclHandler and endDoctypeDeclHandler will not
698 be called, despite an external subset being parsed.
699 Note: If XML_DTD is not defined when Expat is compiled, returns
700 XML_ERROR_FEATURE_REQUIRES_XML_DTD.
701*/
702XMLPARSEAPI(enum XML_Error)
703XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000704
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000705
706/* Sets the base to be used for resolving relative URIs in system
707 identifiers in declarations. Resolving relative identifiers is
708 left to the application: this value will be passed through as the
709 base argument to the XML_ExternalEntityRefHandler,
710 XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
711 argument will be copied. Returns XML_STATUS_ERROR if out of memory,
712 XML_STATUS_OK otherwise.
713*/
714XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000715XML_SetBase(XML_Parser parser, const XML_Char *base);
716
717XMLPARSEAPI(const XML_Char *)
718XML_GetBase(XML_Parser parser);
719
720/* Returns the number of the attribute/value pairs passed in last call
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000721 to the XML_StartElementHandler that were specified in the start-tag
722 rather than defaulted. Each attribute/value pair counts as 2; thus
723 this correspondds to an index into the atts array passed to the
724 XML_StartElementHandler.
725*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000726XMLPARSEAPI(int)
727XML_GetSpecifiedAttributeCount(XML_Parser parser);
728
729/* Returns the index of the ID attribute passed in the last call to
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000730 XML_StartElementHandler, or -1 if there is no ID attribute. Each
731 attribute/value pair counts as 2; thus this correspondds to an
732 index into the atts array passed to the XML_StartElementHandler.
733*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000734XMLPARSEAPI(int)
735XML_GetIdAttributeIndex(XML_Parser parser);
736
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000737/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
738 detected. The last call to XML_Parse must have isFinal true; len
739 may be zero for this call (or any other).
740
Fred Drakedab8b0a2003-02-07 02:15:56 +0000741 Though the return values for these functions has always been
742 described as a Boolean value, the implementation, at least for the
743 1.95.x series, has always returned exactly one of the XML_Status
744 values.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000745*/
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000746XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000747XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
748
749XMLPARSEAPI(void *)
750XML_GetBuffer(XML_Parser parser, int len);
751
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000752XMLPARSEAPI(enum XML_Status)
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000753XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
754
Fred Drake31d485c2004-08-03 07:06:22 +0000755/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
756 Must be called from within a call-back handler, except when aborting
757 (resumable = 0) an already suspended parser. Some call-backs may
758 still follow because they would otherwise get lost. Examples:
759 - endElementHandler() for empty elements when stopped in
760 startElementHandler(),
761 - endNameSpaceDeclHandler() when stopped in endElementHandler(),
762 and possibly others.
763
764 Can be called from most handlers, including DTD related call-backs,
765 except when parsing an external parameter entity and resumable != 0.
766 Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
767 Possible error codes:
768 - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
769 - XML_ERROR_FINISHED: when the parser has already finished.
770 - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
771
772 When resumable != 0 (true) then parsing is suspended, that is,
773 XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
774 Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
775 return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
776
777 *Note*:
778 This will be applied to the current parser instance only, that is, if
779 there is a parent parser then it will continue parsing when the
780 externalEntityRefHandler() returns. It is up to the implementation of
781 the externalEntityRefHandler() to call XML_StopParser() on the parent
782 parser (recursively), if one wants to stop parsing altogether.
783
784 When suspended, parsing can be resumed by calling XML_ResumeParser().
785*/
786XMLPARSEAPI(enum XML_Status)
787XML_StopParser(XML_Parser parser, XML_Bool resumable);
788
789/* Resumes parsing after it has been suspended with XML_StopParser().
790 Must not be called from within a handler call-back. Returns same
791 status codes as XML_Parse() or XML_ParseBuffer().
792 Additional error code XML_ERROR_NOT_SUSPENDED possible.
793
794 *Note*:
795 This must be called on the most deeply nested child parser instance
796 first, and on its parent parser only after the child parser has finished,
797 to be applied recursively until the document entity's parser is restarted.
798 That is, the parent parser will not resume by itself and it is up to the
799 application to call XML_ResumeParser() on it at the appropriate moment.
800*/
801XMLPARSEAPI(enum XML_Status)
802XML_ResumeParser(XML_Parser parser);
803
804enum XML_Parsing {
805 XML_INITIALIZED,
806 XML_PARSING,
807 XML_FINISHED,
808 XML_SUSPENDED
809};
810
811typedef struct {
812 enum XML_Parsing parsing;
813 XML_Bool finalBuffer;
814} XML_ParsingStatus;
815
816/* Returns status of parser with respect to being initialized, parsing,
817 finished, or suspended and processing the final buffer.
818 XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
819 XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
820*/
821XMLPARSEAPI(void)
822XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
823
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000824/* Creates an XML_Parser object that can parse an external general
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000825 entity; context is a '\0'-terminated string specifying the parse
826 context; encoding is a '\0'-terminated string giving the name of
827 the externally specified encoding, or NULL if there is no
828 externally specified encoding. The context string consists of a
829 sequence of tokens separated by formfeeds (\f); a token consisting
830 of a name specifies that the general entity of the name is open; a
831 token of the form prefix=uri specifies the namespace for a
832 particular prefix; a token of the form =uri specifies the default
833 namespace. This can be called at any point after the first call to
834 an ExternalEntityRefHandler so longer as the parser has not yet
835 been freed. The new parser is completely independent and may
836 safely be used in a separate thread. The handlers and userData are
837 initialized from the parser argument. Returns NULL if out of memory.
838 Otherwise returns a new XML_Parser object.
839*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000840XMLPARSEAPI(XML_Parser)
841XML_ExternalEntityParserCreate(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000842 const XML_Char *context,
843 const XML_Char *encoding);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000844
845enum XML_ParamEntityParsing {
846 XML_PARAM_ENTITY_PARSING_NEVER,
847 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
848 XML_PARAM_ENTITY_PARSING_ALWAYS
849};
850
851/* Controls parsing of parameter entities (including the external DTD
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000852 subset). If parsing of parameter entities is enabled, then
853 references to external parameter entities (including the external
854 DTD subset) will be passed to the handler set with
855 XML_SetExternalEntityRefHandler. The context passed will be 0.
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000856
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000857 Unlike external general entities, external parameter entities can
858 only be parsed synchronously. If the external parameter entity is
859 to be parsed, it must be parsed during the call to the external
860 entity ref handler: the complete sequence of
861 XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
862 XML_ParserFree calls must be made during this call. After
863 XML_ExternalEntityParserCreate has been called to create the parser
864 for the external parameter entity (context must be 0 for this
865 call), it is illegal to make any calls on the old parser until
866 XML_ParserFree has been called on the newly created parser.
867 If the library has been compiled without support for parameter
868 entity parsing (ie without XML_DTD being defined), then
869 XML_SetParamEntityParsing will return 0 if parsing of parameter
870 entities is requested; otherwise it will return non-zero.
871 Note: If XML_SetParamEntityParsing is called after XML_Parse or
872 XML_ParseBuffer, then it has no effect and will always return 0.
873*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000874XMLPARSEAPI(int)
875XML_SetParamEntityParsing(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000876 enum XML_ParamEntityParsing parsing);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000877
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000878/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
879 XML_GetErrorCode returns information about the error.
880*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000881XMLPARSEAPI(enum XML_Error)
882XML_GetErrorCode(XML_Parser parser);
883
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000884/* These functions return information about the current parse
885 location. They may be called from any callback called to report
Fred Drake08317ae2003-10-21 15:38:55 +0000886 some parse event; in this case the location is the location of the
887 first of the sequence of characters that generated the event. When
888 called from callbacks generated by declarations in the document
889 prologue, the location identified isn't as neatly defined, but will
890 be within the relevant markup. When called outside of the callback
891 functions, the position indicated will be just past the last parse
892 event (regardless of whether there was an associated callback).
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000893
894 They may also be called after returning from a call to XML_Parse
895 or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then
896 the location is the location of the character at which the error
897 was detected; otherwise the location is the location of the last
898 parse event, as described above.
899*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000900XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser);
901XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser);
902XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser);
903
904/* Return the number of bytes in the current event.
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000905 Returns 0 if the event is in an internal entity.
906*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000907XMLPARSEAPI(int)
908XML_GetCurrentByteCount(XML_Parser parser);
909
910/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
911 the integer pointed to by offset to the offset within this buffer
912 of the current parse position, and sets the integer pointed to by size
913 to the size of this buffer (the number of input bytes). Otherwise
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000914 returns a NULL pointer. Also returns a NULL pointer if a parse isn't
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000915 active.
916
917 NOTE: The character pointer returned should not be used outside
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000918 the handler that makes the call.
919*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000920XMLPARSEAPI(const char *)
921XML_GetInputContext(XML_Parser parser,
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000922 int *offset,
923 int *size);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000924
925/* For backwards compatibility with previous versions. */
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000926#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000927#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000928#define XML_GetErrorByteIndex XML_GetCurrentByteIndex
929
930/* Frees the content model passed to the element declaration handler */
931XMLPARSEAPI(void)
932XML_FreeContentModel(XML_Parser parser, XML_Content *model);
933
934/* Exposing the memory handling functions used in Expat */
935XMLPARSEAPI(void *)
936XML_MemMalloc(XML_Parser parser, size_t size);
937
938XMLPARSEAPI(void *)
939XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
940
941XMLPARSEAPI(void)
942XML_MemFree(XML_Parser parser, void *ptr);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000943
944/* Frees memory used by the parser. */
945XMLPARSEAPI(void)
946XML_ParserFree(XML_Parser parser);
947
948/* Returns a string describing the error. */
949XMLPARSEAPI(const XML_LChar *)
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000950XML_ErrorString(enum XML_Error code);
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000951
952/* Return a string containing the version number of this expat */
953XMLPARSEAPI(const XML_LChar *)
954XML_ExpatVersion(void);
955
956typedef struct {
957 int major;
958 int minor;
959 int micro;
960} XML_Expat_Version;
961
962/* Return an XML_Expat_Version structure containing numeric version
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000963 number information for this version of expat.
964*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000965XMLPARSEAPI(XML_Expat_Version)
966XML_ExpatVersionInfo(void);
967
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000968/* Added in Expat 1.95.5. */
969enum XML_FeatureEnum {
970 XML_FEATURE_END = 0,
971 XML_FEATURE_UNICODE,
972 XML_FEATURE_UNICODE_WCHAR_T,
973 XML_FEATURE_DTD,
974 XML_FEATURE_CONTEXT_BYTES,
975 XML_FEATURE_MIN_SIZE,
976 XML_FEATURE_SIZEOF_XML_CHAR,
977 XML_FEATURE_SIZEOF_XML_LCHAR
978 /* Additional features must be added to the end of this enum. */
979};
Martin v. Löwis8fef47b2002-02-13 07:47:16 +0000980
Martin v. Löwisfc03a942003-01-25 22:41:29 +0000981typedef struct {
982 enum XML_FeatureEnum feature;
983 const XML_LChar *name;
984 long int value;
985} XML_Feature;
986
987XMLPARSEAPI(const XML_Feature *)
988XML_GetFeatureList(void);
989
990
991/* Expat follows the GNU/Linux convention of odd number minor version for
992 beta/development releases and even number minor version for stable
993 releases. Micro is bumped with each release, and set to 0 with each
994 change to major or minor version.
995*/
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000996#define XML_MAJOR_VERSION 1
997#define XML_MINOR_VERSION 95
Fred Drake31d485c2004-08-03 07:06:22 +0000998#define XML_MICRO_VERSION 8
Martin v. Löwisb48d1982002-02-12 09:52:22 +0000999
1000#ifdef __cplusplus
1001}
1002#endif
1003
1004#endif /* not XmlParse_INCLUDED */