blob: e6725a364d586b13348179ca5618ee4d05c74c97 [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 */
Daniel Veillarddad3f682002-11-17 16:47:27 +0000222 int recovery; /* run in recovery mode */
Owen Taylor3473f882001-02-23 17:55:21 +0000223};
224
225/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000226 * xmlSAXLocator:
227 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000228 * A SAX Locator.
Owen Taylor3473f882001-02-23 17:55:21 +0000229 */
Owen Taylor3473f882001-02-23 17:55:21 +0000230struct _xmlSAXLocator {
231 const xmlChar *(*getPublicId)(void *ctx);
232 const xmlChar *(*getSystemId)(void *ctx);
233 int (*getLineNumber)(void *ctx);
234 int (*getColumnNumber)(void *ctx);
235};
236
237/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000238 * xmlSAXHandler:
239 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000240 * A SAX handler is bunch of callbacks called by the parser when processing
Owen Taylor3473f882001-02-23 17:55:21 +0000241 * of the input generate data or structure informations.
242 */
243
Daniel Veillard9d06d302002-01-22 18:15:52 +0000244/**
245 * resolveEntitySAXFunc:
246 * @ctx: the user data (XML parser context)
247 * @publicId: The public ID of the entity
248 * @systemId: The system ID of the entity
249 *
250 * Callback:
251 * The entity loader, to control the loading of external entities,
252 * the application can either:
253 * - override this resolveEntity() callback in the SAX block
254 * - or better use the xmlSetExternalEntityLoader() function to
255 * set up it's own entity resolution routine
256 *
257 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
258 */
Owen Taylor3473f882001-02-23 17:55:21 +0000259typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000260 const xmlChar *publicId,
261 const xmlChar *systemId);
262/**
263 * internalSubsetSAXFunc:
264 * @ctx: the user data (XML parser context)
265 * @name: the root element name
266 * @ExternalID: the external ID
267 * @SystemID: the SYSTEM ID (e.g. filename or URL)
268 *
269 * Callback on internal subset declaration.
270 */
271typedef void (*internalSubsetSAXFunc) (void *ctx,
272 const xmlChar *name,
273 const xmlChar *ExternalID,
274 const xmlChar *SystemID);
275/**
276 * externalSubsetSAXFunc:
277 * @ctx: the user data (XML parser context)
278 * @name: the root element name
279 * @ExternalID: the external ID
280 * @SystemID: the SYSTEM ID (e.g. filename or URL)
281 *
282 * Callback on external subset declaration.
283 */
284typedef void (*externalSubsetSAXFunc) (void *ctx,
285 const xmlChar *name,
286 const xmlChar *ExternalID,
287 const xmlChar *SystemID);
288/**
289 * getEntitySAXFunc:
290 * @ctx: the user data (XML parser context)
291 * @name: The entity name
292 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000293 * Get an entity by name.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000294 *
295 * Returns the xmlEntityPtr if found.
296 */
Owen Taylor3473f882001-02-23 17:55:21 +0000297typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000298 const xmlChar *name);
299/**
300 * getParameterEntitySAXFunc:
301 * @ctx: the user data (XML parser context)
302 * @name: The entity name
303 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000304 * Get a parameter entity by name.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000305 *
306 * Returns the xmlEntityPtr if found.
307 */
Owen Taylor3473f882001-02-23 17:55:21 +0000308typedef xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000309 const xmlChar *name);
310/**
311 * entityDeclSAXFunc:
312 * @ctx: the user data (XML parser context)
313 * @name: the entity name
314 * @type: the entity type
315 * @publicId: The public ID of the entity
316 * @systemId: The system ID of the entity
317 * @content: the entity value (without processing).
318 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000319 * An entity definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000320 */
Owen Taylor3473f882001-02-23 17:55:21 +0000321typedef void (*entityDeclSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000322 const xmlChar *name,
323 int type,
324 const xmlChar *publicId,
325 const xmlChar *systemId,
326 xmlChar *content);
327/**
328 * notationDeclSAXFunc:
329 * @ctx: the user data (XML parser context)
330 * @name: The name of the notation
331 * @publicId: The public ID of the entity
332 * @systemId: The system ID of the entity
333 *
334 * What to do when a notation declaration has been parsed.
335 */
336typedef void (*notationDeclSAXFunc)(void *ctx,
337 const xmlChar *name,
338 const xmlChar *publicId,
339 const xmlChar *systemId);
340/**
341 * attributeDeclSAXFunc:
342 * @ctx: the user data (XML parser context)
343 * @elem: the name of the element
344 * @fullname: the attribute name
345 * @type: the attribute type
346 * @def: the type of default value
347 * @defaultValue: the attribute default value
348 * @tree: the tree of enumerated value set
349 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000350 * An attribute definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000351 */
352typedef void (*attributeDeclSAXFunc)(void *ctx,
353 const xmlChar *elem,
354 const xmlChar *fullname,
355 int type,
356 int def,
357 const xmlChar *defaultValue,
358 xmlEnumerationPtr tree);
359/**
360 * elementDeclSAXFunc:
361 * @ctx: the user data (XML parser context)
362 * @name: the element name
363 * @type: the element type
364 * @content: the element value tree
365 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000366 * An element definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000367 */
368typedef void (*elementDeclSAXFunc)(void *ctx,
369 const xmlChar *name,
370 int type,
371 xmlElementContentPtr content);
372/**
373 * unparsedEntityDeclSAXFunc:
374 * @ctx: the user data (XML parser context)
375 * @name: The name of the entity
376 * @publicId: The public ID of the entity
377 * @systemId: The system ID of the entity
378 * @notationName: the name of the notation
379 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000380 * What to do when an unparsed entity declaration is parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000381 */
Owen Taylor3473f882001-02-23 17:55:21 +0000382typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000383 const xmlChar *name,
384 const xmlChar *publicId,
385 const xmlChar *systemId,
386 const xmlChar *notationName);
387/**
388 * setDocumentLocatorSAXFunc:
389 * @ctx: the user data (XML parser context)
390 * @loc: A SAX Locator
391 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000392 * Receive the document locator at startup, actually xmlDefaultSAXLocator.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000393 * Everything is available on the context, so this is useless in our case.
394 */
Owen Taylor3473f882001-02-23 17:55:21 +0000395typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000396 xmlSAXLocatorPtr loc);
397/**
398 * startDocumentSAXFunc:
399 * @ctx: the user data (XML parser context)
400 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000401 * Called when the document start being processed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000402 */
Owen Taylor3473f882001-02-23 17:55:21 +0000403typedef void (*startDocumentSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000404/**
405 * endDocumentSAXFunc:
406 * @ctx: the user data (XML parser context)
407 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000408 * Called when the document end has been detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000409 */
Owen Taylor3473f882001-02-23 17:55:21 +0000410typedef void (*endDocumentSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000411/**
412 * startElementSAXFunc:
413 * @ctx: the user data (XML parser context)
414 * @name: The element name, including namespace prefix
415 * @atts: An array of name/value attributes pairs, NULL terminated
416 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000417 * Called when an opening tag has been processed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000418 */
419typedef void (*startElementSAXFunc) (void *ctx,
420 const xmlChar *name,
421 const xmlChar **atts);
422/**
423 * endElementSAXFunc:
424 * @ctx: the user data (XML parser context)
425 * @name: The element name
426 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000427 * Called when the end of an element has been detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000428 */
429typedef void (*endElementSAXFunc) (void *ctx,
430 const xmlChar *name);
431/**
432 * attributeSAXFunc:
433 * @ctx: the user data (XML parser context)
434 * @name: The attribute name, including namespace prefix
435 * @value: The attribute value
436 *
437 * Handle an attribute that has been read by the parser.
438 * The default handling is to convert the attribute into an
439 * DOM subtree and past it in a new xmlAttr element added to
440 * the element.
441 */
442typedef void (*attributeSAXFunc) (void *ctx,
443 const xmlChar *name,
444 const xmlChar *value);
445/**
446 * referenceSAXFunc:
447 * @ctx: the user data (XML parser context)
448 * @name: The entity name
449 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000450 * Called when an entity reference is detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000451 */
452typedef void (*referenceSAXFunc) (void *ctx,
453 const xmlChar *name);
454/**
455 * charactersSAXFunc:
456 * @ctx: the user data (XML parser context)
457 * @ch: a xmlChar string
458 * @len: the number of xmlChar
459 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000460 * Receiving some chars from the parser.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000461 */
462typedef void (*charactersSAXFunc) (void *ctx,
463 const xmlChar *ch,
464 int len);
465/**
466 * ignorableWhitespaceSAXFunc:
467 * @ctx: the user data (XML parser context)
468 * @ch: a xmlChar string
469 * @len: the number of xmlChar
470 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000471 * Receiving some ignorable whitespaces from the parser.
472 * UNUSED: by default the DOM building will use characters.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000473 */
Owen Taylor3473f882001-02-23 17:55:21 +0000474typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000475 const xmlChar *ch,
476 int len);
477/**
478 * processingInstructionSAXFunc:
479 * @ctx: the user data (XML parser context)
480 * @target: the target name
481 * @data: the PI data's
482 *
483 * A processing instruction has been parsed.
484 */
Owen Taylor3473f882001-02-23 17:55:21 +0000485typedef void (*processingInstructionSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000486 const xmlChar *target,
487 const xmlChar *data);
488/**
489 * commentSAXFunc:
490 * @ctx: the user data (XML parser context)
491 * @value: the comment content
492 *
493 * A comment has been parsed.
494 */
495typedef void (*commentSAXFunc) (void *ctx,
496 const xmlChar *value);
497/**
498 * cdataBlockSAXFunc:
499 * @ctx: the user data (XML parser context)
500 * @value: The pcdata content
501 * @len: the block length
502 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000503 * Called when a pcdata block has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000504 */
505typedef void (*cdataBlockSAXFunc) (
506 void *ctx,
507 const xmlChar *value,
508 int len);
509/**
510 * warningSAXFunc:
511 * @ctx: an XML parser context
512 * @msg: the message to display/transmit
513 * @...: extra parameters for the message display
514 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000515 * Display and format a warning messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000516 */
517typedef void (*warningSAXFunc) (void *ctx,
518 const char *msg, ...);
519/**
520 * errorSAXFunc:
521 * @ctx: an XML parser context
522 * @msg: the message to display/transmit
523 * @...: extra parameters for the message display
524 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000525 * Display and format an error messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000526 */
527typedef void (*errorSAXFunc) (void *ctx,
528 const char *msg, ...);
529/**
530 * fatalErrorSAXFunc:
531 * @ctx: an XML parser context
532 * @msg: the message to display/transmit
533 * @...: extra parameters for the message display
534 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000535 * Display and format fatal error messages, callback.
Daniel Veillard0821b152002-11-12 20:57:47 +0000536 * Note: so far fatalError() SAX callbacks are not used, error()
537 * get all the callbacks for errors.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000538 */
539typedef void (*fatalErrorSAXFunc) (void *ctx,
540 const char *msg, ...);
541/**
542 * isStandaloneSAXFunc:
543 * @ctx: the user data (XML parser context)
544 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000545 * Is this document tagged standalone?
Daniel Veillard9d06d302002-01-22 18:15:52 +0000546 *
547 * Returns 1 if true
548 */
Owen Taylor3473f882001-02-23 17:55:21 +0000549typedef int (*isStandaloneSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000550/**
551 * hasInternalSubsetSAXFunc:
552 * @ctx: the user data (XML parser context)
553 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000554 * Does this document has an internal subset.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000555 *
556 * Returns 1 if true
557 */
Owen Taylor3473f882001-02-23 17:55:21 +0000558typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000559/**
560 * hasExternalSubsetSAXFunc:
561 * @ctx: the user data (XML parser context)
562 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000563 * Does this document has an external subset?
Daniel Veillard9d06d302002-01-22 18:15:52 +0000564 *
565 * Returns 1 if true
566 */
Owen Taylor3473f882001-02-23 17:55:21 +0000567typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
568
Owen Taylor3473f882001-02-23 17:55:21 +0000569struct _xmlSAXHandler {
570 internalSubsetSAXFunc internalSubset;
571 isStandaloneSAXFunc isStandalone;
572 hasInternalSubsetSAXFunc hasInternalSubset;
573 hasExternalSubsetSAXFunc hasExternalSubset;
574 resolveEntitySAXFunc resolveEntity;
575 getEntitySAXFunc getEntity;
576 entityDeclSAXFunc entityDecl;
577 notationDeclSAXFunc notationDecl;
578 attributeDeclSAXFunc attributeDecl;
579 elementDeclSAXFunc elementDecl;
580 unparsedEntityDeclSAXFunc unparsedEntityDecl;
581 setDocumentLocatorSAXFunc setDocumentLocator;
582 startDocumentSAXFunc startDocument;
583 endDocumentSAXFunc endDocument;
584 startElementSAXFunc startElement;
585 endElementSAXFunc endElement;
586 referenceSAXFunc reference;
587 charactersSAXFunc characters;
588 ignorableWhitespaceSAXFunc ignorableWhitespace;
589 processingInstructionSAXFunc processingInstruction;
590 commentSAXFunc comment;
591 warningSAXFunc warning;
592 errorSAXFunc error;
Daniel Veillard0821b152002-11-12 20:57:47 +0000593 fatalErrorSAXFunc fatalError; /* unused error() get all the errors */
Owen Taylor3473f882001-02-23 17:55:21 +0000594 getParameterEntitySAXFunc getParameterEntity;
595 cdataBlockSAXFunc cdataBlock;
596 externalSubsetSAXFunc externalSubset;
Daniel Veillardd0463562001-10-13 09:15:48 +0000597 int initialized;
Owen Taylor3473f882001-02-23 17:55:21 +0000598};
599
600/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000601 * xmlExternalEntityLoader:
602 * @URL: The System ID of the resource requested
603 * @ID: The Public ID of the resource requested
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000604 * @context: the XML parser context
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000605 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000606 * External entity loaders types.
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000607 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000608 * Returns the entity input parser.
Owen Taylor3473f882001-02-23 17:55:21 +0000609 */
Daniel Veillard9d06d302002-01-22 18:15:52 +0000610typedef xmlParserInputPtr (*xmlExternalEntityLoader) (const char *URL,
611 const char *ID,
612 xmlParserCtxtPtr context);
Owen Taylor3473f882001-02-23 17:55:21 +0000613
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000614/*
Owen Taylor3473f882001-02-23 17:55:21 +0000615 * Global variables: just the default SAX interface tables and XML
616 * version infos.
617 */
Daniel Veillard0ba59232002-02-10 13:20:39 +0000618#if 0
Owen Taylor3473f882001-02-23 17:55:21 +0000619LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000620#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000621
Daniel Veillard0ba59232002-02-10 13:20:39 +0000622/*
Owen Taylor3473f882001-02-23 17:55:21 +0000623LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
624LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
625LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
Daniel Veillardeae522a2001-04-23 13:41:34 +0000626LIBXML_DLL_IMPORT extern xmlSAXHandler docbDefaultSAXHandler;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000627 */
Owen Taylor3473f882001-02-23 17:55:21 +0000628
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000629/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000630 * Entity substitution default behavior.
Owen Taylor3473f882001-02-23 17:55:21 +0000631 */
632
Daniel Veillard0ba59232002-02-10 13:20:39 +0000633#if 0
634LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
Owen Taylor3473f882001-02-23 17:55:21 +0000635LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000636#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000637
Daniel Veillard6c4ffaf2002-02-11 08:54:05 +0000638#ifdef __cplusplus
639}
640#endif
641#include <libxml/encoding.h>
642#include <libxml/xmlIO.h>
643#include <libxml/globals.h>
644#ifdef __cplusplus
645extern "C" {
646#endif
647
Owen Taylor3473f882001-02-23 17:55:21 +0000648
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000649/*
Owen Taylor3473f882001-02-23 17:55:21 +0000650 * Init/Cleanup
651 */
652void xmlInitParser (void);
653void xmlCleanupParser (void);
654
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000655/*
Owen Taylor3473f882001-02-23 17:55:21 +0000656 * Input functions
657 */
658int xmlParserInputRead (xmlParserInputPtr in,
659 int len);
660int xmlParserInputGrow (xmlParserInputPtr in,
661 int len);
662
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000663/*
Owen Taylor3473f882001-02-23 17:55:21 +0000664 * xmlChar handling
665 */
666xmlChar * xmlStrdup (const xmlChar *cur);
667xmlChar * xmlStrndup (const xmlChar *cur,
668 int len);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000669xmlChar * xmlCharStrndup (const char *cur,
670 int len);
671xmlChar * xmlCharStrdup (const char *cur);
Owen Taylor3473f882001-02-23 17:55:21 +0000672xmlChar * xmlStrsub (const xmlChar *str,
673 int start,
674 int len);
675const xmlChar * xmlStrchr (const xmlChar *str,
676 xmlChar val);
677const xmlChar * xmlStrstr (const xmlChar *str,
Daniel Veillard77044732001-06-29 21:31:07 +0000678 const xmlChar *val);
Owen Taylor3473f882001-02-23 17:55:21 +0000679const xmlChar * xmlStrcasestr (const xmlChar *str,
680 xmlChar *val);
681int xmlStrcmp (const xmlChar *str1,
682 const xmlChar *str2);
683int xmlStrncmp (const xmlChar *str1,
684 const xmlChar *str2,
685 int len);
686int xmlStrcasecmp (const xmlChar *str1,
687 const xmlChar *str2);
688int xmlStrncasecmp (const xmlChar *str1,
689 const xmlChar *str2,
690 int len);
691int xmlStrEqual (const xmlChar *str1,
692 const xmlChar *str2);
693int xmlStrlen (const xmlChar *str);
694xmlChar * xmlStrcat (xmlChar *cur,
695 const xmlChar *add);
696xmlChar * xmlStrncat (xmlChar *cur,
697 const xmlChar *add,
698 int len);
699
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000700/*
Owen Taylor3473f882001-02-23 17:55:21 +0000701 * Basic parsing Interfaces
702 */
703xmlDocPtr xmlParseDoc (xmlChar *cur);
Daniel Veillard50822cb2001-07-26 20:05:51 +0000704xmlDocPtr xmlParseMemory (const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000705 int size);
706xmlDocPtr xmlParseFile (const char *filename);
707int xmlSubstituteEntitiesDefault(int val);
708int xmlKeepBlanksDefault (int val);
709void xmlStopParser (xmlParserCtxtPtr ctxt);
710int xmlPedanticParserDefault(int val);
Daniel Veillardd9bad132001-07-23 19:39:43 +0000711int xmlLineNumbersDefault (int val);
Owen Taylor3473f882001-02-23 17:55:21 +0000712
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000713/*
Owen Taylor3473f882001-02-23 17:55:21 +0000714 * Recovery mode
715 */
716xmlDocPtr xmlRecoverDoc (xmlChar *cur);
Daniel Veillard50822cb2001-07-26 20:05:51 +0000717xmlDocPtr xmlRecoverMemory (const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000718 int size);
719xmlDocPtr xmlRecoverFile (const char *filename);
720
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000721/*
Owen Taylor3473f882001-02-23 17:55:21 +0000722 * Less common routines and SAX interfaces
723 */
724int xmlParseDocument (xmlParserCtxtPtr ctxt);
725int xmlParseExtParsedEnt (xmlParserCtxtPtr ctxt);
726xmlDocPtr xmlSAXParseDoc (xmlSAXHandlerPtr sax,
727 xmlChar *cur,
728 int recovery);
729int xmlSAXUserParseFile (xmlSAXHandlerPtr sax,
730 void *user_data,
731 const char *filename);
732int xmlSAXUserParseMemory (xmlSAXHandlerPtr sax,
733 void *user_data,
Daniel Veillardfd7ddca2001-05-16 10:57:35 +0000734 const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000735 int size);
736xmlDocPtr xmlSAXParseMemory (xmlSAXHandlerPtr sax,
Daniel Veillard50822cb2001-07-26 20:05:51 +0000737 const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000738 int size,
739 int recovery);
Daniel Veillard8606bbb2002-11-12 12:36:52 +0000740xmlDocPtr xmlSAXParseMemoryWithData (xmlSAXHandlerPtr sax,
741 const char *buffer,
742 int size,
743 int recovery,
744 void *data);
Owen Taylor3473f882001-02-23 17:55:21 +0000745xmlDocPtr xmlSAXParseFile (xmlSAXHandlerPtr sax,
746 const char *filename,
747 int recovery);
Daniel Veillarda293c322001-10-02 13:54:14 +0000748xmlDocPtr xmlSAXParseFileWithData (xmlSAXHandlerPtr sax,
749 const char *filename,
750 int recovery,
751 void *data);
Owen Taylor3473f882001-02-23 17:55:21 +0000752xmlDocPtr xmlSAXParseEntity (xmlSAXHandlerPtr sax,
753 const char *filename);
754xmlDocPtr xmlParseEntity (const char *filename);
755xmlDtdPtr xmlParseDTD (const xmlChar *ExternalID,
756 const xmlChar *SystemID);
757xmlDtdPtr xmlSAXParseDTD (xmlSAXHandlerPtr sax,
758 const xmlChar *ExternalID,
759 const xmlChar *SystemID);
760xmlDtdPtr xmlIOParseDTD (xmlSAXHandlerPtr sax,
761 xmlParserInputBufferPtr input,
762 xmlCharEncoding enc);
763int xmlParseBalancedChunkMemory(xmlDocPtr doc,
764 xmlSAXHandlerPtr sax,
765 void *user_data,
766 int depth,
767 const xmlChar *string,
Daniel Veillardcda96922001-08-21 10:56:31 +0000768 xmlNodePtr *lst);
Daniel Veillard58e44c92002-08-02 22:19:49 +0000769int xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc,
770 xmlSAXHandlerPtr sax,
771 void *user_data,
772 int depth,
773 const xmlChar *string,
774 xmlNodePtr *lst,
775 int recover);
Owen Taylor3473f882001-02-23 17:55:21 +0000776int xmlParseExternalEntity (xmlDocPtr doc,
777 xmlSAXHandlerPtr sax,
778 void *user_data,
779 int depth,
780 const xmlChar *URL,
781 const xmlChar *ID,
Daniel Veillardcda96922001-08-21 10:56:31 +0000782 xmlNodePtr *lst);
Owen Taylor3473f882001-02-23 17:55:21 +0000783int xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx,
784 const xmlChar *URL,
785 const xmlChar *ID,
Daniel Veillardcda96922001-08-21 10:56:31 +0000786 xmlNodePtr *lst);
Owen Taylor3473f882001-02-23 17:55:21 +0000787
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000788/*
Owen Taylor3473f882001-02-23 17:55:21 +0000789 * Parser contexts handling.
790 */
791void xmlInitParserCtxt (xmlParserCtxtPtr ctxt);
792void xmlClearParserCtxt (xmlParserCtxtPtr ctxt);
793void xmlFreeParserCtxt (xmlParserCtxtPtr ctxt);
794void xmlSetupParserForBuffer (xmlParserCtxtPtr ctxt,
795 const xmlChar* buffer,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000796 const char *filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000797xmlParserCtxtPtr xmlCreateDocParserCtxt (xmlChar *cur);
798
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000799/*
Owen Taylor3473f882001-02-23 17:55:21 +0000800 * Reading/setting optional parsing features.
801 */
802
803int xmlGetFeaturesList (int *len,
804 const char **result);
805int xmlGetFeature (xmlParserCtxtPtr ctxt,
806 const char *name,
807 void *result);
808int xmlSetFeature (xmlParserCtxtPtr ctxt,
809 const char *name,
810 void *value);
811
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000812/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000813 * Interfaces for the Push mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000814 */
815xmlParserCtxtPtr xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax,
816 void *user_data,
817 const char *chunk,
818 int size,
819 const char *filename);
820int xmlParseChunk (xmlParserCtxtPtr ctxt,
821 const char *chunk,
822 int size,
823 int terminate);
824
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000825/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000826 * Special I/O mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000827 */
828
829xmlParserCtxtPtr xmlCreateIOParserCtxt (xmlSAXHandlerPtr sax,
830 void *user_data,
831 xmlInputReadCallback ioread,
832 xmlInputCloseCallback ioclose,
833 void *ioctx,
834 xmlCharEncoding enc);
835
836xmlParserInputPtr xmlNewIOInputStream (xmlParserCtxtPtr ctxt,
837 xmlParserInputBufferPtr input,
838 xmlCharEncoding enc);
839
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000840/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000841 * Node infos.
Owen Taylor3473f882001-02-23 17:55:21 +0000842 */
843const xmlParserNodeInfo*
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000844 xmlParserFindNodeInfo (const xmlParserCtxtPtr ctxt,
845 const xmlNodePtr node);
Owen Taylor3473f882001-02-23 17:55:21 +0000846void xmlInitNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
847void xmlClearNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000848unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,
849 const xmlNodePtr node);
Owen Taylor3473f882001-02-23 17:55:21 +0000850void xmlParserAddNodeInfo (xmlParserCtxtPtr ctxt,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000851 const xmlParserNodeInfoPtr info);
Owen Taylor3473f882001-02-23 17:55:21 +0000852
853/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000854 * External entities handling actually implemented in xmlIO.
Owen Taylor3473f882001-02-23 17:55:21 +0000855 */
856
857void xmlSetExternalEntityLoader(xmlExternalEntityLoader f);
858xmlExternalEntityLoader
859 xmlGetExternalEntityLoader(void);
860xmlParserInputPtr
861 xmlLoadExternalEntity (const char *URL,
862 const char *ID,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000863 xmlParserCtxtPtr ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +0000864
865#ifdef __cplusplus
866}
867#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000868#endif /* __XML_PARSER_H__ */
869