Merge trunk head (r43756)
[reactos.git] / reactos / include / reactos / libs / libxml / parser.h
1 /*
2 * Summary: the core parser module
3 * Description: Interfaces, constants and types related to the XML parser
4 *
5 * Copy: See Copyright for the status of this software.
6 *
7 * Author: Daniel Veillard
8 */
9
10 #ifndef __XML_PARSER_H__
11 #define __XML_PARSER_H__
12
13 #include <stdarg.h>
14
15 #include <libxml/xmlversion.h>
16 #include <libxml/tree.h>
17 #include <libxml/dict.h>
18 #include <libxml/hash.h>
19 #include <libxml/valid.h>
20 #include <libxml/entities.h>
21 #include <libxml/xmlerror.h>
22 #include <libxml/xmlstring.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /**
29 * XML_DEFAULT_VERSION:
30 *
31 * The default version of XML used: 1.0
32 */
33 #define XML_DEFAULT_VERSION "1.0"
34
35 /**
36 * xmlParserInput:
37 *
38 * An xmlParserInput is an input flow for the XML processor.
39 * Each entity parsed is associated an xmlParserInput (except the
40 * few predefined ones). This is the case both for internal entities
41 * - in which case the flow is already completely in memory - or
42 * external entities - in which case we use the buf structure for
43 * progressive reading and I18N conversions to the internal UTF-8 format.
44 */
45
46 /**
47 * xmlParserInputDeallocate:
48 * @str: the string to deallocate
49 *
50 * Callback for freeing some parser input allocations.
51 */
52 typedef void (* xmlParserInputDeallocate)(xmlChar *str);
53
54 struct _xmlParserInput {
55 /* Input buffer */
56 xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */
57
58 const char *filename; /* The file analyzed, if any */
59 const char *directory; /* the directory/base of the file */
60 const xmlChar *base; /* Base of the array to parse */
61 const xmlChar *cur; /* Current char being parsed */
62 const xmlChar *end; /* end of the array to parse */
63 int length; /* length if known */
64 int line; /* Current line */
65 int col; /* Current column */
66 /*
67 * NOTE: consumed is only tested for equality in the parser code,
68 * so even if there is an overflow this should not give troubles
69 * for parsing very large instances.
70 */
71 unsigned long consumed; /* How many xmlChars already consumed */
72 xmlParserInputDeallocate free; /* function to deallocate the base */
73 const xmlChar *encoding; /* the encoding string for entity */
74 const xmlChar *version; /* the version string for entity */
75 int standalone; /* Was that entity marked standalone */
76 int id; /* an unique identifier for the entity */
77 };
78
79 /**
80 * xmlParserNodeInfo:
81 *
82 * The parser can be asked to collect Node informations, i.e. at what
83 * place in the file they were detected.
84 * NOTE: This is off by default and not very well tested.
85 */
86 typedef struct _xmlParserNodeInfo xmlParserNodeInfo;
87 typedef xmlParserNodeInfo *xmlParserNodeInfoPtr;
88
89 struct _xmlParserNodeInfo {
90 const struct _xmlNode* node;
91 /* Position & line # that text that created the node begins & ends on */
92 unsigned long begin_pos;
93 unsigned long begin_line;
94 unsigned long end_pos;
95 unsigned long end_line;
96 };
97
98 typedef struct _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
99 typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
100 struct _xmlParserNodeInfoSeq {
101 unsigned long maximum;
102 unsigned long length;
103 xmlParserNodeInfo* buffer;
104 };
105
106 /**
107 * xmlParserInputState:
108 *
109 * The parser is now working also as a state based parser.
110 * The recursive one use the state info for entities processing.
111 */
112 typedef enum {
113 XML_PARSER_EOF = -1, /* nothing is to be parsed */
114 XML_PARSER_START = 0, /* nothing has been parsed */
115 XML_PARSER_MISC, /* Misc* before int subset */
116 XML_PARSER_PI, /* Within a processing instruction */
117 XML_PARSER_DTD, /* within some DTD content */
118 XML_PARSER_PROLOG, /* Misc* after internal subset */
119 XML_PARSER_COMMENT, /* within a comment */
120 XML_PARSER_START_TAG, /* within a start tag */
121 XML_PARSER_CONTENT, /* within the content */
122 XML_PARSER_CDATA_SECTION, /* within a CDATA section */
123 XML_PARSER_END_TAG, /* within a closing tag */
124 XML_PARSER_ENTITY_DECL, /* within an entity declaration */
125 XML_PARSER_ENTITY_VALUE, /* within an entity value in a decl */
126 XML_PARSER_ATTRIBUTE_VALUE, /* within an attribute value */
127 XML_PARSER_SYSTEM_LITERAL, /* within a SYSTEM value */
128 XML_PARSER_EPILOG, /* the Misc* after the last end tag */
129 XML_PARSER_IGNORE, /* within an IGNORED section */
130 XML_PARSER_PUBLIC_LITERAL /* within a PUBLIC value */
131 } xmlParserInputState;
132
133 /**
134 * XML_DETECT_IDS:
135 *
136 * Bit in the loadsubset context field to tell to do ID/REFs lookups.
137 * Use it to initialize xmlLoadExtDtdDefaultValue.
138 */
139 #define XML_DETECT_IDS 2
140
141 /**
142 * XML_COMPLETE_ATTRS:
143 *
144 * Bit in the loadsubset context field to tell to do complete the
145 * elements attributes lists with the ones defaulted from the DTDs.
146 * Use it to initialize xmlLoadExtDtdDefaultValue.
147 */
148 #define XML_COMPLETE_ATTRS 4
149
150 /**
151 * XML_SKIP_IDS:
152 *
153 * Bit in the loadsubset context field to tell to not do ID/REFs registration.
154 * Used to initialize xmlLoadExtDtdDefaultValue in some special cases.
155 */
156 #define XML_SKIP_IDS 8
157
158 /**
159 * xmlParserMode:
160 *
161 * A parser can operate in various modes
162 */
163 typedef enum {
164 XML_PARSE_UNKNOWN = 0,
165 XML_PARSE_DOM = 1,
166 XML_PARSE_SAX = 2,
167 XML_PARSE_PUSH_DOM = 3,
168 XML_PARSE_PUSH_SAX = 4,
169 XML_PARSE_READER = 5
170 } xmlParserMode;
171
172 /**
173 * xmlParserCtxt:
174 *
175 * The parser context.
176 * NOTE This doesn't completely define the parser state, the (current ?)
177 * design of the parser uses recursive function calls since this allow
178 * and easy mapping from the production rules of the specification
179 * to the actual code. The drawback is that the actual function call
180 * also reflect the parser state. However most of the parsing routines
181 * takes as the only argument the parser context pointer, so migrating
182 * to a state based parser for progressive parsing shouldn't be too hard.
183 */
184 struct _xmlParserCtxt {
185 struct _xmlSAXHandler *sax; /* The SAX handler */
186 void *userData; /* For SAX interface only, used by DOM build */
187 xmlDocPtr myDoc; /* the document being built */
188 int wellFormed; /* is the document well formed */
189 int replaceEntities; /* shall we replace entities ? */
190 const xmlChar *version; /* the XML version string */
191 const xmlChar *encoding; /* the declared encoding, if any */
192 int standalone; /* standalone document */
193 int html; /* an HTML(1)/Docbook(2) document
194 * 3 is HTML after <head>
195 * 10 is HTML after <body>
196 */
197
198 /* Input stream stack */
199 xmlParserInputPtr input; /* Current input stream */
200 int inputNr; /* Number of current input streams */
201 int inputMax; /* Max number of input streams */
202 xmlParserInputPtr *inputTab; /* stack of inputs */
203
204 /* Node analysis stack only used for DOM building */
205 xmlNodePtr node; /* Current parsed Node */
206 int nodeNr; /* Depth of the parsing stack */
207 int nodeMax; /* Max depth of the parsing stack */
208 xmlNodePtr *nodeTab; /* array of nodes */
209
210 int record_info; /* Whether node info should be kept */
211 xmlParserNodeInfoSeq node_seq; /* info about each node parsed */
212
213 int errNo; /* error code */
214
215 int hasExternalSubset; /* reference and external subset */
216 int hasPErefs; /* the internal subset has PE refs */
217 int external; /* are we parsing an external entity */
218
219 int valid; /* is the document valid */
220 int validate; /* shall we try to validate ? */
221 xmlValidCtxt vctxt; /* The validity context */
222
223 xmlParserInputState instate; /* current type of input */
224 int token; /* next char look-ahead */
225
226 char *directory; /* the data directory */
227
228 /* Node name stack */
229 const xmlChar *name; /* Current parsed Node */
230 int nameNr; /* Depth of the parsing stack */
231 int nameMax; /* Max depth of the parsing stack */
232 const xmlChar * *nameTab; /* array of nodes */
233
234 long nbChars; /* number of xmlChar processed */
235 long checkIndex; /* used by progressive parsing lookup */
236 int keepBlanks; /* ugly but ... */
237 int disableSAX; /* SAX callbacks are disabled */
238 int inSubset; /* Parsing is in int 1/ext 2 subset */
239 const xmlChar * intSubName; /* name of subset */
240 xmlChar * extSubURI; /* URI of external subset */
241 xmlChar * extSubSystem; /* SYSTEM ID of external subset */
242
243 /* xml:space values */
244 int * space; /* Should the parser preserve spaces */
245 int spaceNr; /* Depth of the parsing stack */
246 int spaceMax; /* Max depth of the parsing stack */
247 int * spaceTab; /* array of space infos */
248
249 int depth; /* to prevent entity substitution loops */
250 xmlParserInputPtr entity; /* used to check entities boundaries */
251 int charset; /* encoding of the in-memory content
252 actually an xmlCharEncoding */
253 int nodelen; /* Those two fields are there to */
254 int nodemem; /* Speed up large node parsing */
255 int pedantic; /* signal pedantic warnings */
256 void *_private; /* For user data, libxml won't touch it */
257
258 int loadsubset; /* should the external subset be loaded */
259 int linenumbers; /* set line number in element content */
260 void *catalogs; /* document's own catalog */
261 int recovery; /* run in recovery mode */
262 int progressive; /* is this a progressive parsing */
263 xmlDictPtr dict; /* dictionnary for the parser */
264 const xmlChar * *atts; /* array for the attributes callbacks */
265 int maxatts; /* the size of the array */
266 int docdict; /* use strings from dict to build tree */
267
268 /*
269 * pre-interned strings
270 */
271 const xmlChar *str_xml;
272 const xmlChar *str_xmlns;
273 const xmlChar *str_xml_ns;
274
275 /*
276 * Everything below is used only by the new SAX mode
277 */
278 int sax2; /* operating in the new SAX mode */
279 int nsNr; /* the number of inherited namespaces */
280 int nsMax; /* the size of the arrays */
281 const xmlChar * *nsTab; /* the array of prefix/namespace name */
282 int *attallocs; /* which attribute were allocated */
283 void * *pushTab; /* array of data for push */
284 xmlHashTablePtr attsDefault; /* defaulted attributes if any */
285 xmlHashTablePtr attsSpecial; /* non-CDATA attributes if any */
286 int nsWellFormed; /* is the document XML Nanespace okay */
287 int options; /* Extra options */
288
289 /*
290 * Those fields are needed only for treaming parsing so far
291 */
292 int dictNames; /* Use dictionary names for the tree */
293 int freeElemsNr; /* number of freed element nodes */
294 xmlNodePtr freeElems; /* List of freed element nodes */
295 int freeAttrsNr; /* number of freed attributes nodes */
296 xmlAttrPtr freeAttrs; /* List of freed attributes nodes */
297
298 /*
299 * the complete error informations for the last error.
300 */
301 xmlError lastError;
302 xmlParserMode parseMode; /* the parser mode */
303 unsigned long nbentities; /* number of entities references */
304 unsigned long sizeentities; /* size of parsed entities */
305 };
306
307 /**
308 * xmlSAXLocator:
309 *
310 * A SAX Locator.
311 */
312 struct _xmlSAXLocator {
313 const xmlChar *(*getPublicId)(void *ctx);
314 const xmlChar *(*getSystemId)(void *ctx);
315 int (*getLineNumber)(void *ctx);
316 int (*getColumnNumber)(void *ctx);
317 };
318
319 /**
320 * xmlSAXHandler:
321 *
322 * A SAX handler is bunch of callbacks called by the parser when processing
323 * of the input generate data or structure informations.
324 */
325
326 /**
327 * resolveEntitySAXFunc:
328 * @ctx: the user data (XML parser context)
329 * @publicId: The public ID of the entity
330 * @systemId: The system ID of the entity
331 *
332 * Callback:
333 * The entity loader, to control the loading of external entities,
334 * the application can either:
335 * - override this resolveEntity() callback in the SAX block
336 * - or better use the xmlSetExternalEntityLoader() function to
337 * set up it's own entity resolution routine
338 *
339 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
340 */
341 typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx,
342 const xmlChar *publicId,
343 const xmlChar *systemId);
344 /**
345 * internalSubsetSAXFunc:
346 * @ctx: the user data (XML parser context)
347 * @name: the root element name
348 * @ExternalID: the external ID
349 * @SystemID: the SYSTEM ID (e.g. filename or URL)
350 *
351 * Callback on internal subset declaration.
352 */
353 typedef void (*internalSubsetSAXFunc) (void *ctx,
354 const xmlChar *name,
355 const xmlChar *ExternalID,
356 const xmlChar *SystemID);
357 /**
358 * externalSubsetSAXFunc:
359 * @ctx: the user data (XML parser context)
360 * @name: the root element name
361 * @ExternalID: the external ID
362 * @SystemID: the SYSTEM ID (e.g. filename or URL)
363 *
364 * Callback on external subset declaration.
365 */
366 typedef void (*externalSubsetSAXFunc) (void *ctx,
367 const xmlChar *name,
368 const xmlChar *ExternalID,
369 const xmlChar *SystemID);
370 /**
371 * getEntitySAXFunc:
372 * @ctx: the user data (XML parser context)
373 * @name: The entity name
374 *
375 * Get an entity by name.
376 *
377 * Returns the xmlEntityPtr if found.
378 */
379 typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx,
380 const xmlChar *name);
381 /**
382 * getParameterEntitySAXFunc:
383 * @ctx: the user data (XML parser context)
384 * @name: The entity name
385 *
386 * Get a parameter entity by name.
387 *
388 * Returns the xmlEntityPtr if found.
389 */
390 typedef xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx,
391 const xmlChar *name);
392 /**
393 * entityDeclSAXFunc:
394 * @ctx: the user data (XML parser context)
395 * @name: the entity name
396 * @type: the entity type
397 * @publicId: The public ID of the entity
398 * @systemId: The system ID of the entity
399 * @content: the entity value (without processing).
400 *
401 * An entity definition has been parsed.
402 */
403 typedef void (*entityDeclSAXFunc) (void *ctx,
404 const xmlChar *name,
405 int type,
406 const xmlChar *publicId,
407 const xmlChar *systemId,
408 xmlChar *content);
409 /**
410 * notationDeclSAXFunc:
411 * @ctx: the user data (XML parser context)
412 * @name: The name of the notation
413 * @publicId: The public ID of the entity
414 * @systemId: The system ID of the entity
415 *
416 * What to do when a notation declaration has been parsed.
417 */
418 typedef void (*notationDeclSAXFunc)(void *ctx,
419 const xmlChar *name,
420 const xmlChar *publicId,
421 const xmlChar *systemId);
422 /**
423 * attributeDeclSAXFunc:
424 * @ctx: the user data (XML parser context)
425 * @elem: the name of the element
426 * @fullname: the attribute name
427 * @type: the attribute type
428 * @def: the type of default value
429 * @defaultValue: the attribute default value
430 * @tree: the tree of enumerated value set
431 *
432 * An attribute definition has been parsed.
433 */
434 typedef void (*attributeDeclSAXFunc)(void *ctx,
435 const xmlChar *elem,
436 const xmlChar *fullname,
437 int type,
438 int def,
439 const xmlChar *defaultValue,
440 xmlEnumerationPtr tree);
441 /**
442 * elementDeclSAXFunc:
443 * @ctx: the user data (XML parser context)
444 * @name: the element name
445 * @type: the element type
446 * @content: the element value tree
447 *
448 * An element definition has been parsed.
449 */
450 typedef void (*elementDeclSAXFunc)(void *ctx,
451 const xmlChar *name,
452 int type,
453 xmlElementContentPtr content);
454 /**
455 * unparsedEntityDeclSAXFunc:
456 * @ctx: the user data (XML parser context)
457 * @name: The name of the entity
458 * @publicId: The public ID of the entity
459 * @systemId: The system ID of the entity
460 * @notationName: the name of the notation
461 *
462 * What to do when an unparsed entity declaration is parsed.
463 */
464 typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
465 const xmlChar *name,
466 const xmlChar *publicId,
467 const xmlChar *systemId,
468 const xmlChar *notationName);
469 /**
470 * setDocumentLocatorSAXFunc:
471 * @ctx: the user data (XML parser context)
472 * @loc: A SAX Locator
473 *
474 * Receive the document locator at startup, actually xmlDefaultSAXLocator.
475 * Everything is available on the context, so this is useless in our case.
476 */
477 typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
478 xmlSAXLocatorPtr loc);
479 /**
480 * startDocumentSAXFunc:
481 * @ctx: the user data (XML parser context)
482 *
483 * Called when the document start being processed.
484 */
485 typedef void (*startDocumentSAXFunc) (void *ctx);
486 /**
487 * endDocumentSAXFunc:
488 * @ctx: the user data (XML parser context)
489 *
490 * Called when the document end has been detected.
491 */
492 typedef void (*endDocumentSAXFunc) (void *ctx);
493 /**
494 * startElementSAXFunc:
495 * @ctx: the user data (XML parser context)
496 * @name: The element name, including namespace prefix
497 * @atts: An array of name/value attributes pairs, NULL terminated
498 *
499 * Called when an opening tag has been processed.
500 */
501 typedef void (*startElementSAXFunc) (void *ctx,
502 const xmlChar *name,
503 const xmlChar **atts);
504 /**
505 * endElementSAXFunc:
506 * @ctx: the user data (XML parser context)
507 * @name: The element name
508 *
509 * Called when the end of an element has been detected.
510 */
511 typedef void (*endElementSAXFunc) (void *ctx,
512 const xmlChar *name);
513 /**
514 * attributeSAXFunc:
515 * @ctx: the user data (XML parser context)
516 * @name: The attribute name, including namespace prefix
517 * @value: The attribute value
518 *
519 * Handle an attribute that has been read by the parser.
520 * The default handling is to convert the attribute into an
521 * DOM subtree and past it in a new xmlAttr element added to
522 * the element.
523 */
524 typedef void (*attributeSAXFunc) (void *ctx,
525 const xmlChar *name,
526 const xmlChar *value);
527 /**
528 * referenceSAXFunc:
529 * @ctx: the user data (XML parser context)
530 * @name: The entity name
531 *
532 * Called when an entity reference is detected.
533 */
534 typedef void (*referenceSAXFunc) (void *ctx,
535 const xmlChar *name);
536 /**
537 * charactersSAXFunc:
538 * @ctx: the user data (XML parser context)
539 * @ch: a xmlChar string
540 * @len: the number of xmlChar
541 *
542 * Receiving some chars from the parser.
543 */
544 typedef void (*charactersSAXFunc) (void *ctx,
545 const xmlChar *ch,
546 int len);
547 /**
548 * ignorableWhitespaceSAXFunc:
549 * @ctx: the user data (XML parser context)
550 * @ch: a xmlChar string
551 * @len: the number of xmlChar
552 *
553 * Receiving some ignorable whitespaces from the parser.
554 * UNUSED: by default the DOM building will use characters.
555 */
556 typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
557 const xmlChar *ch,
558 int len);
559 /**
560 * processingInstructionSAXFunc:
561 * @ctx: the user data (XML parser context)
562 * @target: the target name
563 * @data: the PI data's
564 *
565 * A processing instruction has been parsed.
566 */
567 typedef void (*processingInstructionSAXFunc) (void *ctx,
568 const xmlChar *target,
569 const xmlChar *data);
570 /**
571 * commentSAXFunc:
572 * @ctx: the user data (XML parser context)
573 * @value: the comment content
574 *
575 * A comment has been parsed.
576 */
577 typedef void (*commentSAXFunc) (void *ctx,
578 const xmlChar *value);
579 /**
580 * cdataBlockSAXFunc:
581 * @ctx: the user data (XML parser context)
582 * @value: The pcdata content
583 * @len: the block length
584 *
585 * Called when a pcdata block has been parsed.
586 */
587 typedef void (*cdataBlockSAXFunc) (
588 void *ctx,
589 const xmlChar *value,
590 int len);
591 /**
592 * warningSAXFunc:
593 * @ctx: an XML parser context
594 * @msg: the message to display/transmit
595 * @...: extra parameters for the message display
596 *
597 * Display and format a warning messages, callback.
598 */
599 typedef void (XMLCDECL *warningSAXFunc) (void *ctx,
600 const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
601 /**
602 * errorSAXFunc:
603 * @ctx: an XML parser context
604 * @msg: the message to display/transmit
605 * @...: extra parameters for the message display
606 *
607 * Display and format an error messages, callback.
608 */
609 typedef void (XMLCDECL *errorSAXFunc) (void *ctx,
610 const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
611 /**
612 * fatalErrorSAXFunc:
613 * @ctx: an XML parser context
614 * @msg: the message to display/transmit
615 * @...: extra parameters for the message display
616 *
617 * Display and format fatal error messages, callback.
618 * Note: so far fatalError() SAX callbacks are not used, error()
619 * get all the callbacks for errors.
620 */
621 typedef void (XMLCDECL *fatalErrorSAXFunc) (void *ctx,
622 const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
623 /**
624 * isStandaloneSAXFunc:
625 * @ctx: the user data (XML parser context)
626 *
627 * Is this document tagged standalone?
628 *
629 * Returns 1 if true
630 */
631 typedef int (*isStandaloneSAXFunc) (void *ctx);
632 /**
633 * hasInternalSubsetSAXFunc:
634 * @ctx: the user data (XML parser context)
635 *
636 * Does this document has an internal subset.
637 *
638 * Returns 1 if true
639 */
640 typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
641
642 /**
643 * hasExternalSubsetSAXFunc:
644 * @ctx: the user data (XML parser context)
645 *
646 * Does this document has an external subset?
647 *
648 * Returns 1 if true
649 */
650 typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
651
652 /************************************************************************
653 * *
654 * The SAX version 2 API extensions *
655 * *
656 ************************************************************************/
657 /**
658 * XML_SAX2_MAGIC:
659 *
660 * Special constant found in SAX2 blocks initialized fields
661 */
662 #define XML_SAX2_MAGIC 0xDEEDBEAF
663
664 /**
665 * startElementNsSAX2Func:
666 * @ctx: the user data (XML parser context)
667 * @localname: the local name of the element
668 * @prefix: the element namespace prefix if available
669 * @URI: the element namespace name if available
670 * @nb_namespaces: number of namespace definitions on that node
671 * @namespaces: pointer to the array of prefix/URI pairs namespace definitions
672 * @nb_attributes: the number of attributes on that node
673 * @nb_defaulted: the number of defaulted attributes. The defaulted
674 * ones are at the end of the array
675 * @attributes: pointer to the array of (localname/prefix/URI/value/end)
676 * attribute values.
677 *
678 * SAX2 callback when an element start has been detected by the parser.
679 * It provides the namespace informations for the element, as well as
680 * the new namespace declarations on the element.
681 */
682
683 typedef void (*startElementNsSAX2Func) (void *ctx,
684 const xmlChar *localname,
685 const xmlChar *prefix,
686 const xmlChar *URI,
687 int nb_namespaces,
688 const xmlChar **namespaces,
689 int nb_attributes,
690 int nb_defaulted,
691 const xmlChar **attributes);
692
693 /**
694 * endElementNsSAX2Func:
695 * @ctx: the user data (XML parser context)
696 * @localname: the local name of the element
697 * @prefix: the element namespace prefix if available
698 * @URI: the element namespace name if available
699 *
700 * SAX2 callback when an element end has been detected by the parser.
701 * It provides the namespace informations for the element.
702 */
703
704 typedef void (*endElementNsSAX2Func) (void *ctx,
705 const xmlChar *localname,
706 const xmlChar *prefix,
707 const xmlChar *URI);
708
709
710 struct _xmlSAXHandler {
711 internalSubsetSAXFunc internalSubset;
712 isStandaloneSAXFunc isStandalone;
713 hasInternalSubsetSAXFunc hasInternalSubset;
714 hasExternalSubsetSAXFunc hasExternalSubset;
715 resolveEntitySAXFunc resolveEntity;
716 getEntitySAXFunc getEntity;
717 entityDeclSAXFunc entityDecl;
718 notationDeclSAXFunc notationDecl;
719 attributeDeclSAXFunc attributeDecl;
720 elementDeclSAXFunc elementDecl;
721 unparsedEntityDeclSAXFunc unparsedEntityDecl;
722 setDocumentLocatorSAXFunc setDocumentLocator;
723 startDocumentSAXFunc startDocument;
724 endDocumentSAXFunc endDocument;
725 startElementSAXFunc startElement;
726 endElementSAXFunc endElement;
727 referenceSAXFunc reference;
728 charactersSAXFunc characters;
729 ignorableWhitespaceSAXFunc ignorableWhitespace;
730 processingInstructionSAXFunc processingInstruction;
731 commentSAXFunc comment;
732 warningSAXFunc warning;
733 errorSAXFunc error;
734 fatalErrorSAXFunc fatalError; /* unused error() get all the errors */
735 getParameterEntitySAXFunc getParameterEntity;
736 cdataBlockSAXFunc cdataBlock;
737 externalSubsetSAXFunc externalSubset;
738 unsigned int initialized;
739 /* The following fields are extensions available only on version 2 */
740 void *_private;
741 startElementNsSAX2Func startElementNs;
742 endElementNsSAX2Func endElementNs;
743 xmlStructuredErrorFunc serror;
744 };
745
746 /*
747 * SAX Version 1
748 */
749 typedef struct _xmlSAXHandlerV1 xmlSAXHandlerV1;
750 typedef xmlSAXHandlerV1 *xmlSAXHandlerV1Ptr;
751 struct _xmlSAXHandlerV1 {
752 internalSubsetSAXFunc internalSubset;
753 isStandaloneSAXFunc isStandalone;
754 hasInternalSubsetSAXFunc hasInternalSubset;
755 hasExternalSubsetSAXFunc hasExternalSubset;
756 resolveEntitySAXFunc resolveEntity;
757 getEntitySAXFunc getEntity;
758 entityDeclSAXFunc entityDecl;
759 notationDeclSAXFunc notationDecl;
760 attributeDeclSAXFunc attributeDecl;
761 elementDeclSAXFunc elementDecl;
762 unparsedEntityDeclSAXFunc unparsedEntityDecl;
763 setDocumentLocatorSAXFunc setDocumentLocator;
764 startDocumentSAXFunc startDocument;
765 endDocumentSAXFunc endDocument;
766 startElementSAXFunc startElement;
767 endElementSAXFunc endElement;
768 referenceSAXFunc reference;
769 charactersSAXFunc characters;
770 ignorableWhitespaceSAXFunc ignorableWhitespace;
771 processingInstructionSAXFunc processingInstruction;
772 commentSAXFunc comment;
773 warningSAXFunc warning;
774 errorSAXFunc error;
775 fatalErrorSAXFunc fatalError; /* unused error() get all the errors */
776 getParameterEntitySAXFunc getParameterEntity;
777 cdataBlockSAXFunc cdataBlock;
778 externalSubsetSAXFunc externalSubset;
779 unsigned int initialized;
780 };
781
782
783 /**
784 * xmlExternalEntityLoader:
785 * @URL: The System ID of the resource requested
786 * @ID: The Public ID of the resource requested
787 * @context: the XML parser context
788 *
789 * External entity loaders types.
790 *
791 * Returns the entity input parser.
792 */
793 typedef xmlParserInputPtr (*xmlExternalEntityLoader) (const char *URL,
794 const char *ID,
795 xmlParserCtxtPtr context);
796
797 #ifdef __cplusplus
798 }
799 #endif
800
801 #include <libxml/encoding.h>
802 #include <libxml/xmlIO.h>
803 #include <libxml/globals.h>
804
805 #ifdef __cplusplus
806 extern "C" {
807 #endif
808
809
810 /*
811 * Init/Cleanup
812 */
813 XMLPUBFUN void XMLCALL
814 xmlInitParser (void);
815 XMLPUBFUN void XMLCALL
816 xmlCleanupParser (void);
817
818 /*
819 * Input functions
820 */
821 XMLPUBFUN int XMLCALL
822 xmlParserInputRead (xmlParserInputPtr in,
823 int len);
824 XMLPUBFUN int XMLCALL
825 xmlParserInputGrow (xmlParserInputPtr in,
826 int len);
827
828 /*
829 * Basic parsing Interfaces
830 */
831 #ifdef LIBXML_SAX1_ENABLED
832 XMLPUBFUN xmlDocPtr XMLCALL
833 xmlParseDoc (const xmlChar *cur);
834 XMLPUBFUN xmlDocPtr XMLCALL
835 xmlParseFile (const char *filename);
836 XMLPUBFUN xmlDocPtr XMLCALL
837 xmlParseMemory (const char *buffer,
838 int size);
839 #endif /* LIBXML_SAX1_ENABLED */
840 XMLPUBFUN int XMLCALL
841 xmlSubstituteEntitiesDefault(int val);
842 XMLPUBFUN int XMLCALL
843 xmlKeepBlanksDefault (int val);
844 XMLPUBFUN void XMLCALL
845 xmlStopParser (xmlParserCtxtPtr ctxt);
846 XMLPUBFUN int XMLCALL
847 xmlPedanticParserDefault(int val);
848 XMLPUBFUN int XMLCALL
849 xmlLineNumbersDefault (int val);
850
851 #ifdef LIBXML_SAX1_ENABLED
852 /*
853 * Recovery mode
854 */
855 XMLPUBFUN xmlDocPtr XMLCALL
856 xmlRecoverDoc (const xmlChar *cur);
857 XMLPUBFUN xmlDocPtr XMLCALL
858 xmlRecoverMemory (const char *buffer,
859 int size);
860 XMLPUBFUN xmlDocPtr XMLCALL
861 xmlRecoverFile (const char *filename);
862 #endif /* LIBXML_SAX1_ENABLED */
863
864 /*
865 * Less common routines and SAX interfaces
866 */
867 XMLPUBFUN int XMLCALL
868 xmlParseDocument (xmlParserCtxtPtr ctxt);
869 XMLPUBFUN int XMLCALL
870 xmlParseExtParsedEnt (xmlParserCtxtPtr ctxt);
871 #ifdef LIBXML_SAX1_ENABLED
872 XMLPUBFUN int XMLCALL
873 xmlSAXUserParseFile (xmlSAXHandlerPtr sax,
874 void *user_data,
875 const char *filename);
876 XMLPUBFUN int XMLCALL
877 xmlSAXUserParseMemory (xmlSAXHandlerPtr sax,
878 void *user_data,
879 const char *buffer,
880 int size);
881 XMLPUBFUN xmlDocPtr XMLCALL
882 xmlSAXParseDoc (xmlSAXHandlerPtr sax,
883 const xmlChar *cur,
884 int recovery);
885 XMLPUBFUN xmlDocPtr XMLCALL
886 xmlSAXParseMemory (xmlSAXHandlerPtr sax,
887 const char *buffer,
888 int size,
889 int recovery);
890 XMLPUBFUN xmlDocPtr XMLCALL
891 xmlSAXParseMemoryWithData (xmlSAXHandlerPtr sax,
892 const char *buffer,
893 int size,
894 int recovery,
895 void *data);
896 XMLPUBFUN xmlDocPtr XMLCALL
897 xmlSAXParseFile (xmlSAXHandlerPtr sax,
898 const char *filename,
899 int recovery);
900 XMLPUBFUN xmlDocPtr XMLCALL
901 xmlSAXParseFileWithData (xmlSAXHandlerPtr sax,
902 const char *filename,
903 int recovery,
904 void *data);
905 XMLPUBFUN xmlDocPtr XMLCALL
906 xmlSAXParseEntity (xmlSAXHandlerPtr sax,
907 const char *filename);
908 XMLPUBFUN xmlDocPtr XMLCALL
909 xmlParseEntity (const char *filename);
910 #endif /* LIBXML_SAX1_ENABLED */
911
912 #ifdef LIBXML_VALID_ENABLED
913 XMLPUBFUN xmlDtdPtr XMLCALL
914 xmlSAXParseDTD (xmlSAXHandlerPtr sax,
915 const xmlChar *ExternalID,
916 const xmlChar *SystemID);
917 XMLPUBFUN xmlDtdPtr XMLCALL
918 xmlParseDTD (const xmlChar *ExternalID,
919 const xmlChar *SystemID);
920 XMLPUBFUN xmlDtdPtr XMLCALL
921 xmlIOParseDTD (xmlSAXHandlerPtr sax,
922 xmlParserInputBufferPtr input,
923 xmlCharEncoding enc);
924 #endif /* LIBXML_VALID_ENABLE */
925 #ifdef LIBXML_SAX1_ENABLED
926 XMLPUBFUN int XMLCALL
927 xmlParseBalancedChunkMemory(xmlDocPtr doc,
928 xmlSAXHandlerPtr sax,
929 void *user_data,
930 int depth,
931 const xmlChar *string,
932 xmlNodePtr *lst);
933 #endif /* LIBXML_SAX1_ENABLED */
934 XMLPUBFUN xmlParserErrors XMLCALL
935 xmlParseInNodeContext (xmlNodePtr node,
936 const char *data,
937 int datalen,
938 int options,
939 xmlNodePtr *lst);
940 #ifdef LIBXML_SAX1_ENABLED
941 XMLPUBFUN int XMLCALL
942 xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc,
943 xmlSAXHandlerPtr sax,
944 void *user_data,
945 int depth,
946 const xmlChar *string,
947 xmlNodePtr *lst,
948 int recover);
949 XMLPUBFUN int XMLCALL
950 xmlParseExternalEntity (xmlDocPtr doc,
951 xmlSAXHandlerPtr sax,
952 void *user_data,
953 int depth,
954 const xmlChar *URL,
955 const xmlChar *ID,
956 xmlNodePtr *lst);
957 #endif /* LIBXML_SAX1_ENABLED */
958 XMLPUBFUN int XMLCALL
959 xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx,
960 const xmlChar *URL,
961 const xmlChar *ID,
962 xmlNodePtr *lst);
963
964 /*
965 * Parser contexts handling.
966 */
967 XMLPUBFUN xmlParserCtxtPtr XMLCALL
968 xmlNewParserCtxt (void);
969 XMLPUBFUN int XMLCALL
970 xmlInitParserCtxt (xmlParserCtxtPtr ctxt);
971 XMLPUBFUN void XMLCALL
972 xmlClearParserCtxt (xmlParserCtxtPtr ctxt);
973 XMLPUBFUN void XMLCALL
974 xmlFreeParserCtxt (xmlParserCtxtPtr ctxt);
975 #ifdef LIBXML_SAX1_ENABLED
976 XMLPUBFUN void XMLCALL
977 xmlSetupParserForBuffer (xmlParserCtxtPtr ctxt,
978 const xmlChar* buffer,
979 const char *filename);
980 #endif /* LIBXML_SAX1_ENABLED */
981 XMLPUBFUN xmlParserCtxtPtr XMLCALL
982 xmlCreateDocParserCtxt (const xmlChar *cur);
983
984 #ifdef LIBXML_LEGACY_ENABLED
985 /*
986 * Reading/setting optional parsing features.
987 */
988 XMLPUBFUN int XMLCALL
989 xmlGetFeaturesList (int *len,
990 const char **result);
991 XMLPUBFUN int XMLCALL
992 xmlGetFeature (xmlParserCtxtPtr ctxt,
993 const char *name,
994 void *result);
995 XMLPUBFUN int XMLCALL
996 xmlSetFeature (xmlParserCtxtPtr ctxt,
997 const char *name,
998 void *value);
999 #endif /* LIBXML_LEGACY_ENABLED */
1000
1001 #ifdef LIBXML_PUSH_ENABLED
1002 /*
1003 * Interfaces for the Push mode.
1004 */
1005 XMLPUBFUN xmlParserCtxtPtr XMLCALL
1006 xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax,
1007 void *user_data,
1008 const char *chunk,
1009 int size,
1010 const char *filename);
1011 XMLPUBFUN int XMLCALL
1012 xmlParseChunk (xmlParserCtxtPtr ctxt,
1013 const char *chunk,
1014 int size,
1015 int terminate);
1016 #endif /* LIBXML_PUSH_ENABLED */
1017
1018 /*
1019 * Special I/O mode.
1020 */
1021
1022 XMLPUBFUN xmlParserCtxtPtr XMLCALL
1023 xmlCreateIOParserCtxt (xmlSAXHandlerPtr sax,
1024 void *user_data,
1025 xmlInputReadCallback ioread,
1026 xmlInputCloseCallback ioclose,
1027 void *ioctx,
1028 xmlCharEncoding enc);
1029
1030 XMLPUBFUN xmlParserInputPtr XMLCALL
1031 xmlNewIOInputStream (xmlParserCtxtPtr ctxt,
1032 xmlParserInputBufferPtr input,
1033 xmlCharEncoding enc);
1034
1035 /*
1036 * Node infos.
1037 */
1038 XMLPUBFUN const xmlParserNodeInfo* XMLCALL
1039 xmlParserFindNodeInfo (const xmlParserCtxtPtr ctxt,
1040 const xmlNodePtr node);
1041 XMLPUBFUN void XMLCALL
1042 xmlInitNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
1043 XMLPUBFUN void XMLCALL
1044 xmlClearNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
1045 XMLPUBFUN unsigned long XMLCALL
1046 xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,
1047 const xmlNodePtr node);
1048 XMLPUBFUN void XMLCALL
1049 xmlParserAddNodeInfo (xmlParserCtxtPtr ctxt,
1050 const xmlParserNodeInfoPtr info);
1051
1052 /*
1053 * External entities handling actually implemented in xmlIO.
1054 */
1055
1056 XMLPUBFUN void XMLCALL
1057 xmlSetExternalEntityLoader(xmlExternalEntityLoader f);
1058 XMLPUBFUN xmlExternalEntityLoader XMLCALL
1059 xmlGetExternalEntityLoader(void);
1060 XMLPUBFUN xmlParserInputPtr XMLCALL
1061 xmlLoadExternalEntity (const char *URL,
1062 const char *ID,
1063 xmlParserCtxtPtr ctxt);
1064
1065 /*
1066 * Index lookup, actually implemented in the encoding module
1067 */
1068 XMLPUBFUN long XMLCALL
1069 xmlByteConsumed (xmlParserCtxtPtr ctxt);
1070
1071 /*
1072 * New set of simpler/more flexible APIs
1073 */
1074 /**
1075 * xmlParserOption:
1076 *
1077 * This is the set of XML parser options that can be passed down
1078 * to the xmlReadDoc() and similar calls.
1079 */
1080 typedef enum {
1081 XML_PARSE_RECOVER = 1<<0, /* recover on errors */
1082 XML_PARSE_NOENT = 1<<1, /* substitute entities */
1083 XML_PARSE_DTDLOAD = 1<<2, /* load the external subset */
1084 XML_PARSE_DTDATTR = 1<<3, /* default DTD attributes */
1085 XML_PARSE_DTDVALID = 1<<4, /* validate with the DTD */
1086 XML_PARSE_NOERROR = 1<<5, /* suppress error reports */
1087 XML_PARSE_NOWARNING = 1<<6, /* suppress warning reports */
1088 XML_PARSE_PEDANTIC = 1<<7, /* pedantic error reporting */
1089 XML_PARSE_NOBLANKS = 1<<8, /* remove blank nodes */
1090 XML_PARSE_SAX1 = 1<<9, /* use the SAX1 interface internally */
1091 XML_PARSE_XINCLUDE = 1<<10,/* Implement XInclude substitition */
1092 XML_PARSE_NONET = 1<<11,/* Forbid network access */
1093 XML_PARSE_NODICT = 1<<12,/* Do not reuse the context dictionnary */
1094 XML_PARSE_NSCLEAN = 1<<13,/* remove redundant namespaces declarations */
1095 XML_PARSE_NOCDATA = 1<<14,/* merge CDATA as text nodes */
1096 XML_PARSE_NOXINCNODE= 1<<15,/* do not generate XINCLUDE START/END nodes */
1097 XML_PARSE_COMPACT = 1<<16,/* compact small text nodes; no modification of
1098 the tree allowed afterwards (will possibly
1099 crash if you try to modify the tree) */
1100 XML_PARSE_OLD10 = 1<<17,/* parse using XML-1.0 before update 5 */
1101 XML_PARSE_NOBASEFIX = 1<<18,/* do not fixup XINCLUDE xml:base uris */
1102 XML_PARSE_HUGE = 1<<19, /* relax any hardcoded limit from the parser */
1103 XML_PARSE_OLDSAX = 1<<20 /* parse using SAX2 interface from before 2.7.0 */
1104 } xmlParserOption;
1105
1106 XMLPUBFUN void XMLCALL
1107 xmlCtxtReset (xmlParserCtxtPtr ctxt);
1108 XMLPUBFUN int XMLCALL
1109 xmlCtxtResetPush (xmlParserCtxtPtr ctxt,
1110 const char *chunk,
1111 int size,
1112 const char *filename,
1113 const char *encoding);
1114 XMLPUBFUN int XMLCALL
1115 xmlCtxtUseOptions (xmlParserCtxtPtr ctxt,
1116 int options);
1117 XMLPUBFUN xmlDocPtr XMLCALL
1118 xmlReadDoc (const xmlChar *cur,
1119 const char *URL,
1120 const char *encoding,
1121 int options);
1122 XMLPUBFUN xmlDocPtr XMLCALL
1123 xmlReadFile (const char *URL,
1124 const char *encoding,
1125 int options);
1126 XMLPUBFUN xmlDocPtr XMLCALL
1127 xmlReadMemory (const char *buffer,
1128 int size,
1129 const char *URL,
1130 const char *encoding,
1131 int options);
1132 XMLPUBFUN xmlDocPtr XMLCALL
1133 xmlReadFd (int fd,
1134 const char *URL,
1135 const char *encoding,
1136 int options);
1137 XMLPUBFUN xmlDocPtr XMLCALL
1138 xmlReadIO (xmlInputReadCallback ioread,
1139 xmlInputCloseCallback ioclose,
1140 void *ioctx,
1141 const char *URL,
1142 const char *encoding,
1143 int options);
1144 XMLPUBFUN xmlDocPtr XMLCALL
1145 xmlCtxtReadDoc (xmlParserCtxtPtr ctxt,
1146 const xmlChar *cur,
1147 const char *URL,
1148 const char *encoding,
1149 int options);
1150 XMLPUBFUN xmlDocPtr XMLCALL
1151 xmlCtxtReadFile (xmlParserCtxtPtr ctxt,
1152 const char *filename,
1153 const char *encoding,
1154 int options);
1155 XMLPUBFUN xmlDocPtr XMLCALL
1156 xmlCtxtReadMemory (xmlParserCtxtPtr ctxt,
1157 const char *buffer,
1158 int size,
1159 const char *URL,
1160 const char *encoding,
1161 int options);
1162 XMLPUBFUN xmlDocPtr XMLCALL
1163 xmlCtxtReadFd (xmlParserCtxtPtr ctxt,
1164 int fd,
1165 const char *URL,
1166 const char *encoding,
1167 int options);
1168 XMLPUBFUN xmlDocPtr XMLCALL
1169 xmlCtxtReadIO (xmlParserCtxtPtr ctxt,
1170 xmlInputReadCallback ioread,
1171 xmlInputCloseCallback ioclose,
1172 void *ioctx,
1173 const char *URL,
1174 const char *encoding,
1175 int options);
1176
1177 /*
1178 * Library wide options
1179 */
1180 /**
1181 * xmlFeature:
1182 *
1183 * Used to examine the existance of features that can be enabled
1184 * or disabled at compile-time.
1185 * They used to be called XML_FEATURE_xxx but this clashed with Expat
1186 */
1187 typedef enum {
1188 XML_WITH_THREAD = 1,
1189 XML_WITH_TREE = 2,
1190 XML_WITH_OUTPUT = 3,
1191 XML_WITH_PUSH = 4,
1192 XML_WITH_READER = 5,
1193 XML_WITH_PATTERN = 6,
1194 XML_WITH_WRITER = 7,
1195 XML_WITH_SAX1 = 8,
1196 XML_WITH_FTP = 9,
1197 XML_WITH_HTTP = 10,
1198 XML_WITH_VALID = 11,
1199 XML_WITH_HTML = 12,
1200 XML_WITH_LEGACY = 13,
1201 XML_WITH_C14N = 14,
1202 XML_WITH_CATALOG = 15,
1203 XML_WITH_XPATH = 16,
1204 XML_WITH_XPTR = 17,
1205 XML_WITH_XINCLUDE = 18,
1206 XML_WITH_ICONV = 19,
1207 XML_WITH_ISO8859X = 20,
1208 XML_WITH_UNICODE = 21,
1209 XML_WITH_REGEXP = 22,
1210 XML_WITH_AUTOMATA = 23,
1211 XML_WITH_EXPR = 24,
1212 XML_WITH_SCHEMAS = 25,
1213 XML_WITH_SCHEMATRON = 26,
1214 XML_WITH_MODULES = 27,
1215 XML_WITH_DEBUG = 28,
1216 XML_WITH_DEBUG_MEM = 29,
1217 XML_WITH_DEBUG_RUN = 30,
1218 XML_WITH_ZLIB = 31,
1219 XML_WITH_NONE = 99999 /* just to be sure of allocation size */
1220 } xmlFeature;
1221
1222 XMLPUBFUN int XMLCALL
1223 xmlHasFeature (xmlFeature feature);
1224
1225 #ifdef __cplusplus
1226 }
1227 #endif
1228 #endif /* __XML_PARSER_H__ */
1229