blob: 4578ad91b1bf457ced86fce0263e0581b733339e [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 */
Daniel Veillard3e59fc52003-04-18 12:34:58 +000058 /*
59 * NOTE: consumed is only tested for equality in the parser code,
60 * so even if there is an overflow this should not give troubles
61 * for parsing very large instances.
62 */
63 unsigned long consumed; /* How many xmlChars already consumed */
Owen Taylor3473f882001-02-23 17:55:21 +000064 xmlParserInputDeallocate free; /* function to deallocate the base */
65 const xmlChar *encoding; /* the encoding string for entity */
66 const xmlChar *version; /* the version string for entity */
67 int standalone; /* Was that entity marked standalone */
68};
69
70/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000071 * xmlParserNodeInfo:
72 *
Daniel Veillard61f26172002-03-12 18:46:39 +000073 * The parser can be asked to collect Node informations, i.e. at what
Owen Taylor3473f882001-02-23 17:55:21 +000074 * place in the file they were detected.
75 * NOTE: This is off by default and not very well tested.
76 */
77typedef struct _xmlParserNodeInfo xmlParserNodeInfo;
78typedef xmlParserNodeInfo *xmlParserNodeInfoPtr;
79
80struct _xmlParserNodeInfo {
81 const struct _xmlNode* node;
82 /* Position & line # that text that created the node begins & ends on */
83 unsigned long begin_pos;
84 unsigned long begin_line;
85 unsigned long end_pos;
86 unsigned long end_line;
87};
88
89typedef struct _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
90typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
91struct _xmlParserNodeInfoSeq {
92 unsigned long maximum;
93 unsigned long length;
94 xmlParserNodeInfo* buffer;
95};
96
97/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000098 * xmlParserInputState:
99 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000100 * The parser is now working also as a state based parser.
101 * The recursive one use the state info for entities processing.
Owen Taylor3473f882001-02-23 17:55:21 +0000102 */
103typedef enum {
104 XML_PARSER_EOF = -1, /* nothing is to be parsed */
105 XML_PARSER_START = 0, /* nothing has been parsed */
106 XML_PARSER_MISC, /* Misc* before int subset */
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000107 XML_PARSER_PI, /* Within a processing instruction */
Owen Taylor3473f882001-02-23 17:55:21 +0000108 XML_PARSER_DTD, /* within some DTD content */
109 XML_PARSER_PROLOG, /* Misc* after internal subset */
110 XML_PARSER_COMMENT, /* within a comment */
111 XML_PARSER_START_TAG, /* within a start tag */
112 XML_PARSER_CONTENT, /* within the content */
113 XML_PARSER_CDATA_SECTION, /* within a CDATA section */
114 XML_PARSER_END_TAG, /* within a closing tag */
115 XML_PARSER_ENTITY_DECL, /* within an entity declaration */
116 XML_PARSER_ENTITY_VALUE, /* within an entity value in a decl */
117 XML_PARSER_ATTRIBUTE_VALUE, /* within an attribute value */
118 XML_PARSER_SYSTEM_LITERAL, /* within a SYSTEM value */
119 XML_PARSER_EPILOG, /* the Misc* after the last end tag */
Daniel Veillard4a7ae502002-02-18 19:18:17 +0000120 XML_PARSER_IGNORE, /* within an IGNORED section */
121 XML_PARSER_PUBLIC_LITERAL /* within a PUBLIC value */
Owen Taylor3473f882001-02-23 17:55:21 +0000122} xmlParserInputState;
123
124/**
Daniel Veillardd16df9f2001-05-23 13:44:21 +0000125 * XML_DETECT_IDS:
126 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000127 * Bit in the loadsubset context field to tell to do ID/REFs lookups.
128 * Use it to initialize xmlLoadExtDtdDefaultValue.
Daniel Veillardd16df9f2001-05-23 13:44:21 +0000129 */
130#define XML_DETECT_IDS 2
131
132/**
133 * XML_COMPLETE_ATTRS:
134 *
135 * Bit in the loadsubset context field to tell to do complete the
Daniel Veillard61f26172002-03-12 18:46:39 +0000136 * elements attributes lists with the ones defaulted from the DTDs.
137 * Use it to initialize xmlLoadExtDtdDefaultValue.
Daniel Veillardd16df9f2001-05-23 13:44:21 +0000138 */
139#define XML_COMPLETE_ATTRS 4
140
141/**
Daniel Veillardef8dd7b2003-03-23 12:02:56 +0000142 * XML_SKIP_IDS:
143 *
144 * Bit in the loadsubset context field to tell to not do ID/REFs registration.
145 * Used to initialize xmlLoadExtDtdDefaultValue in some special cases.
146 */
147#define XML_SKIP_IDS 8
148
149/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000150 * xmlParserCtxt:
151 *
Owen Taylor3473f882001-02-23 17:55:21 +0000152 * The parser context.
Daniel Veillard61f26172002-03-12 18:46:39 +0000153 * NOTE This doesn't completely define the parser state, the (current ?)
Owen Taylor3473f882001-02-23 17:55:21 +0000154 * design of the parser uses recursive function calls since this allow
155 * and easy mapping from the production rules of the specification
156 * to the actual code. The drawback is that the actual function call
157 * also reflect the parser state. However most of the parsing routines
158 * takes as the only argument the parser context pointer, so migrating
159 * to a state based parser for progressive parsing shouldn't be too hard.
160 */
Owen Taylor3473f882001-02-23 17:55:21 +0000161struct _xmlParserCtxt {
162 struct _xmlSAXHandler *sax; /* The SAX handler */
163 void *userData; /* For SAX interface only, used by DOM build */
164 xmlDocPtr myDoc; /* the document being built */
165 int wellFormed; /* is the document well formed */
166 int replaceEntities; /* shall we replace entities ? */
167 const xmlChar *version; /* the XML version string */
168 const xmlChar *encoding; /* the declared encoding, if any */
169 int standalone; /* standalone document */
170 int html; /* an HTML(1)/Docbook(2) document */
171
172 /* Input stream stack */
173 xmlParserInputPtr input; /* Current input stream */
174 int inputNr; /* Number of current input streams */
175 int inputMax; /* Max number of input streams */
176 xmlParserInputPtr *inputTab; /* stack of inputs */
177
178 /* Node analysis stack only used for DOM building */
179 xmlNodePtr node; /* Current parsed Node */
180 int nodeNr; /* Depth of the parsing stack */
181 int nodeMax; /* Max depth of the parsing stack */
182 xmlNodePtr *nodeTab; /* array of nodes */
183
184 int record_info; /* Whether node info should be kept */
185 xmlParserNodeInfoSeq node_seq; /* info about each node parsed */
186
187 int errNo; /* error code */
188
189 int hasExternalSubset; /* reference and external subset */
190 int hasPErefs; /* the internal subset has PE refs */
191 int external; /* are we parsing an external entity */
192
193 int valid; /* is the document valid */
194 int validate; /* shall we try to validate ? */
195 xmlValidCtxt vctxt; /* The validity context */
196
197 xmlParserInputState instate; /* current type of input */
198 int token; /* next char look-ahead */
199
200 char *directory; /* the data directory */
201
202 /* Node name stack */
203 xmlChar *name; /* Current parsed Node */
204 int nameNr; /* Depth of the parsing stack */
205 int nameMax; /* Max depth of the parsing stack */
206 xmlChar * *nameTab; /* array of nodes */
207
208 long nbChars; /* number of xmlChar processed */
209 long checkIndex; /* used by progressive parsing lookup */
210 int keepBlanks; /* ugly but ... */
211 int disableSAX; /* SAX callbacks are disabled */
212 int inSubset; /* Parsing is in int 1/ext 2 subset */
213 xmlChar * intSubName; /* name of subset */
214 xmlChar * extSubURI; /* URI of external subset */
215 xmlChar * extSubSystem; /* SYSTEM ID of external subset */
216
217 /* xml:space values */
218 int * space; /* Should the parser preserve spaces */
219 int spaceNr; /* Depth of the parsing stack */
220 int spaceMax; /* Max depth of the parsing stack */
221 int * spaceTab; /* array of space infos */
222
223 int depth; /* to prevent entity substitution loops */
224 xmlParserInputPtr entity; /* used to check entities boundaries */
225 int charset; /* encoding of the in-memory content
226 actually an xmlCharEncoding */
227 int nodelen; /* Those two fields are there to */
228 int nodemem; /* Speed up large node parsing */
229 int pedantic; /* signal pedantic warnings */
230 void *_private; /* For user data, libxml won't touch it */
231
232 int loadsubset; /* should the external subset be loaded */
Daniel Veillardd9bad132001-07-23 19:39:43 +0000233 int linenumbers; /* set line number in element content */
Daniel Veillard5d90b6c2001-08-22 14:29:45 +0000234 void *catalogs; /* document's own catalog */
Daniel Veillarddad3f682002-11-17 16:47:27 +0000235 int recovery; /* run in recovery mode */
Daniel Veillarda880b122003-04-21 21:36:41 +0000236 int progressive; /* is this a progressive parsing */
Owen Taylor3473f882001-02-23 17:55:21 +0000237};
238
239/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000240 * xmlSAXLocator:
241 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000242 * A SAX Locator.
Owen Taylor3473f882001-02-23 17:55:21 +0000243 */
Owen Taylor3473f882001-02-23 17:55:21 +0000244struct _xmlSAXLocator {
245 const xmlChar *(*getPublicId)(void *ctx);
246 const xmlChar *(*getSystemId)(void *ctx);
247 int (*getLineNumber)(void *ctx);
248 int (*getColumnNumber)(void *ctx);
249};
250
251/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000252 * xmlSAXHandler:
253 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000254 * A SAX handler is bunch of callbacks called by the parser when processing
Owen Taylor3473f882001-02-23 17:55:21 +0000255 * of the input generate data or structure informations.
256 */
257
Daniel Veillard9d06d302002-01-22 18:15:52 +0000258/**
259 * resolveEntitySAXFunc:
260 * @ctx: the user data (XML parser context)
261 * @publicId: The public ID of the entity
262 * @systemId: The system ID of the entity
263 *
264 * Callback:
265 * The entity loader, to control the loading of external entities,
266 * the application can either:
267 * - override this resolveEntity() callback in the SAX block
268 * - or better use the xmlSetExternalEntityLoader() function to
269 * set up it's own entity resolution routine
270 *
271 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
272 */
Owen Taylor3473f882001-02-23 17:55:21 +0000273typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000274 const xmlChar *publicId,
275 const xmlChar *systemId);
276/**
277 * internalSubsetSAXFunc:
278 * @ctx: the user data (XML parser context)
279 * @name: the root element name
280 * @ExternalID: the external ID
281 * @SystemID: the SYSTEM ID (e.g. filename or URL)
282 *
283 * Callback on internal subset declaration.
284 */
285typedef void (*internalSubsetSAXFunc) (void *ctx,
286 const xmlChar *name,
287 const xmlChar *ExternalID,
288 const xmlChar *SystemID);
289/**
290 * externalSubsetSAXFunc:
291 * @ctx: the user data (XML parser context)
292 * @name: the root element name
293 * @ExternalID: the external ID
294 * @SystemID: the SYSTEM ID (e.g. filename or URL)
295 *
296 * Callback on external subset declaration.
297 */
298typedef void (*externalSubsetSAXFunc) (void *ctx,
299 const xmlChar *name,
300 const xmlChar *ExternalID,
301 const xmlChar *SystemID);
302/**
303 * getEntitySAXFunc:
304 * @ctx: the user data (XML parser context)
305 * @name: The entity name
306 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000307 * Get an entity by name.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000308 *
309 * Returns the xmlEntityPtr if found.
310 */
Owen Taylor3473f882001-02-23 17:55:21 +0000311typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000312 const xmlChar *name);
313/**
314 * getParameterEntitySAXFunc:
315 * @ctx: the user data (XML parser context)
316 * @name: The entity name
317 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000318 * Get a parameter entity by name.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000319 *
320 * Returns the xmlEntityPtr if found.
321 */
Owen Taylor3473f882001-02-23 17:55:21 +0000322typedef xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000323 const xmlChar *name);
324/**
325 * entityDeclSAXFunc:
326 * @ctx: the user data (XML parser context)
327 * @name: the entity name
328 * @type: the entity type
329 * @publicId: The public ID of the entity
330 * @systemId: The system ID of the entity
331 * @content: the entity value (without processing).
332 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000333 * An entity definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000334 */
Owen Taylor3473f882001-02-23 17:55:21 +0000335typedef void (*entityDeclSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000336 const xmlChar *name,
337 int type,
338 const xmlChar *publicId,
339 const xmlChar *systemId,
340 xmlChar *content);
341/**
342 * notationDeclSAXFunc:
343 * @ctx: the user data (XML parser context)
344 * @name: The name of the notation
345 * @publicId: The public ID of the entity
346 * @systemId: The system ID of the entity
347 *
348 * What to do when a notation declaration has been parsed.
349 */
350typedef void (*notationDeclSAXFunc)(void *ctx,
351 const xmlChar *name,
352 const xmlChar *publicId,
353 const xmlChar *systemId);
354/**
355 * attributeDeclSAXFunc:
356 * @ctx: the user data (XML parser context)
357 * @elem: the name of the element
358 * @fullname: the attribute name
359 * @type: the attribute type
360 * @def: the type of default value
361 * @defaultValue: the attribute default value
362 * @tree: the tree of enumerated value set
363 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000364 * An attribute definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000365 */
366typedef void (*attributeDeclSAXFunc)(void *ctx,
367 const xmlChar *elem,
368 const xmlChar *fullname,
369 int type,
370 int def,
371 const xmlChar *defaultValue,
372 xmlEnumerationPtr tree);
373/**
374 * elementDeclSAXFunc:
375 * @ctx: the user data (XML parser context)
376 * @name: the element name
377 * @type: the element type
378 * @content: the element value tree
379 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000380 * An element definition has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000381 */
382typedef void (*elementDeclSAXFunc)(void *ctx,
383 const xmlChar *name,
384 int type,
385 xmlElementContentPtr content);
386/**
387 * unparsedEntityDeclSAXFunc:
388 * @ctx: the user data (XML parser context)
389 * @name: The name of the entity
390 * @publicId: The public ID of the entity
391 * @systemId: The system ID of the entity
392 * @notationName: the name of the notation
393 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000394 * What to do when an unparsed entity declaration is parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000395 */
Owen Taylor3473f882001-02-23 17:55:21 +0000396typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000397 const xmlChar *name,
398 const xmlChar *publicId,
399 const xmlChar *systemId,
400 const xmlChar *notationName);
401/**
402 * setDocumentLocatorSAXFunc:
403 * @ctx: the user data (XML parser context)
404 * @loc: A SAX Locator
405 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000406 * Receive the document locator at startup, actually xmlDefaultSAXLocator.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000407 * Everything is available on the context, so this is useless in our case.
408 */
Owen Taylor3473f882001-02-23 17:55:21 +0000409typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000410 xmlSAXLocatorPtr loc);
411/**
412 * startDocumentSAXFunc:
413 * @ctx: the user data (XML parser context)
414 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000415 * Called when the document start being processed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000416 */
Owen Taylor3473f882001-02-23 17:55:21 +0000417typedef void (*startDocumentSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000418/**
419 * endDocumentSAXFunc:
420 * @ctx: the user data (XML parser context)
421 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000422 * Called when the document end has been detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000423 */
Owen Taylor3473f882001-02-23 17:55:21 +0000424typedef void (*endDocumentSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000425/**
426 * startElementSAXFunc:
427 * @ctx: the user data (XML parser context)
428 * @name: The element name, including namespace prefix
429 * @atts: An array of name/value attributes pairs, NULL terminated
430 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000431 * Called when an opening tag has been processed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000432 */
433typedef void (*startElementSAXFunc) (void *ctx,
434 const xmlChar *name,
435 const xmlChar **atts);
436/**
437 * endElementSAXFunc:
438 * @ctx: the user data (XML parser context)
439 * @name: The element name
440 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000441 * Called when the end of an element has been detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000442 */
443typedef void (*endElementSAXFunc) (void *ctx,
444 const xmlChar *name);
445/**
446 * attributeSAXFunc:
447 * @ctx: the user data (XML parser context)
448 * @name: The attribute name, including namespace prefix
449 * @value: The attribute value
450 *
451 * Handle an attribute that has been read by the parser.
452 * The default handling is to convert the attribute into an
453 * DOM subtree and past it in a new xmlAttr element added to
454 * the element.
455 */
456typedef void (*attributeSAXFunc) (void *ctx,
457 const xmlChar *name,
458 const xmlChar *value);
459/**
460 * referenceSAXFunc:
461 * @ctx: the user data (XML parser context)
462 * @name: The entity name
463 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000464 * Called when an entity reference is detected.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000465 */
466typedef void (*referenceSAXFunc) (void *ctx,
467 const xmlChar *name);
468/**
469 * charactersSAXFunc:
470 * @ctx: the user data (XML parser context)
471 * @ch: a xmlChar string
472 * @len: the number of xmlChar
473 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000474 * Receiving some chars from the parser.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000475 */
476typedef void (*charactersSAXFunc) (void *ctx,
477 const xmlChar *ch,
478 int len);
479/**
480 * ignorableWhitespaceSAXFunc:
481 * @ctx: the user data (XML parser context)
482 * @ch: a xmlChar string
483 * @len: the number of xmlChar
484 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000485 * Receiving some ignorable whitespaces from the parser.
486 * UNUSED: by default the DOM building will use characters.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000487 */
Owen Taylor3473f882001-02-23 17:55:21 +0000488typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000489 const xmlChar *ch,
490 int len);
491/**
492 * processingInstructionSAXFunc:
493 * @ctx: the user data (XML parser context)
494 * @target: the target name
495 * @data: the PI data's
496 *
497 * A processing instruction has been parsed.
498 */
Owen Taylor3473f882001-02-23 17:55:21 +0000499typedef void (*processingInstructionSAXFunc) (void *ctx,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000500 const xmlChar *target,
501 const xmlChar *data);
502/**
503 * commentSAXFunc:
504 * @ctx: the user data (XML parser context)
505 * @value: the comment content
506 *
507 * A comment has been parsed.
508 */
509typedef void (*commentSAXFunc) (void *ctx,
510 const xmlChar *value);
511/**
512 * cdataBlockSAXFunc:
513 * @ctx: the user data (XML parser context)
514 * @value: The pcdata content
515 * @len: the block length
516 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000517 * Called when a pcdata block has been parsed.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000518 */
519typedef void (*cdataBlockSAXFunc) (
520 void *ctx,
521 const xmlChar *value,
522 int len);
523/**
524 * warningSAXFunc:
525 * @ctx: an XML parser context
526 * @msg: the message to display/transmit
527 * @...: extra parameters for the message display
528 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000529 * Display and format a warning messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000530 */
531typedef void (*warningSAXFunc) (void *ctx,
532 const char *msg, ...);
533/**
534 * errorSAXFunc:
535 * @ctx: an XML parser context
536 * @msg: the message to display/transmit
537 * @...: extra parameters for the message display
538 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000539 * Display and format an error messages, callback.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000540 */
541typedef void (*errorSAXFunc) (void *ctx,
542 const char *msg, ...);
543/**
544 * fatalErrorSAXFunc:
545 * @ctx: an XML parser context
546 * @msg: the message to display/transmit
547 * @...: extra parameters for the message display
548 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000549 * Display and format fatal error messages, callback.
Daniel Veillard0821b152002-11-12 20:57:47 +0000550 * Note: so far fatalError() SAX callbacks are not used, error()
551 * get all the callbacks for errors.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000552 */
553typedef void (*fatalErrorSAXFunc) (void *ctx,
554 const char *msg, ...);
555/**
556 * isStandaloneSAXFunc:
557 * @ctx: the user data (XML parser context)
558 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000559 * Is this document tagged standalone?
Daniel Veillard9d06d302002-01-22 18:15:52 +0000560 *
561 * Returns 1 if true
562 */
Owen Taylor3473f882001-02-23 17:55:21 +0000563typedef int (*isStandaloneSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000564/**
565 * hasInternalSubsetSAXFunc:
566 * @ctx: the user data (XML parser context)
567 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000568 * Does this document has an internal subset.
Daniel Veillard9d06d302002-01-22 18:15:52 +0000569 *
570 * Returns 1 if true
571 */
Owen Taylor3473f882001-02-23 17:55:21 +0000572typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000573/**
574 * hasExternalSubsetSAXFunc:
575 * @ctx: the user data (XML parser context)
576 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000577 * Does this document has an external subset?
Daniel Veillard9d06d302002-01-22 18:15:52 +0000578 *
579 * Returns 1 if true
580 */
Owen Taylor3473f882001-02-23 17:55:21 +0000581typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
582
Owen Taylor3473f882001-02-23 17:55:21 +0000583struct _xmlSAXHandler {
584 internalSubsetSAXFunc internalSubset;
585 isStandaloneSAXFunc isStandalone;
586 hasInternalSubsetSAXFunc hasInternalSubset;
587 hasExternalSubsetSAXFunc hasExternalSubset;
588 resolveEntitySAXFunc resolveEntity;
589 getEntitySAXFunc getEntity;
590 entityDeclSAXFunc entityDecl;
591 notationDeclSAXFunc notationDecl;
592 attributeDeclSAXFunc attributeDecl;
593 elementDeclSAXFunc elementDecl;
594 unparsedEntityDeclSAXFunc unparsedEntityDecl;
595 setDocumentLocatorSAXFunc setDocumentLocator;
596 startDocumentSAXFunc startDocument;
597 endDocumentSAXFunc endDocument;
598 startElementSAXFunc startElement;
599 endElementSAXFunc endElement;
600 referenceSAXFunc reference;
601 charactersSAXFunc characters;
602 ignorableWhitespaceSAXFunc ignorableWhitespace;
603 processingInstructionSAXFunc processingInstruction;
604 commentSAXFunc comment;
605 warningSAXFunc warning;
606 errorSAXFunc error;
Daniel Veillard0821b152002-11-12 20:57:47 +0000607 fatalErrorSAXFunc fatalError; /* unused error() get all the errors */
Owen Taylor3473f882001-02-23 17:55:21 +0000608 getParameterEntitySAXFunc getParameterEntity;
609 cdataBlockSAXFunc cdataBlock;
610 externalSubsetSAXFunc externalSubset;
Daniel Veillardd0463562001-10-13 09:15:48 +0000611 int initialized;
Owen Taylor3473f882001-02-23 17:55:21 +0000612};
613
614/**
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000615 * xmlExternalEntityLoader:
616 * @URL: The System ID of the resource requested
617 * @ID: The Public ID of the resource requested
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000618 * @context: the XML parser context
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000619 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000620 * External entity loaders types.
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000621 *
Daniel Veillard61f26172002-03-12 18:46:39 +0000622 * Returns the entity input parser.
Owen Taylor3473f882001-02-23 17:55:21 +0000623 */
Daniel Veillard9d06d302002-01-22 18:15:52 +0000624typedef xmlParserInputPtr (*xmlExternalEntityLoader) (const char *URL,
625 const char *ID,
626 xmlParserCtxtPtr context);
Owen Taylor3473f882001-02-23 17:55:21 +0000627
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000628/*
Owen Taylor3473f882001-02-23 17:55:21 +0000629 * Global variables: just the default SAX interface tables and XML
630 * version infos.
631 */
Daniel Veillard0ba59232002-02-10 13:20:39 +0000632#if 0
Owen Taylor3473f882001-02-23 17:55:21 +0000633LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000634#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000635
Daniel Veillard0ba59232002-02-10 13:20:39 +0000636/*
Owen Taylor3473f882001-02-23 17:55:21 +0000637LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
638LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
639LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
Daniel Veillardeae522a2001-04-23 13:41:34 +0000640LIBXML_DLL_IMPORT extern xmlSAXHandler docbDefaultSAXHandler;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000641 */
Owen Taylor3473f882001-02-23 17:55:21 +0000642
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000643/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000644 * Entity substitution default behavior.
Owen Taylor3473f882001-02-23 17:55:21 +0000645 */
646
Daniel Veillard0ba59232002-02-10 13:20:39 +0000647#if 0
648LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
Owen Taylor3473f882001-02-23 17:55:21 +0000649LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
Daniel Veillard0ba59232002-02-10 13:20:39 +0000650#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000651
Daniel Veillard6c4ffaf2002-02-11 08:54:05 +0000652#ifdef __cplusplus
653}
654#endif
655#include <libxml/encoding.h>
656#include <libxml/xmlIO.h>
657#include <libxml/globals.h>
658#ifdef __cplusplus
659extern "C" {
660#endif
661
Owen Taylor3473f882001-02-23 17:55:21 +0000662
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000663/*
Owen Taylor3473f882001-02-23 17:55:21 +0000664 * Init/Cleanup
665 */
666void xmlInitParser (void);
667void xmlCleanupParser (void);
668
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000669/*
Owen Taylor3473f882001-02-23 17:55:21 +0000670 * Input functions
671 */
672int xmlParserInputRead (xmlParserInputPtr in,
673 int len);
674int xmlParserInputGrow (xmlParserInputPtr in,
675 int len);
676
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000677/*
Owen Taylor3473f882001-02-23 17:55:21 +0000678 * xmlChar handling
679 */
680xmlChar * xmlStrdup (const xmlChar *cur);
681xmlChar * xmlStrndup (const xmlChar *cur,
682 int len);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000683xmlChar * xmlCharStrndup (const char *cur,
684 int len);
685xmlChar * xmlCharStrdup (const char *cur);
Owen Taylor3473f882001-02-23 17:55:21 +0000686xmlChar * xmlStrsub (const xmlChar *str,
687 int start,
688 int len);
689const xmlChar * xmlStrchr (const xmlChar *str,
690 xmlChar val);
691const xmlChar * xmlStrstr (const xmlChar *str,
Daniel Veillard77044732001-06-29 21:31:07 +0000692 const xmlChar *val);
Owen Taylor3473f882001-02-23 17:55:21 +0000693const xmlChar * xmlStrcasestr (const xmlChar *str,
694 xmlChar *val);
695int xmlStrcmp (const xmlChar *str1,
696 const xmlChar *str2);
697int xmlStrncmp (const xmlChar *str1,
698 const xmlChar *str2,
699 int len);
700int xmlStrcasecmp (const xmlChar *str1,
701 const xmlChar *str2);
702int xmlStrncasecmp (const xmlChar *str1,
703 const xmlChar *str2,
704 int len);
705int xmlStrEqual (const xmlChar *str1,
706 const xmlChar *str2);
707int xmlStrlen (const xmlChar *str);
708xmlChar * xmlStrcat (xmlChar *cur,
709 const xmlChar *add);
710xmlChar * xmlStrncat (xmlChar *cur,
711 const xmlChar *add,
712 int len);
713
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000714/*
Owen Taylor3473f882001-02-23 17:55:21 +0000715 * Basic parsing Interfaces
716 */
717xmlDocPtr xmlParseDoc (xmlChar *cur);
Daniel Veillard50822cb2001-07-26 20:05:51 +0000718xmlDocPtr xmlParseMemory (const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000719 int size);
720xmlDocPtr xmlParseFile (const char *filename);
721int xmlSubstituteEntitiesDefault(int val);
722int xmlKeepBlanksDefault (int val);
723void xmlStopParser (xmlParserCtxtPtr ctxt);
724int xmlPedanticParserDefault(int val);
Daniel Veillardd9bad132001-07-23 19:39:43 +0000725int xmlLineNumbersDefault (int val);
Owen Taylor3473f882001-02-23 17:55:21 +0000726
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000727/*
Owen Taylor3473f882001-02-23 17:55:21 +0000728 * Recovery mode
729 */
730xmlDocPtr xmlRecoverDoc (xmlChar *cur);
Daniel Veillard50822cb2001-07-26 20:05:51 +0000731xmlDocPtr xmlRecoverMemory (const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000732 int size);
733xmlDocPtr xmlRecoverFile (const char *filename);
734
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000735/*
Owen Taylor3473f882001-02-23 17:55:21 +0000736 * Less common routines and SAX interfaces
737 */
738int xmlParseDocument (xmlParserCtxtPtr ctxt);
739int xmlParseExtParsedEnt (xmlParserCtxtPtr ctxt);
740xmlDocPtr xmlSAXParseDoc (xmlSAXHandlerPtr sax,
741 xmlChar *cur,
742 int recovery);
743int xmlSAXUserParseFile (xmlSAXHandlerPtr sax,
744 void *user_data,
745 const char *filename);
746int xmlSAXUserParseMemory (xmlSAXHandlerPtr sax,
747 void *user_data,
Daniel Veillardfd7ddca2001-05-16 10:57:35 +0000748 const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000749 int size);
750xmlDocPtr xmlSAXParseMemory (xmlSAXHandlerPtr sax,
Daniel Veillard50822cb2001-07-26 20:05:51 +0000751 const char *buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000752 int size,
753 int recovery);
Daniel Veillard8606bbb2002-11-12 12:36:52 +0000754xmlDocPtr xmlSAXParseMemoryWithData (xmlSAXHandlerPtr sax,
755 const char *buffer,
756 int size,
757 int recovery,
758 void *data);
Owen Taylor3473f882001-02-23 17:55:21 +0000759xmlDocPtr xmlSAXParseFile (xmlSAXHandlerPtr sax,
760 const char *filename,
761 int recovery);
Daniel Veillarda293c322001-10-02 13:54:14 +0000762xmlDocPtr xmlSAXParseFileWithData (xmlSAXHandlerPtr sax,
763 const char *filename,
764 int recovery,
765 void *data);
Owen Taylor3473f882001-02-23 17:55:21 +0000766xmlDocPtr xmlSAXParseEntity (xmlSAXHandlerPtr sax,
767 const char *filename);
768xmlDocPtr xmlParseEntity (const char *filename);
769xmlDtdPtr xmlParseDTD (const xmlChar *ExternalID,
770 const xmlChar *SystemID);
771xmlDtdPtr xmlSAXParseDTD (xmlSAXHandlerPtr sax,
772 const xmlChar *ExternalID,
773 const xmlChar *SystemID);
774xmlDtdPtr xmlIOParseDTD (xmlSAXHandlerPtr sax,
775 xmlParserInputBufferPtr input,
776 xmlCharEncoding enc);
777int xmlParseBalancedChunkMemory(xmlDocPtr doc,
778 xmlSAXHandlerPtr sax,
779 void *user_data,
780 int depth,
781 const xmlChar *string,
Daniel Veillardcda96922001-08-21 10:56:31 +0000782 xmlNodePtr *lst);
Daniel Veillard58e44c92002-08-02 22:19:49 +0000783int xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc,
784 xmlSAXHandlerPtr sax,
785 void *user_data,
786 int depth,
787 const xmlChar *string,
788 xmlNodePtr *lst,
789 int recover);
Owen Taylor3473f882001-02-23 17:55:21 +0000790int xmlParseExternalEntity (xmlDocPtr doc,
791 xmlSAXHandlerPtr sax,
792 void *user_data,
793 int depth,
794 const xmlChar *URL,
795 const xmlChar *ID,
Daniel Veillardcda96922001-08-21 10:56:31 +0000796 xmlNodePtr *lst);
Owen Taylor3473f882001-02-23 17:55:21 +0000797int xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx,
798 const xmlChar *URL,
799 const xmlChar *ID,
Daniel Veillardcda96922001-08-21 10:56:31 +0000800 xmlNodePtr *lst);
Owen Taylor3473f882001-02-23 17:55:21 +0000801
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000802/*
Owen Taylor3473f882001-02-23 17:55:21 +0000803 * Parser contexts handling.
804 */
805void xmlInitParserCtxt (xmlParserCtxtPtr ctxt);
806void xmlClearParserCtxt (xmlParserCtxtPtr ctxt);
807void xmlFreeParserCtxt (xmlParserCtxtPtr ctxt);
808void xmlSetupParserForBuffer (xmlParserCtxtPtr ctxt,
809 const xmlChar* buffer,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000810 const char *filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000811xmlParserCtxtPtr xmlCreateDocParserCtxt (xmlChar *cur);
812
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000813/*
Owen Taylor3473f882001-02-23 17:55:21 +0000814 * Reading/setting optional parsing features.
815 */
816
817int xmlGetFeaturesList (int *len,
818 const char **result);
819int xmlGetFeature (xmlParserCtxtPtr ctxt,
820 const char *name,
821 void *result);
822int xmlSetFeature (xmlParserCtxtPtr ctxt,
823 const char *name,
824 void *value);
825
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000826/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000827 * Interfaces for the Push mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000828 */
829xmlParserCtxtPtr xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax,
830 void *user_data,
831 const char *chunk,
832 int size,
833 const char *filename);
834int xmlParseChunk (xmlParserCtxtPtr ctxt,
835 const char *chunk,
836 int size,
837 int terminate);
838
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000839/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000840 * Special I/O mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000841 */
842
843xmlParserCtxtPtr xmlCreateIOParserCtxt (xmlSAXHandlerPtr sax,
844 void *user_data,
845 xmlInputReadCallback ioread,
846 xmlInputCloseCallback ioclose,
847 void *ioctx,
848 xmlCharEncoding enc);
849
850xmlParserInputPtr xmlNewIOInputStream (xmlParserCtxtPtr ctxt,
851 xmlParserInputBufferPtr input,
852 xmlCharEncoding enc);
853
Daniel Veillardf69bb4b2001-05-19 13:24:56 +0000854/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000855 * Node infos.
Owen Taylor3473f882001-02-23 17:55:21 +0000856 */
857const xmlParserNodeInfo*
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000858 xmlParserFindNodeInfo (const xmlParserCtxtPtr ctxt,
859 const xmlNodePtr node);
Owen Taylor3473f882001-02-23 17:55:21 +0000860void xmlInitNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
861void xmlClearNodeInfoSeq (xmlParserNodeInfoSeqPtr seq);
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000862unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,
863 const xmlNodePtr node);
Owen Taylor3473f882001-02-23 17:55:21 +0000864void xmlParserAddNodeInfo (xmlParserCtxtPtr ctxt,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000865 const xmlParserNodeInfoPtr info);
Owen Taylor3473f882001-02-23 17:55:21 +0000866
867/*
Daniel Veillard61f26172002-03-12 18:46:39 +0000868 * External entities handling actually implemented in xmlIO.
Owen Taylor3473f882001-02-23 17:55:21 +0000869 */
870
871void xmlSetExternalEntityLoader(xmlExternalEntityLoader f);
872xmlExternalEntityLoader
873 xmlGetExternalEntityLoader(void);
874xmlParserInputPtr
875 xmlLoadExternalEntity (const char *URL,
876 const char *ID,
Daniel Veillard9d06d302002-01-22 18:15:52 +0000877 xmlParserCtxtPtr ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +0000878
879#ifdef __cplusplus
880}
881#endif
Owen Taylor3473f882001-02-23 17:55:21 +0000882#endif /* __XML_PARSER_H__ */
883