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