blob: 8f50096e234293ce36302cc70b461a420a099510 [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * parser.h : Interfaces, constants and types related to the XML parser.
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Owen Taylor3473f882001-02-23 17:55:21 +00007 */
8
9#ifndef __XML_PARSER_H__
10#define __XML_PARSER_H__
11
12#include <libxml/tree.h>
13#include <libxml/valid.h>
Owen Taylor3473f882001-02-23 17:55:21 +000014#include <libxml/entities.h>
Owen Taylor3473f882001-02-23 17:55:21 +000015
16#ifdef __cplusplus
17extern "C" {
18#endif
19
Daniel Veillard5e2dace2001-07-18 19:30:27 +000020/**
21 * XML_DEFAULT_VERSION:
22 *
23 * The default version of XML used: 1.0
Owen Taylor3473f882001-02-23 17:55:21 +000024 */
25#define XML_DEFAULT_VERSION "1.0"
26
27/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000028 * xmlParserInput:
29 *
Daniel Veillard61f26172002-03-12 18:46:39 +000030 * An xmlParserInput is an input flow for the XML processor.
Owen Taylor3473f882001-02-23 17:55:21 +000031 * Each entity parsed is associated an xmlParserInput (except the
32 * few predefined ones). This is the case both for internal entities
33 * - in which case the flow is already completely in memory - or
34 * external entities - in which case we use the buf structure for
35 * progressive reading and I18N conversions to the internal UTF-8 format.
36 */
37
Daniel Veillard9d06d302002-01-22 18:15:52 +000038/**
39 * xmlParserInputDeallocate:
40 * @str: the string to deallocate
41 *
Daniel Veillard61f26172002-03-12 18:46:39 +000042 * Callback for freeing some parser input allocations.
Daniel Veillard9d06d302002-01-22 18:15:52 +000043 */
44typedef void (* xmlParserInputDeallocate)(xmlChar *str);
Daniel Veillard5e2dace2001-07-18 19:30:27 +000045
Owen Taylor3473f882001-02-23 17:55:21 +000046struct _xmlParserInput {
47 /* Input buffer */
48 xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */
49
50 const char *filename; /* The file analyzed, if any */
Daniel Veillard60087f32001-10-10 09:45:09 +000051 const char *directory; /* the directory/base of the file */
Owen Taylor3473f882001-02-23 17:55:21 +000052 const xmlChar *base; /* Base of the array to parse */
53 const xmlChar *cur; /* Current char being parsed */
Daniel Veillardcbaf3992001-12-31 16:16:02 +000054 const xmlChar *end; /* end of the array to parse */
Owen Taylor3473f882001-02-23 17:55:21 +000055 int length; /* length if known */
56 int line; /* Current line */
57 int col; /* Current column */
58 int consumed; /* How many xmlChars already consumed */
59 xmlParserInputDeallocate free; /* function to deallocate the base */
60 const xmlChar *encoding; /* the encoding string for entity */
61 const xmlChar *version; /* the version string for entity */
62 int standalone; /* Was that entity marked standalone */
63};
64
65/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000066 * xmlParserNodeInfo:
67 *
Daniel Veillard61f26172002-03-12 18:46:39 +000068 * The parser can be asked to collect Node informations, i.e. at what
Owen Taylor3473f882001-02-23 17:55:21 +000069 * place in the file they were detected.
70 * NOTE: This is off by default and not very well tested.
71 */
72typedef struct _xmlParserNodeInfo xmlParserNodeInfo;
73typedef xmlParserNodeInfo *xmlParserNodeInfoPtr;
74
75struct _xmlParserNodeInfo {
76 const struct _xmlNode* node;
77 /* Position & line # that text that created the node begins & ends on */
78 unsigned long begin_pos;
79 unsigned long begin_line;
80 unsigned long end_pos;
81 unsigned long end_line;
82};
83
84typedef struct _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
85typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
86struct _xmlParserNodeInfoSeq {
87 unsigned long maximum;
88 unsigned long length;
89 xmlParserNodeInfo* buffer;
90};
91
92/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000093 * xmlParserInputState:
94 *
Daniel Veillard61f26172002-03-12 18:46:39 +000095 * The parser is now working also as a state based parser.
96 * The recursive one use the state info for entities processing.
Owen Taylor3473f882001-02-23 17:55:21 +000097 */
98typedef enum {
99 XML_PARSER_EOF = -1, /* nothing is to be parsed */
100 XML_PARSER_START = 0, /* nothing has been parsed */
101 XML_PARSER_MISC, /* Misc* before int subset */
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000102 XML_PARSER_PI, /* Within a processing instruction */
Owen Taylor3473f882001-02-23 17:55:21 +0000103 XML_PARSER_DTD, /* within some DTD content */
104 XML_PARSER_PROLOG, /* Misc* after internal subset */
105 XML_PARSER_COMMENT, /* within a comment */
106 XML_PARSER_START_TAG, /* within a start tag */
107 XML_PARSER_CONTENT, /* within the content */
108 XML_PARSER_CDATA_SECTION, /* within a CDATA section */
109 XML_PARSER_END_TAG, /* within a closing tag */
110 XML_PARSER_ENTITY_DECL, /* within an entity declaration */
111 XML_PARSER_ENTITY_VALUE, /* within an entity value in a decl */
112 XML_PARSER_ATTRIBUTE_VALUE, /* within an attribute value */
113 XML_PARSER_SYSTEM_LITERAL, /* within a SYSTEM value */
114 XML_PARSER_EPILOG, /* the Misc* after the last end tag */
Daniel Veillard4a7ae502002-02-18 19:18:17 +0000115 XML_PARSER_IGNORE, /* within an IGNORED section */
116 XML_PARSER_PUBLIC_LITERAL /* within a PUBLIC value */
Owen Taylor3473f882001-02-23 17:55:21 +0000117} xmlParserInputState;
118
119/**
Daniel Veillardd16df9f2001-05-23 13:44:21 +0000120 * XML_DETECT_IDS:
121 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000122 * Bit in the loadsubset context field to tell to do ID/REFs lookups.
123 * Use it to initialize xmlLoadExtDtdDefaultValue.
Daniel Veillardd16df9f2001-05-23 13:44:21 +0000124 */
125#define XML_DETECT_IDS 2
126
127/**
128 * XML_COMPLETE_ATTRS:
129 *
130 * Bit in the loadsubset context field to tell to do complete the
Daniel Veillard61f26172002-03-12 18:46:39 +0000131 * elements attributes lists with the ones defaulted from the DTDs.
132 * Use it to initialize xmlLoadExtDtdDefaultValue.
Daniel Veillardd16df9f2001-05-23 13:44:21 +0000133 */
134#define XML_COMPLETE_ATTRS 4
135
136/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000137 * xmlParserCtxt:
138 *
Owen Taylor3473f882001-02-23 17:55:21 +0000139 * The parser context.
Daniel Veillard61f26172002-03-12 18:46:39 +0000140 * NOTE This doesn't completely define the parser state, the (current ?)
Owen Taylor3473f882001-02-23 17:55:21 +0000141 * design of the parser uses recursive function calls since this allow
142 * and easy mapping from the production rules of the specification
143 * to the actual code. The drawback is that the actual function call
144 * also reflect the parser state. However most of the parsing routines
145 * takes as the only argument the parser context pointer, so migrating
146 * to a state based parser for progressive parsing shouldn't be too hard.
147 */
Owen Taylor3473f882001-02-23 17:55:21 +0000148struct _xmlParserCtxt {
149 struct _xmlSAXHandler *sax; /* The SAX handler */
150 void *userData; /* For SAX interface only, used by DOM build */
151 xmlDocPtr myDoc; /* the document being built */
152 int wellFormed; /* is the document well formed */
153 int replaceEntities; /* shall we replace entities ? */
154 const xmlChar *version; /* the XML version string */
155 const xmlChar *encoding; /* the declared encoding, if any */
156 int standalone; /* standalone document */
157 int html; /* an HTML(1)/Docbook(2) document */
158
159 /* Input stream stack */
160 xmlParserInputPtr input; /* Current input stream */
161 int inputNr; /* Number of current input streams */
162 int inputMax; /* Max number of input streams */
163 xmlParserInputPtr *inputTab; /* stack of inputs */
164
165 /* Node analysis stack only used for DOM building */
166 xmlNodePtr node; /* Current parsed Node */
167 int nodeNr; /* Depth of the parsing stack */
168 int nodeMax; /* Max depth of the parsing stack */
169 xmlNodePtr *nodeTab; /* array of nodes */
170
171 int record_info; /* Whether node info should be kept */
172 xmlParserNodeInfoSeq node_seq; /* info about each node parsed */
173
174 int errNo; /* error code */
175
176 int hasExternalSubset; /* reference and external subset */
177 int hasPErefs; /* the internal subset has PE refs */
178 int external; /* are we parsing an external entity */
179
180 int valid; /* is the document valid */
181 int validate; /* shall we try to validate ? */
182 xmlValidCtxt vctxt; /* The validity context */
183
184 xmlParserInputState instate; /* current type of input */
185 int token; /* next char look-ahead */
186
187 char *directory; /* the data directory */
188
189 /* Node name stack */
190 xmlChar *name; /* Current parsed Node */
191 int nameNr; /* Depth of the parsing stack */
192 int nameMax; /* Max depth of the parsing stack */
193 xmlChar * *nameTab; /* array of nodes */
194
195 long nbChars; /* number of xmlChar processed */
196 long checkIndex; /* used by progressive parsing lookup */
197 int keepBlanks; /* ugly but ... */
198 int disableSAX; /* SAX callbacks are disabled */
199 int inSubset; /* Parsing is in int 1/ext 2 subset */
200 xmlChar * intSubName; /* name of subset */
201 xmlChar * extSubURI; /* URI of external subset */
202 xmlChar * extSubSystem; /* SYSTEM ID of external subset */
203
204 /* xml:space values */
205 int * space; /* Should the parser preserve spaces */
206 int spaceNr; /* Depth of the parsing stack */
207 int spaceMax; /* Max depth of the parsing stack */
208 int * spaceTab; /* array of space infos */
209
210 int depth; /* to prevent entity substitution loops */
211 xmlParserInputPtr entity; /* used to check entities boundaries */
212 int charset; /* encoding of the in-memory content
213 actually an xmlCharEncoding */
214 int nodelen; /* Those two fields are there to */
215 int nodemem; /* Speed up large node parsing */
216 int pedantic; /* signal pedantic warnings */
217 void *_private; /* For user data, libxml won't touch it */
218
219 int loadsubset; /* should the external subset be loaded */
Daniel Veillardd9bad132001-07-23 19:39:43 +0000220 int linenumbers; /* set line number in element content */
Daniel Veillard5d90b6c2001-08-22 14:29:45 +0000221 void *catalogs; /* document's own catalog */
Owen Taylor3473f882001-02-23 17:55:21 +0000222};
223
224/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000225 * xmlSAXLocator:
226 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000227 * A SAX Locator.
Owen Taylor3473f882001-02-23 17:55:21 +0000228 */
Owen Taylor3473f882001-02-23 17:55:21 +0000229struct _xmlSAXLocator {
230 const xmlChar *(*getPublicId)(void *ctx);
231 const xmlChar *(*getSystemId)(void *ctx);
232 int (*getLineNumber)(void *ctx);
233 int (*getColumnNumber)(void *ctx);
234};
235
236/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000237 * xmlSAXHandler:
238 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000239 * A SAX handler is bunch of callbacks called by the parser when processing
Owen Taylor3473f882001-02-23 17:55:21 +0000240 * of the input generate data or structure informations.
241 */
242
Daniel Veillard9d06d302002-01-22 18:15:52 +0000243/**
244 * resolveEntitySAXFunc:
245 * @ctx: the user data (XML parser context)
246 * @publicId: The public ID of the entity
247 * @systemId: The system ID of the entity
248 *
249 * Callback:
250 * The entity loader, to control the loading of external entities,
251 * the application can either:
252 * - override this resolveEntity() callback in the SAX block
253 * - or better use the xmlSetExternalEntityLoader() function to
254 * set up it's own entity resolution routine
255 *
256 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
257 */
Owen Taylor3473f882001-02-23 17:55:21 +0000258typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000259 const xmlChar *publicId,
260 const xmlChar *systemId);
261/**
262 * internalSubsetSAXFunc:
263 * @ctx: the user data (XML parser context)
264 * @name: the root element name
265 * @ExternalID: the external ID
266 * @SystemID: the SYSTEM ID (e.g. filename or URL)
267 *
268 * Callback on internal subset declaration.
269 */
270typedef void (*internalSubsetSAXFunc) (void *ctx,
271 const xmlChar *name,
272 const xmlChar *ExternalID,
273 const xmlChar *SystemID);
274/**
275 * externalSubsetSAXFunc:
276 * @ctx: the user data (XML parser context)
277 * @name: the root element name
278 * @ExternalID: the external ID
279 * @SystemID: the SYSTEM ID (e.g. filename or URL)
280 *
281 * Callback on external subset declaration.
282 */
283typedef void (*externalSubsetSAXFunc) (void *ctx,
284 const xmlChar *name,
285 const xmlChar *ExternalID,
286 const xmlChar *SystemID);
287/**
288 * getEntitySAXFunc:
289 * @ctx: the user data (XML parser context)
290 * @name: The entity name
291 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000292 * Get an entity by name.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000293 *
294 * Returns the xmlEntityPtr if found.
295 */
Owen Taylor3473f882001-02-23 17:55:21 +0000296typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000297 const xmlChar *name);
298/**
299 * getParameterEntitySAXFunc:
300 * @ctx: the user data (XML parser context)
301 * @name: The entity name
302 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000303 * Get a parameter entity by name.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000304 *
305 * Returns the xmlEntityPtr if found.
306 */
Owen Taylor3473f882001-02-23 17:55:21 +0000307typedef xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000308 const xmlChar *name);
309/**
310 * entityDeclSAXFunc:
311 * @ctx: the user data (XML parser context)
312 * @name: the entity name
313 * @type: the entity type
314 * @publicId: The public ID of the entity
315 * @systemId: The system ID of the entity
316 * @content: the entity value (without processing).
317 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000318 * An entity definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000319 */
Owen Taylor3473f882001-02-23 17:55:21 +0000320typedef void (*entityDeclSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000321 const xmlChar *name,
322 int type,
323 const xmlChar *publicId,
324 const xmlChar *systemId,
325 xmlChar *content);
326/**
327 * notationDeclSAXFunc:
328 * @ctx: the user data (XML parser context)
329 * @name: The name of the notation
330 * @publicId: The public ID of the entity
331 * @systemId: The system ID of the entity
332 *
333 * What to do when a notation declaration has been parsed.
334 */
335typedef void (*notationDeclSAXFunc)(void *ctx,
336 const xmlChar *name,
337 const xmlChar *publicId,
338 const xmlChar *systemId);
339/**
340 * attributeDeclSAXFunc:
341 * @ctx: the user data (XML parser context)
342 * @elem: the name of the element
343 * @fullname: the attribute name
344 * @type: the attribute type
345 * @def: the type of default value
346 * @defaultValue: the attribute default value
347 * @tree: the tree of enumerated value set
348 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000349 * An attribute definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000350 */
351typedef void (*attributeDeclSAXFunc)(void *ctx,
352 const xmlChar *elem,
353 const xmlChar *fullname,
354 int type,
355 int def,
356 const xmlChar *defaultValue,
357 xmlEnumerationPtr tree);
358/**
359 * elementDeclSAXFunc:
360 * @ctx: the user data (XML parser context)
361 * @name: the element name
362 * @type: the element type
363 * @content: the element value tree
364 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000365 * An element definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000366 */
367typedef void (*elementDeclSAXFunc)(void *ctx,
368 const xmlChar *name,
369 int type,
370 xmlElementContentPtr content);
371/**
372 * unparsedEntityDeclSAXFunc:
373 * @ctx: the user data (XML parser context)
374 * @name: The name of the entity
375 * @publicId: The public ID of the entity
376 * @systemId: The system ID of the entity
377 * @notationName: the name of the notation
378 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000379 * What to do when an unparsed entity declaration is parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000380 */
Owen Taylor3473f882001-02-23 17:55:21 +0000381typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000382 const xmlChar *name,
383 const xmlChar *publicId,
384 const xmlChar *systemId,
385 const xmlChar *notationName);
386/**
387 * setDocumentLocatorSAXFunc:
388 * @ctx: the user data (XML parser context)
389 * @loc: A SAX Locator
390 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000391 * Receive the document locator at startup, actually xmlDefaultSAXLocator.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000392 * Everything is available on the context, so this is useless in our case.
393 */
Owen Taylor3473f882001-02-23 17:55:21 +0000394typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000395 xmlSAXLocatorPtr loc);
396/**
397 * startDocumentSAXFunc:
398 * @ctx: the user data (XML parser context)
399 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000400 * Called when the document start being processed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000401 */
Owen Taylor3473f882001-02-23 17:55:21 +0000402typedef void (*startDocumentSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000403/**
404 * endDocumentSAXFunc:
405 * @ctx: the user data (XML parser context)
406 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000407 * Called when the document end has been detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000408 */
Owen Taylor3473f882001-02-23 17:55:21 +0000409typedef void (*endDocumentSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000410/**
411 * startElementSAXFunc:
412 * @ctx: the user data (XML parser context)
413 * @name: The element name, including namespace prefix
414 * @atts: An array of name/value attributes pairs, NULL terminated
415 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000416 * Called when an opening tag has been processed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000417 */
418typedef void (*startElementSAXFunc) (void *ctx,
419 const xmlChar *name,
420 const xmlChar **atts);
421/**
422 * endElementSAXFunc:
423 * @ctx: the user data (XML parser context)
424 * @name: The element name
425 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000426 * Called when the end of an element has been detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000427 */
428typedef void (*endElementSAXFunc) (void *ctx,
429 const xmlChar *name);
430/**
431 * attributeSAXFunc:
432 * @ctx: the user data (XML parser context)
433 * @name: The attribute name, including namespace prefix
434 * @value: The attribute value
435 *
436 * Handle an attribute that has been read by the parser.
437 * The default handling is to convert the attribute into an
438 * DOM subtree and past it in a new xmlAttr element added to
439 * the element.
440 */
441typedef void (*attributeSAXFunc) (void *ctx,
442 const xmlChar *name,
443 const xmlChar *value);
444/**
445 * referenceSAXFunc:
446 * @ctx: the user data (XML parser context)
447 * @name: The entity name
448 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000449 * Called when an entity reference is detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000450 */
451typedef void (*referenceSAXFunc) (void *ctx,
452 const xmlChar *name);
453/**
454 * charactersSAXFunc:
455 * @ctx: the user data (XML parser context)
456 * @ch: a xmlChar string
457 * @len: the number of xmlChar
458 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000459 * Receiving some chars from the parser.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000460 */
461typedef void (*charactersSAXFunc) (void *ctx,
462 const xmlChar *ch,
463 int len);
464/**
465 * ignorableWhitespaceSAXFunc:
466 * @ctx: the user data (XML parser context)
467 * @ch: a xmlChar string
468 * @len: the number of xmlChar
469 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000470 * Receiving some ignorable whitespaces from the parser.
471 * UNUSED: by default the DOM building will use characters.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000472 */
Owen Taylor3473f882001-02-23 17:55:21 +0000473typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000474 const xmlChar *ch,
475 int len);
476/**
477 * processingInstructionSAXFunc:
478 * @ctx: the user data (XML parser context)
479 * @target: the target name
480 * @data: the PI data's
481 *
482 * A processing instruction has been parsed.
483 */
Owen Taylor3473f882001-02-23 17:55:21 +0000484typedef void (*processingInstructionSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000485 const xmlChar *target,
486 const xmlChar *data);
487/**
488 * commentSAXFunc:
489 * @ctx: the user data (XML parser context)
490 * @value: the comment content
491 *
492 * A comment has been parsed.
493 */
494typedef void (*commentSAXFunc) (void *ctx,
495 const xmlChar *value);
496/**
497 * cdataBlockSAXFunc:
498 * @ctx: the user data (XML parser context)
499 * @value: The pcdata content
500 * @len: the block length
501 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000502 * Called when a pcdata block has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000503 */
504typedef void (*cdataBlockSAXFunc) (
505 void *ctx,
506 const xmlChar *value,
507 int len);
508/**
509 * warningSAXFunc:
510 * @ctx: an XML parser context
511 * @msg: the message to display/transmit
512 * @...: extra parameters for the message display
513 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000514 * Display and format a warning messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000515 */
516typedef void (*warningSAXFunc) (void *ctx,
517 const char *msg, ...);
518/**
519 * errorSAXFunc:
520 * @ctx: an XML parser context
521 * @msg: the message to display/transmit
522 * @...: extra parameters for the message display
523 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000524 * Display and format an error messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000525 */
526typedef void (*errorSAXFunc) (void *ctx,
527 const char *msg, ...);
528/**
529 * fatalErrorSAXFunc:
530 * @ctx: an XML parser context
531 * @msg: the message to display/transmit
532 * @...: extra parameters for the message display
533 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000534 * Display and format fatal error messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000535 */
536typedef void (*fatalErrorSAXFunc) (void *ctx,
537 const char *msg, ...);
538/**
539 * isStandaloneSAXFunc:
540 * @ctx: the user data (XML parser context)
541 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000542 * Is this document tagged standalone?
Daniel Veillard9d06d302002-01-22 18:15:52 +0000543 *
544 * Returns 1 if true
545 */
Owen Taylor3473f882001-02-23 17:55:21 +0000546typedef int (*isStandaloneSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000547/**
548 * hasInternalSubsetSAXFunc:
549 * @ctx: the user data (XML parser context)
550 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000551 * Does this document has an internal subset.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000552 *
553 * Returns 1 if true
554 */
Owen Taylor3473f882001-02-23 17:55:21 +0000555typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000556/**
557 * hasExternalSubsetSAXFunc:
558 * @ctx: the user data (XML parser context)
559 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000560 * Does this document has an external subset?
Daniel Veillard9d06d302002-01-22 18:15:52 +0000561 *
562 * Returns 1 if true
563 */
Owen Taylor3473f882001-02-23 17:55:21 +0000564typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
565
Owen Taylor3473f882001-02-23 17:55:21 +0000566struct _xmlSAXHandler {
567 internalSubsetSAXFunc internalSubset;
568 isStandaloneSAXFunc isStandalone;
569 hasInternalSubsetSAXFunc hasInternalSubset;
570 hasExternalSubsetSAXFunc hasExternalSubset;
571 resolveEntitySAXFunc resolveEntity;
572 getEntitySAXFunc getEntity;
573 entityDeclSAXFunc entityDecl;
574 notationDeclSAXFunc notationDecl;
575 attributeDeclSAXFunc attributeDecl;
576 elementDeclSAXFunc elementDecl;
577 unparsedEntityDeclSAXFunc unparsedEntityDecl;
578 setDocumentLocatorSAXFunc setDocumentLocator;
579 startDocumentSAXFunc startDocument;
580 endDocumentSAXFunc endDocument;
581 startElementSAXFunc startElement;
582 endElementSAXFunc endElement;
583 referenceSAXFunc reference;
584 charactersSAXFunc characters;
585 ignorableWhitespaceSAXFunc ignorableWhitespace;
586 processingInstructionSAXFunc processingInstruction;
587 commentSAXFunc comment;
588 warningSAXFunc warning;
589 errorSAXFunc error;
590 fatalErrorSAXFunc fatalError;
591 getParameterEntitySAXFunc getParameterEntity;
592 cdataBlockSAXFunc cdataBlock;
593 externalSubsetSAXFunc externalSubset;
Daniel Veillardd0463562001-10-13 09:15:48 +0000594 int initialized;
Owen Taylor3473f882001-02-23 17:55:21 +0000595};
596
597/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000598 * xmlExternalEntityLoader:
599 * @URL: The System ID of the resource requested
600 * @ID: The Public ID of the resource requested
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000601 * @context: the XML parser context
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000602 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000603 * External entity loaders types.
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000604 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000605 * Returns the entity input parser.
Owen Taylor3473f882001-02-23 17:55:21 +0000606 */
Daniel Veillard9d06d302002-01-22 18:15:52 +0000607typedef xmlParserInputPtr (*xmlExternalEntityLoader) (const char *URL,
608 const char *ID,
609 xmlParserCtxtPtr context);
Owen Taylor3473f882001-02-23 17:55:21 +0000610
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000611/*
Owen Taylor3473f882001-02-23 17:55:21 +0000612 * Global variables: just the default SAX interface tables and XML
613 * version infos.
614 */
Daniel Veillard0ba59232002-02-10 13:20:39 +0000615#if 0
Owen Taylor3473f882001-02-23 17:55:21 +0000616LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000617#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000618
Daniel Veillard0ba59232002-02-10 13:20:39 +0000619/*
Owen Taylor3473f882001-02-23 17:55:21 +0000620LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
621LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
622LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
Daniel Veillardeae522a2001-04-23 13:41:34 +0000623LIBXML_DLL_IMPORT extern xmlSAXHandler docbDefaultSAXHandler;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000624 */
Owen Taylor3473f882001-02-23 17:55:21 +0000625
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000626/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000627 * Entity substitution default behavior.
Owen Taylor3473f882001-02-23 17:55:21 +0000628 */
629
630#ifdef VMS
Daniel Veillard5e2dace2001-07-18 19:30:27 +0000631/**
632 * xmlSubstituteEntitiesDefaultValue:
633 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000634 * Global variable controlling the entity substitution default behavior.
Daniel Veillard5e2dace2001-07-18 19:30:27 +0000635 */
Owen Taylor3473f882001-02-23 17:55:21 +0000636LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultVal;
637#define xmlSubstituteEntitiesDefaultValue xmlSubstituteEntitiesDefaultVal
Owen Taylor3473f882001-02-23 17:55:21 +0000638#endif
Daniel Veillard0ba59232002-02-10 13:20:39 +0000639#if 0
640LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
Owen Taylor3473f882001-02-23 17:55:21 +0000641LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000642#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000643
Daniel Veillard6c4ffaf2002-02-11 08:54:05 +0000644#ifdef __cplusplus
645}
646#endif
647#include <libxml/encoding.h>
648#include <libxml/xmlIO.h>
649#include <libxml/globals.h>
650#ifdef __cplusplus
651extern "C" {
652#endif
653
Owen Taylor3473f882001-02-23 17:55:21 +0000654
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000655/*
Owen Taylor3473f882001-02-23 17:55:21 +0000656 * Init/Cleanup
657 */
658void xmlInitParser (void);
659void xmlCleanupParser (void);
660
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000661/*
Owen Taylor3473f882001-02-23 17:55:21 +0000662 * Input functions
663 */
664int xmlParserInputRead (xmlParserInputPtr in,
665 int len);
666int xmlParserInputGrow (xmlParserInputPtr in,
667 int len);
668
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000669/*
Owen Taylor3473f882001-02-23 17:55:21 +0000670 * xmlChar handling
671 */
672xmlChar * xmlStrdup (const xmlChar *cur);
673xmlChar * xmlStrndup (const xmlChar *cur,
674 int len);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000675xmlChar * xmlCharStrndup (const char *cur,
676 int len);
677xmlChar * xmlCharStrdup (const char *cur);
Owen Taylor3473f882001-02-23 17:55:21 +0000678xmlChar * xmlStrsub (const xmlChar *str,
679 int start,
680 int len);
681const xmlChar * xmlStrchr (const xmlChar *str,
682 xmlChar val);
683const xmlChar * xmlStrstr (const xmlChar *str,
Daniel Veillard77044732001-06-29 21:31:07 +0000684 const xmlChar *val);
Owen Taylor3473f882001-02-23 17:55:21 +0000685const xmlChar * xmlStrcasestr (const xmlChar *str,
686 xmlChar *val);
687int xmlStrcmp (const xmlChar *str1,
688 const xmlChar *str2);
689int xmlStrncmp (const xmlChar *str1,
690 const xmlChar *str2,
691 int len);
692int xmlStrcasecmp (const xmlChar *str1,
693 const xmlChar *str2);
694int xmlStrncasecmp (const xmlChar *str1,
695 const xmlChar *str2,
696 int len);
697int xmlStrEqual (const xmlChar *str1,
698 const xmlChar *str2);
699int xmlStrlen (const xmlChar *str);
700xmlChar * xmlStrcat (xmlChar *cur,
701 const xmlChar *add);
702xmlChar * xmlStrncat (xmlChar *cur,
703 const xmlChar *add,
704 int len);
705
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000706/*
Owen Taylor3473f882001-02-23 17:55:21 +0000707 * Basic parsing Interfaces
708 */
709xmlDocPtr xmlParseDoc (xmlChar *cur);
Daniel Veillard50822cb2001-07-26 20:05:51 +0000710xmlDocPtr xmlParseMemory (const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000711 int size);
712xmlDocPtr xmlParseFile (const char *filename);
713int xmlSubstituteEntitiesDefault(int val);
714int xmlKeepBlanksDefault (int val);
715void xmlStopParser (xmlParserCtxtPtr ctxt);
716int xmlPedanticParserDefault(int val);
Daniel Veillardd9bad132001-07-23 19:39:43 +0000717int xmlLineNumbersDefault (int val);
Owen Taylor3473f882001-02-23 17:55:21 +0000718
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000719/*
Owen Taylor3473f882001-02-23 17:55:21 +0000720 * Recovery mode
721 */
722xmlDocPtr xmlRecoverDoc (xmlChar *cur);
Daniel Veillard50822cb2001-07-26 20:05:51 +0000723xmlDocPtr xmlRecoverMemory (const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000724 int size);
725xmlDocPtr xmlRecoverFile (const char *filename);
726
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000727/*
Owen Taylor3473f882001-02-23 17:55:21 +0000728 * Less common routines and SAX interfaces
729 */
730int xmlParseDocument (xmlParserCtxtPtr ctxt);
731int xmlParseExtParsedEnt (xmlParserCtxtPtr ctxt);
732xmlDocPtr xmlSAXParseDoc (xmlSAXHandlerPtr sax,
733 xmlChar *cur,
734 int recovery);
735int xmlSAXUserParseFile (xmlSAXHandlerPtr sax,
736 void *user_data,
737 const char *filename);
738int xmlSAXUserParseMemory (xmlSAXHandlerPtr sax,
739 void *user_data,
Daniel Veillardfd7ddca2001-05-16 10:57:35 +0000740 const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000741 int size);
742xmlDocPtr xmlSAXParseMemory (xmlSAXHandlerPtr sax,
Daniel Veillard50822cb2001-07-26 20:05:51 +0000743 const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000744 int size,
745 int recovery);
746xmlDocPtr xmlSAXParseFile (xmlSAXHandlerPtr sax,
747 const char *filename,
748 int recovery);
Daniel Veillarda293c322001-10-02 13:54:14 +0000749xmlDocPtr xmlSAXParseFileWithData (xmlSAXHandlerPtr sax,
750 const char *filename,
751 int recovery,
752 void *data);
Owen Taylor3473f882001-02-23 17:55:21 +0000753xmlDocPtr xmlSAXParseEntity (xmlSAXHandlerPtr sax,
754 const char *filename);
755xmlDocPtr xmlParseEntity (const char *filename);
756xmlDtdPtr xmlParseDTD (const xmlChar *ExternalID,
757 const xmlChar *SystemID);
758xmlDtdPtr xmlSAXParseDTD (xmlSAXHandlerPtr sax,
759 const xmlChar *ExternalID,
760 const xmlChar *SystemID);
761xmlDtdPtr xmlIOParseDTD (xmlSAXHandlerPtr sax,
762 xmlParserInputBufferPtr input,
763 xmlCharEncoding enc);
764int xmlParseBalancedChunkMemory(xmlDocPtr doc,
765 xmlSAXHandlerPtr sax,
766 void *user_data,
767 int depth,
768 const xmlChar *string,
Daniel Veillardcda96922001-08-21 10:56:31 +0000769 xmlNodePtr *lst);
Daniel Veillard58e44c92002-08-02 22:19:49 +0000770int xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc,
771 xmlSAXHandlerPtr sax,
772 void *user_data,
773 int depth,
774 const xmlChar *string,
775 xmlNodePtr *lst,
776 int recover);
Owen Taylor3473f882001-02-23 17:55:21 +0000777int xmlParseExternalEntity (xmlDocPtr doc,
778 xmlSAXHandlerPtr sax,
779 void *user_data,
780 int depth,
781 const xmlChar *URL,
782 const xmlChar *ID,
Daniel Veillardcda96922001-08-21 10:56:31 +0000783 xmlNodePtr *lst);
Owen Taylor3473f882001-02-23 17:55:21 +0000784int xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx,
785 const xmlChar *URL,
786 const xmlChar *ID,
Daniel Veillardcda96922001-08-21 10:56:31 +0000787 xmlNodePtr *lst);
Owen Taylor3473f882001-02-23 17:55:21 +0000788
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000789/*
Owen Taylor3473f882001-02-23 17:55:21 +0000790 * Parser contexts handling.
791 */
792void xmlInitParserCtxt (xmlParserCtxtPtr ctxt);
793void xmlClearParserCtxt (xmlParserCtxtPtr ctxt);
794void xmlFreeParserCtxt (xmlParserCtxtPtr ctxt);
795void xmlSetupParserForBuffer (xmlParserCtxtPtr ctxt,
796 const xmlChar* buffer,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000797 const char *filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000798xmlParserCtxtPtr xmlCreateDocParserCtxt (xmlChar *cur);
799
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000800/*
Owen Taylor3473f882001-02-23 17:55:21 +0000801 * Reading/setting optional parsing features.
802 */
803
804int xmlGetFeaturesList (int *len,
805 const char **result);
806int xmlGetFeature (xmlParserCtxtPtr ctxt,
807 const char *name,
808 void *result);
809int xmlSetFeature (xmlParserCtxtPtr ctxt,
810 const char *name,
811 void *value);
812
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000813/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000814 * Interfaces for the Push mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000815 */
816xmlParserCtxtPtr xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax,
817 void *user_data,
818 const char *chunk,
819 int size,
820 const char *filename);
821int xmlParseChunk (xmlParserCtxtPtr ctxt,
822 const char *chunk,
823 int size,
824 int terminate);
825
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000826/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000827 * Special I/O mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000828 */
829
830xmlParserCtxtPtr xmlCreateIOParserCtxt (xmlSAXHandlerPtr sax,
831 void *user_data,
832 xmlInputReadCallback ioread,
833 xmlInputCloseCallback ioclose,
834 void *ioctx,
835 xmlCharEncoding enc);
836
837xmlParserInputPtr xmlNewIOInputStream (xmlParserCtxtPtr ctxt,
838 xmlParserInputBufferPtr input,
839 xmlCharEncoding enc);
840
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000841/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000842 * Node infos.
Owen Taylor3473f882001-02-23 17:55:21 +0000843 */
844const xmlParserNodeInfo*
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000845 xmlParserFindNodeInfo (const xmlParserCtxtPtr ctxt,
846 const xmlNodePtr node);
Owen Taylor3473f882001-02-23 17:55:21 +0000847void xmlInitNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
848void xmlClearNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000849unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,
850 const xmlNodePtr node);
Owen Taylor3473f882001-02-23 17:55:21 +0000851void xmlParserAddNodeInfo (xmlParserCtxtPtr ctxt,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000852 const xmlParserNodeInfoPtr info);
Owen Taylor3473f882001-02-23 17:55:21 +0000853
854/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000855 * External entities handling actually implemented in xmlIO.
Owen Taylor3473f882001-02-23 17:55:21 +0000856 */
857
858void xmlSetExternalEntityLoader(xmlExternalEntityLoader f);
859xmlExternalEntityLoader
860 xmlGetExternalEntityLoader(void);
861xmlParserInputPtr
862 xmlLoadExternalEntity (const char *URL,
863 const char *ID,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000864 xmlParserCtxtPtr ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +0000865
866#ifdef __cplusplus
867}
868#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000869#endif /* __XML_PARSER_H__ */
870