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