blob: 35c316bc606aa780a999ffd9a3a3fb0deda36113 [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * SAX.c : Default SAX handler to build a tree.
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * Daniel Veillard <daniel@veillard.com>
Owen Taylor3473f882001-02-23 17:55:21 +00007 */
8
9
Bjorn Reese70a9da52001-04-21 16:57:29 +000010#include "libxml.h"
Owen Taylor3473f882001-02-23 17:55:21 +000011#include <stdlib.h>
12#include <string.h>
13#include <libxml/xmlmemory.h>
14#include <libxml/tree.h>
15#include <libxml/parser.h>
16#include <libxml/parserInternals.h>
17#include <libxml/valid.h>
18#include <libxml/entities.h>
19#include <libxml/xmlerror.h>
20#include <libxml/debugXML.h>
21#include <libxml/xmlIO.h>
22#include <libxml/SAX.h>
23#include <libxml/uri.h>
Daniel Veillard48da9102001-08-07 01:10:10 +000024#include <libxml/valid.h>
Owen Taylor3473f882001-02-23 17:55:21 +000025#include <libxml/HTMLtree.h>
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000026#include <libxml/globals.h>
Owen Taylor3473f882001-02-23 17:55:21 +000027
28/* #define DEBUG_SAX */
29/* #define DEBUG_SAX_TREE */
30
31/**
32 * getPublicId:
33 * @ctx: the user data (XML parser context)
34 *
35 * Return the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN"
36 *
37 * Returns a xmlChar *
38 */
39const xmlChar *
Daniel Veillardc86a4fa2001-03-26 16:28:29 +000040getPublicId(void *ctx ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +000041{
42 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
43 return(NULL);
44}
45
46/**
47 * getSystemId:
48 * @ctx: the user data (XML parser context)
49 *
50 * Return the system ID, basically URL or filename e.g.
51 * http://www.sgmlsource.com/dtds/memo.dtd
52 *
53 * Returns a xmlChar *
54 */
55const xmlChar *
56getSystemId(void *ctx)
57{
58 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Daniel Veillard56a4cb82001-03-24 17:00:36 +000059 return((const xmlChar *) ctxt->input->filename);
Owen Taylor3473f882001-02-23 17:55:21 +000060}
61
62/**
63 * getLineNumber:
64 * @ctx: the user data (XML parser context)
65 *
66 * Return the line number of the current parsing point.
67 *
68 * Returns an int
69 */
70int
71getLineNumber(void *ctx)
72{
73 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
74 return(ctxt->input->line);
75}
76
77/**
78 * getColumnNumber:
79 * @ctx: the user data (XML parser context)
80 *
81 * Return the column number of the current parsing point.
82 *
83 * Returns an int
84 */
85int
86getColumnNumber(void *ctx)
87{
88 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
89 return(ctxt->input->col);
90}
91
Owen Taylor3473f882001-02-23 17:55:21 +000092/**
93 * isStandalone:
94 * @ctx: the user data (XML parser context)
95 *
96 * Is this document tagged standalone ?
97 *
98 * Returns 1 if true
99 */
100int
101isStandalone(void *ctx)
102{
103 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
104 return(ctxt->myDoc->standalone == 1);
105}
106
107/**
108 * hasInternalSubset:
109 * @ctx: the user data (XML parser context)
110 *
111 * Does this document has an internal subset
112 *
113 * Returns 1 if true
114 */
115int
116hasInternalSubset(void *ctx)
117{
118 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
119 return(ctxt->myDoc->intSubset != NULL);
120}
121
122/**
123 * hasExternalSubset:
124 * @ctx: the user data (XML parser context)
125 *
126 * Does this document has an external subset
127 *
128 * Returns 1 if true
129 */
130int
131hasExternalSubset(void *ctx)
132{
133 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
134 return(ctxt->myDoc->extSubset != NULL);
135}
136
137/**
138 * internalSubset:
139 * @ctx: the user data (XML parser context)
140 * @name: the root element name
141 * @ExternalID: the external ID
142 * @SystemID: the SYSTEM ID (e.g. filename or URL)
143 *
144 * Callback on internal subset declaration.
145 */
146void
147internalSubset(void *ctx, const xmlChar *name,
148 const xmlChar *ExternalID, const xmlChar *SystemID)
149{
150 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
151 xmlDtdPtr dtd;
152#ifdef DEBUG_SAX
153 xmlGenericError(xmlGenericErrorContext,
154 "SAX.internalSubset(%s, %s, %s)\n",
155 name, ExternalID, SystemID);
156#endif
157
158 if (ctxt->myDoc == NULL)
159 return;
160 dtd = xmlGetIntSubset(ctxt->myDoc);
161 if (dtd != NULL) {
162 if (ctxt->html)
163 return;
164 xmlUnlinkNode((xmlNodePtr) dtd);
165 xmlFreeDtd(dtd);
166 ctxt->myDoc->intSubset = NULL;
167 }
168 ctxt->myDoc->intSubset =
169 xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID);
170}
171
172/**
173 * externalSubset:
174 * @ctx: the user data (XML parser context)
175 * @name: the root element name
176 * @ExternalID: the external ID
177 * @SystemID: the SYSTEM ID (e.g. filename or URL)
178 *
179 * Callback on external subset declaration.
180 */
181void
182externalSubset(void *ctx, const xmlChar *name,
183 const xmlChar *ExternalID, const xmlChar *SystemID)
184{
185 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
186#ifdef DEBUG_SAX
187 xmlGenericError(xmlGenericErrorContext,
188 "SAX.externalSubset(%s, %s, %s)\n",
189 name, ExternalID, SystemID);
190#endif
191 if (((ExternalID != NULL) || (SystemID != NULL)) &&
Daniel Veillard9403a042001-05-28 11:00:53 +0000192 (((ctxt->validate) || (ctxt->loadsubset != 0)) &&
Owen Taylor3473f882001-02-23 17:55:21 +0000193 (ctxt->wellFormed && ctxt->myDoc))) {
194 /*
195 * Try to fetch and parse the external subset.
196 */
197 xmlParserInputPtr oldinput;
198 int oldinputNr;
199 int oldinputMax;
200 xmlParserInputPtr *oldinputTab;
Owen Taylor3473f882001-02-23 17:55:21 +0000201 xmlParserInputPtr input = NULL;
202 xmlCharEncoding enc;
203 int oldcharset;
204
205 /*
206 * Ask the Entity resolver to load the damn thing
207 */
208 if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
209 input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID,
210 SystemID);
211 if (input == NULL) {
212 return;
213 }
214
215 xmlNewDtd(ctxt->myDoc, name, ExternalID, SystemID);
216
217 /*
218 * make sure we won't destroy the main document context
219 */
220 oldinput = ctxt->input;
221 oldinputNr = ctxt->inputNr;
222 oldinputMax = ctxt->inputMax;
223 oldinputTab = ctxt->inputTab;
Owen Taylor3473f882001-02-23 17:55:21 +0000224 oldcharset = ctxt->charset;
225
226 ctxt->inputTab = (xmlParserInputPtr *)
227 xmlMalloc(5 * sizeof(xmlParserInputPtr));
228 if (ctxt->inputTab == NULL) {
229 ctxt->errNo = XML_ERR_NO_MEMORY;
230 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
231 ctxt->sax->error(ctxt->userData,
232 "externalSubset: out of memory\n");
233 ctxt->errNo = XML_ERR_NO_MEMORY;
234 ctxt->input = oldinput;
235 ctxt->inputNr = oldinputNr;
236 ctxt->inputMax = oldinputMax;
237 ctxt->inputTab = oldinputTab;
238 ctxt->charset = oldcharset;
239 return;
240 }
241 ctxt->inputNr = 0;
242 ctxt->inputMax = 5;
243 ctxt->input = NULL;
244 xmlPushInput(ctxt, input);
245
246 /*
247 * On the fly encoding conversion if needed
248 */
249 enc = xmlDetectCharEncoding(ctxt->input->cur, 4);
250 xmlSwitchEncoding(ctxt, enc);
251
252 if (input->filename == NULL)
253 input->filename = (char *) xmlStrdup(SystemID);
254 input->line = 1;
255 input->col = 1;
256 input->base = ctxt->input->cur;
257 input->cur = ctxt->input->cur;
258 input->free = NULL;
259
260 /*
261 * let's parse that entity knowing it's an external subset.
262 */
263 xmlParseExternalSubset(ctxt, ExternalID, SystemID);
264
265 /*
266 * Free up the external entities
267 */
268
269 while (ctxt->inputNr > 1)
270 xmlPopInput(ctxt);
271 xmlFreeInputStream(ctxt->input);
272 xmlFree(ctxt->inputTab);
273
274 /*
275 * Restore the parsing context of the main entity
276 */
277 ctxt->input = oldinput;
278 ctxt->inputNr = oldinputNr;
279 ctxt->inputMax = oldinputMax;
280 ctxt->inputTab = oldinputTab;
281 ctxt->charset = oldcharset;
282 /* ctxt->wellFormed = oldwellFormed; */
283 }
284}
285
286/**
287 * resolveEntity:
288 * @ctx: the user data (XML parser context)
289 * @publicId: The public ID of the entity
290 * @systemId: The system ID of the entity
291 *
292 * The entity loader, to control the loading of external entities,
293 * the application can either:
294 * - override this resolveEntity() callback in the SAX block
295 * - or better use the xmlSetExternalEntityLoader() function to
296 * set up it's own entity resolution routine
297 *
298 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
299 */
300xmlParserInputPtr
301resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
302{
303 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
304 xmlParserInputPtr ret;
305 xmlChar *URI;
306 const char *base = NULL;
307
308 if (ctxt->input != NULL)
309 base = ctxt->input->filename;
310 if (base == NULL)
311 base = ctxt->directory;
312
313 URI = xmlBuildURI(systemId, (const xmlChar *) base);
314
315#ifdef DEBUG_SAX
316 xmlGenericError(xmlGenericErrorContext,
317 "SAX.resolveEntity(%s, %s)\n", publicId, systemId);
318#endif
319
320 ret = xmlLoadExternalEntity((const char *) URI,
321 (const char *) publicId, ctxt);
322 if (URI != NULL)
323 xmlFree(URI);
324 return(ret);
325}
326
327/**
328 * getEntity:
329 * @ctx: the user data (XML parser context)
330 * @name: The entity name
331 *
332 * Get an entity by name
333 *
334 * Returns the xmlEntityPtr if found.
335 */
336xmlEntityPtr
337getEntity(void *ctx, const xmlChar *name)
338{
339 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
340 xmlEntityPtr ret;
341
342#ifdef DEBUG_SAX
343 xmlGenericError(xmlGenericErrorContext,
344 "SAX.getEntity(%s)\n", name);
345#endif
346
347 ret = xmlGetDocEntity(ctxt->myDoc, name);
348 if ((ret != NULL) && (ctxt->validate) && (ret->children == NULL) &&
349 (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
350 /*
351 * for validation purposes we really need to fetch and
352 * parse the external entity
353 */
Owen Taylor3473f882001-02-23 17:55:21 +0000354 xmlNodePtr children;
355
Daniel Veillard5015b712001-08-17 09:37:52 +0000356 xmlParseCtxtExternalEntity(ctxt, ret->URI, ret->ExternalID, &children);
Owen Taylor3473f882001-02-23 17:55:21 +0000357 xmlAddChildList((xmlNodePtr) ret, children);
358 }
359 return(ret);
360}
361
362/**
363 * getParameterEntity:
364 * @ctx: the user data (XML parser context)
365 * @name: The entity name
366 *
367 * Get a parameter entity by name
368 *
369 * Returns the xmlEntityPtr if found.
370 */
371xmlEntityPtr
372getParameterEntity(void *ctx, const xmlChar *name)
373{
374 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
375 xmlEntityPtr ret;
376
377#ifdef DEBUG_SAX
378 xmlGenericError(xmlGenericErrorContext,
379 "SAX.getParameterEntity(%s)\n", name);
380#endif
381
382 ret = xmlGetParameterEntity(ctxt->myDoc, name);
383 return(ret);
384}
385
386
387/**
388 * entityDecl:
389 * @ctx: the user data (XML parser context)
390 * @name: the entity name
391 * @type: the entity type
392 * @publicId: The public ID of the entity
393 * @systemId: The system ID of the entity
394 * @content: the entity value (without processing).
395 *
396 * An entity definition has been parsed
397 */
398void
399entityDecl(void *ctx, const xmlChar *name, int type,
400 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
401{
402 xmlEntityPtr ent;
403 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
404
405#ifdef DEBUG_SAX
406 xmlGenericError(xmlGenericErrorContext,
407 "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
408 name, type, publicId, systemId, content);
409#endif
410 if (ctxt->inSubset == 1) {
411 ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId,
412 systemId, content);
413 if ((ent == NULL) && (ctxt->pedantic) &&
414 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
415 ctxt->sax->warning(ctxt,
416 "Entity(%s) already defined in the internal subset\n", name);
417 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
418 xmlChar *URI;
419 const char *base = NULL;
420
421 if (ctxt->input != NULL)
422 base = ctxt->input->filename;
423 if (base == NULL)
424 base = ctxt->directory;
425
426 URI = xmlBuildURI(systemId, (const xmlChar *) base);
427 ent->URI = URI;
428 }
429 } else if (ctxt->inSubset == 2) {
430 ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,
431 systemId, content);
432 if ((ent == NULL) && (ctxt->pedantic) &&
433 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
434 ctxt->sax->warning(ctxt,
435 "Entity(%s) already defined in the external subset\n", name);
436 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
437 xmlChar *URI;
438 const char *base = NULL;
439
440 if (ctxt->input != NULL)
441 base = ctxt->input->filename;
442 if (base == NULL)
443 base = ctxt->directory;
444
445 URI = xmlBuildURI(systemId, (const xmlChar *) base);
446 ent->URI = URI;
447 }
448 } else {
449 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
450 ctxt->sax->error(ctxt,
451 "SAX.entityDecl(%s) called while not in subset\n", name);
452 }
453}
454
455/**
456 * attributeDecl:
457 * @ctx: the user data (XML parser context)
458 * @elem: the name of the element
459 * @fullname: the attribute name
460 * @type: the attribute type
461 * @def: the type of default value
462 * @defaultValue: the attribute default value
463 * @tree: the tree of enumerated value set
464 *
465 * An attribute definition has been parsed
466 */
467void
468attributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
469 int type, int def, const xmlChar *defaultValue,
470 xmlEnumerationPtr tree)
471{
472 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
473 xmlAttributePtr attr;
474 xmlChar *name = NULL, *prefix = NULL;
475
476#ifdef DEBUG_SAX
477 xmlGenericError(xmlGenericErrorContext,
478 "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
479 elem, fullname, type, def, defaultValue);
480#endif
481 name = xmlSplitQName(ctxt, fullname, &prefix);
Daniel Veillardc7612992002-02-17 22:47:37 +0000482 ctxt->vctxt.valid = 1;
Owen Taylor3473f882001-02-23 17:55:21 +0000483 if (ctxt->inSubset == 1)
484 attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,
485 name, prefix, (xmlAttributeType) type,
486 (xmlAttributeDefault) def, defaultValue, tree);
487 else if (ctxt->inSubset == 2)
488 attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,
489 name, prefix, (xmlAttributeType) type,
490 (xmlAttributeDefault) def, defaultValue, tree);
491 else {
492 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
493 ctxt->sax->error(ctxt,
494 "SAX.attributeDecl(%s) called while not in subset\n", name);
495 return;
496 }
Daniel Veillardc7612992002-02-17 22:47:37 +0000497 if (ctxt->vctxt.valid == 0)
498 ctxt->valid = 0;
Owen Taylor3473f882001-02-23 17:55:21 +0000499 if (ctxt->validate && ctxt->wellFormed &&
500 ctxt->myDoc && ctxt->myDoc->intSubset)
501 ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
502 attr);
503 if (prefix != NULL)
504 xmlFree(prefix);
505 if (name != NULL)
506 xmlFree(name);
507}
508
509/**
510 * elementDecl:
511 * @ctx: the user data (XML parser context)
512 * @name: the element name
513 * @type: the element type
514 * @content: the element value tree
515 *
516 * An element definition has been parsed
517 */
518void
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000519elementDecl(void *ctx, const xmlChar * name, int type,
520 xmlElementContentPtr content)
Owen Taylor3473f882001-02-23 17:55:21 +0000521{
522 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
523 xmlElementPtr elem = NULL;
524
525#ifdef DEBUG_SAX
526 xmlGenericError(xmlGenericErrorContext,
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000527 "SAX.elementDecl(%s, %d, ...)\n", name, type);
Owen Taylor3473f882001-02-23 17:55:21 +0000528#endif
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000529
Owen Taylor3473f882001-02-23 17:55:21 +0000530 if (ctxt->inSubset == 1)
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000531 elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,
532 name, (xmlElementTypeVal) type, content);
Owen Taylor3473f882001-02-23 17:55:21 +0000533 else if (ctxt->inSubset == 2)
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000534 elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
535 name, (xmlElementTypeVal) type, content);
Owen Taylor3473f882001-02-23 17:55:21 +0000536 else {
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000537 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
538 ctxt->sax->error(ctxt,
539 "SAX.elementDecl(%s) called while not in subset\n",
540 name);
541 return;
Owen Taylor3473f882001-02-23 17:55:21 +0000542 }
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000543 if (elem == NULL)
544 ctxt->valid = 0;
Owen Taylor3473f882001-02-23 17:55:21 +0000545 if (ctxt->validate && ctxt->wellFormed &&
546 ctxt->myDoc && ctxt->myDoc->intSubset)
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000547 ctxt->valid &=
548 xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);
Owen Taylor3473f882001-02-23 17:55:21 +0000549}
550
551/**
552 * notationDecl:
553 * @ctx: the user data (XML parser context)
554 * @name: The name of the notation
555 * @publicId: The public ID of the entity
556 * @systemId: The system ID of the entity
557 *
558 * What to do when a notation declaration has been parsed.
559 */
560void
561notationDecl(void *ctx, const xmlChar *name,
562 const xmlChar *publicId, const xmlChar *systemId)
563{
564 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
565 xmlNotationPtr nota = NULL;
566
567#ifdef DEBUG_SAX
568 xmlGenericError(xmlGenericErrorContext,
569 "SAX.notationDecl(%s, %s, %s)\n", name, publicId, systemId);
570#endif
571
Daniel Veillard7aea52d2002-02-17 23:07:47 +0000572 if ((publicId == NULL) && (systemId == NULL)) {
573 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
574 ctxt->sax->error(ctxt,
575 "SAX.notationDecl(%s) externalID or PublicID missing\n", name);
576 ctxt->valid = 0;
577 ctxt->wellFormed = 0;
578 return;
579 } else if (ctxt->inSubset == 1)
Owen Taylor3473f882001-02-23 17:55:21 +0000580 nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
581 publicId, systemId);
582 else if (ctxt->inSubset == 2)
Daniel Veillard25239c12001-03-14 13:56:48 +0000583 nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
Owen Taylor3473f882001-02-23 17:55:21 +0000584 publicId, systemId);
585 else {
586 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
587 ctxt->sax->error(ctxt,
588 "SAX.notationDecl(%s) called while not in subset\n", name);
589 return;
590 }
591 if (nota == NULL) ctxt->valid = 0;
592 if (ctxt->validate && ctxt->wellFormed &&
593 ctxt->myDoc && ctxt->myDoc->intSubset)
594 ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
595 nota);
596}
597
598/**
599 * unparsedEntityDecl:
600 * @ctx: the user data (XML parser context)
601 * @name: The name of the entity
602 * @publicId: The public ID of the entity
603 * @systemId: The system ID of the entity
604 * @notationName: the name of the notation
605 *
606 * What to do when an unparsed entity declaration is parsed
607 */
608void
609unparsedEntityDecl(void *ctx, const xmlChar *name,
610 const xmlChar *publicId, const xmlChar *systemId,
611 const xmlChar *notationName)
612{
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000613 xmlEntityPtr ent;
Owen Taylor3473f882001-02-23 17:55:21 +0000614 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
615#ifdef DEBUG_SAX
616 xmlGenericError(xmlGenericErrorContext,
617 "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
618 name, publicId, systemId, notationName);
619#endif
620 if (ctxt->validate && ctxt->wellFormed &&
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000621 ctxt->myDoc && ctxt->myDoc->extSubset)
Owen Taylor3473f882001-02-23 17:55:21 +0000622 ctxt->valid &= xmlValidateNotationUse(&ctxt->vctxt, ctxt->myDoc,
623 notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000624 if (ctxt->inSubset == 1) {
625 ent = xmlAddDocEntity(ctxt->myDoc, name,
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000626 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
627 publicId, systemId, notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000628 if ((ent == NULL) && (ctxt->pedantic) &&
629 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
630 ctxt->sax->warning(ctxt,
631 "Entity(%s) already defined in the internal subset\n", name);
632 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
633 xmlChar *URI;
634 const char *base = NULL;
635
636 if (ctxt->input != NULL)
637 base = ctxt->input->filename;
638 if (base == NULL)
639 base = ctxt->directory;
640
641 URI = xmlBuildURI(systemId, (const xmlChar *) base);
642 ent->URI = URI;
643 }
644 } else if (ctxt->inSubset == 2) {
645 ent = xmlAddDtdEntity(ctxt->myDoc, name,
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000646 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
647 publicId, systemId, notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000648 if ((ent == NULL) && (ctxt->pedantic) &&
649 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
650 ctxt->sax->warning(ctxt,
651 "Entity(%s) already defined in the external subset\n", name);
652 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
653 xmlChar *URI;
654 const char *base = NULL;
655
656 if (ctxt->input != NULL)
657 base = ctxt->input->filename;
658 if (base == NULL)
659 base = ctxt->directory;
660
661 URI = xmlBuildURI(systemId, (const xmlChar *) base);
662 ent->URI = URI;
663 }
664 } else {
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000665 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
666 ctxt->sax->error(ctxt,
667 "SAX.unparsedEntityDecl(%s) called while not in subset\n", name);
668 }
Owen Taylor3473f882001-02-23 17:55:21 +0000669}
670
671/**
672 * setDocumentLocator:
673 * @ctx: the user data (XML parser context)
674 * @loc: A SAX Locator
675 *
676 * Receive the document locator at startup, actually xmlDefaultSAXLocator
677 * Everything is available on the context, so this is useless in our case.
678 */
679void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000680setDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +0000681{
682 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
683#ifdef DEBUG_SAX
684 xmlGenericError(xmlGenericErrorContext,
685 "SAX.setDocumentLocator()\n");
686#endif
687}
688
689/**
690 * startDocument:
691 * @ctx: the user data (XML parser context)
692 *
693 * called when the document start being processed.
694 */
695void
696startDocument(void *ctx)
697{
698 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
699 xmlDocPtr doc;
700
701#ifdef DEBUG_SAX
702 xmlGenericError(xmlGenericErrorContext,
703 "SAX.startDocument()\n");
704#endif
705 if (ctxt->html) {
706 if (ctxt->myDoc == NULL)
707#ifdef LIBXML_HTML_ENABLED
708 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
709#else
710 xmlGenericError(xmlGenericErrorContext,
711 "libxml2 built without HTML support\n");
712#endif
713 } else {
714 doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
715 if (doc != NULL) {
716 if (ctxt->encoding != NULL)
717 doc->encoding = xmlStrdup(ctxt->encoding);
718 else
719 doc->encoding = NULL;
720 doc->standalone = ctxt->standalone;
721 }
722 }
723 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
724 (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000725 ctxt->myDoc->URL = xmlStrdup((const xmlChar *) ctxt->input->filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000726 }
727}
728
729/**
730 * endDocument:
731 * @ctx: the user data (XML parser context)
732 *
733 * called when the document end has been detected.
734 */
735void
736endDocument(void *ctx)
737{
738 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
739#ifdef DEBUG_SAX
740 xmlGenericError(xmlGenericErrorContext,
741 "SAX.endDocument()\n");
742#endif
743 if (ctxt->validate && ctxt->wellFormed &&
744 ctxt->myDoc && ctxt->myDoc->intSubset)
745 ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
746
747 /*
748 * Grab the encoding if it was added on-the-fly
749 */
750 if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) &&
751 (ctxt->myDoc->encoding == NULL)) {
752 ctxt->myDoc->encoding = ctxt->encoding;
753 ctxt->encoding = NULL;
754 }
755 if ((ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) &&
756 (ctxt->myDoc->encoding == NULL)) {
757 ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding);
758 }
759 if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) &&
760 (ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) {
761 ctxt->myDoc->charset = ctxt->charset;
762 }
763}
764
765/**
766 * attribute:
767 * @ctx: the user data (XML parser context)
768 * @fullname: The attribute name, including namespace prefix
769 * @value: The attribute value
770 *
771 * Handle an attribute that has been read by the parser.
772 * The default handling is to convert the attribute into an
773 * DOM subtree and past it in a new xmlAttr element added to
774 * the element.
775 */
776void
777attribute(void *ctx, const xmlChar *fullname, const xmlChar *value)
778{
779 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
780 xmlAttrPtr ret;
781 xmlChar *name;
782 xmlChar *ns;
783 xmlChar *nval;
784 xmlNsPtr namespace;
785
786/****************
787#ifdef DEBUG_SAX
788 xmlGenericError(xmlGenericErrorContext,
789 "SAX.attribute(%s, %s)\n", fullname, value);
790#endif
791 ****************/
792 /*
793 * Split the full name into a namespace prefix and the tag name
794 */
795 name = xmlSplitQName(ctxt, fullname, &ns);
796
797 /*
798 * Do the last stage of the attribute normalization
799 * Needed for HTML too:
800 * http://www.w3.org/TR/html4/types.html#h-6.2
801 */
802 nval = xmlValidNormalizeAttributeValue(ctxt->myDoc, ctxt->node,
803 fullname, value);
804 if (nval != NULL)
805 value = nval;
806
807 /*
808 * Check whether it's a namespace definition
809 */
810 if ((!ctxt->html) && (ns == NULL) &&
811 (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
812 (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
813 if (value[0] != 0) {
814 xmlURIPtr uri;
815
816 uri = xmlParseURI((const char *)value);
817 if (uri == NULL) {
818 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
819 ctxt->sax->warning(ctxt->userData,
820 "nmlns: %s not a valid URI\n", value);
821 } else {
822 if (uri->scheme == NULL) {
823 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
824 ctxt->sax->warning(ctxt->userData,
825 "nmlns: URI %s is not absolute\n", value);
826 }
827 xmlFreeURI(uri);
828 }
829 }
830
831 /* a default namespace definition */
832 xmlNewNs(ctxt->node, value, NULL);
833 if (name != NULL)
834 xmlFree(name);
835 if (nval != NULL)
836 xmlFree(nval);
837 return;
838 }
839 if ((!ctxt->html) &&
840 (ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
841 (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
842 /*
843 * Validate also for namespace decls, they are attributes from
844 * an XML-1.0 perspective
845 TODO ... doesn't map well with current API
846 if (ctxt->validate && ctxt->wellFormed &&
847 ctxt->myDoc && ctxt->myDoc->intSubset)
848 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
849 ctxt->node, ret, value);
850 */
851 /* a standard namespace definition */
852 xmlNewNs(ctxt->node, value, name);
853 xmlFree(ns);
854 if (name != NULL)
855 xmlFree(name);
856 if (nval != NULL)
857 xmlFree(nval);
858 return;
859 }
860
861 if (ns != NULL)
862 namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
863 else {
864 namespace = NULL;
865 }
866
867 /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */
868 ret = xmlNewNsProp(ctxt->node, namespace, name, NULL);
869
870 if (ret != NULL) {
871 if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
872 xmlNodePtr tmp;
873
874 ret->children = xmlStringGetNodeList(ctxt->myDoc, value);
875 tmp = ret->children;
876 while (tmp != NULL) {
877 tmp->parent = (xmlNodePtr) ret;
878 if (tmp->next == NULL)
879 ret->last = tmp;
880 tmp = tmp->next;
881 }
882 } else if (value != NULL) {
883 ret->children = xmlNewDocText(ctxt->myDoc, value);
884 ret->last = ret->children;
885 if (ret->children != NULL)
886 ret->children->parent = (xmlNodePtr) ret;
887 }
888 }
889
890 if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
891 ctxt->myDoc && ctxt->myDoc->intSubset) {
892
893 /*
894 * If we don't substitute entities, the validation should be
895 * done on a value with replaced entities anyway.
896 */
897 if (!ctxt->replaceEntities) {
898 xmlChar *val;
899
900 ctxt->depth++;
901 val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
902 0,0,0);
903 ctxt->depth--;
Daniel Veillardc7612992002-02-17 22:47:37 +0000904
Owen Taylor3473f882001-02-23 17:55:21 +0000905 if (val == NULL)
906 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
907 ctxt->myDoc, ctxt->node, ret, value);
908 else {
Daniel Veillardc7612992002-02-17 22:47:37 +0000909 xmlChar *nvalnorm;
910
911 /*
912 * Do the last stage of the attribute normalization
913 * It need to be done twice ... it's an extra burden related
914 * to the ability to keep references in attributes
915 */
916 nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc,
917 ctxt->node, fullname, val);
918 if (nvalnorm != NULL) {
919 xmlFree(val);
920 val = nvalnorm;
921 }
922
Owen Taylor3473f882001-02-23 17:55:21 +0000923 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
924 ctxt->myDoc, ctxt->node, ret, val);
925 xmlFree(val);
926 }
927 } else {
928 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
929 ctxt->node, ret, value);
930 }
Daniel Veillard62f313b2001-07-04 19:49:14 +0000931 } else if (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
932 ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0))) {
Owen Taylor3473f882001-02-23 17:55:21 +0000933 /*
934 * when validating, the ID registration is done at the attribute
935 * validation level. Otherwise we have to do specific handling here.
936 */
937 if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
938 xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
939 else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
940 xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
941 }
942
943 if (nval != NULL)
944 xmlFree(nval);
945 if (name != NULL)
946 xmlFree(name);
947 if (ns != NULL)
948 xmlFree(ns);
949}
950
951/**
952 * startElement:
953 * @ctx: the user data (XML parser context)
954 * @fullname: The element name, including namespace prefix
955 * @atts: An array of name/value attributes pairs, NULL terminated
956 *
957 * called when an opening tag has been processed.
958 */
959void
960startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
961{
962 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
963 xmlNodePtr ret;
964 xmlNodePtr parent = ctxt->node;
965 xmlNsPtr ns;
966 xmlChar *name;
967 xmlChar *prefix;
968 const xmlChar *att;
969 const xmlChar *value;
970 int i;
971
972#ifdef DEBUG_SAX
973 xmlGenericError(xmlGenericErrorContext,
974 "SAX.startElement(%s)\n", fullname);
975#endif
976
977 /*
978 * First check on validity:
979 */
980 if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
981 ((ctxt->myDoc->intSubset == NULL) ||
982 ((ctxt->myDoc->intSubset->notations == NULL) &&
983 (ctxt->myDoc->intSubset->elements == NULL) &&
984 (ctxt->myDoc->intSubset->attributes == NULL) &&
985 (ctxt->myDoc->intSubset->entities == NULL)))) {
986 if (ctxt->vctxt.error != NULL) {
987 ctxt->vctxt.error(ctxt->vctxt.userData,
988 "Validation failed: no DTD found !\n");
989 }
990 ctxt->validate = 0;
Daniel Veillard7a51d6d2001-09-10 14:40:43 +0000991 ctxt->valid = 0;
992 ctxt->errNo = XML_ERR_NO_DTD;
Owen Taylor3473f882001-02-23 17:55:21 +0000993 }
994
995
996 /*
997 * Split the full name into a namespace prefix and the tag name
998 */
999 name = xmlSplitQName(ctxt, fullname, &prefix);
1000
1001
1002 /*
1003 * Note : the namespace resolution is deferred until the end of the
1004 * attributes parsing, since local namespace can be defined as
1005 * an attribute at this level.
1006 */
1007 ret = xmlNewDocNode(ctxt->myDoc, NULL, name, NULL);
1008 if (ret == NULL) return;
1009 if (ctxt->myDoc->children == NULL) {
1010#ifdef DEBUG_SAX_TREE
1011 xmlGenericError(xmlGenericErrorContext, "Setting %s as root\n", name);
1012#endif
1013 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1014 } else if (parent == NULL) {
1015 parent = ctxt->myDoc->children;
1016 }
1017 ctxt->nodemem = -1;
Daniel Veillardd9bad132001-07-23 19:39:43 +00001018 if (ctxt->linenumbers) {
1019 if (ctxt->input != NULL)
1020 ret->content = (void *) (long) ctxt->input->line;
1021 }
Owen Taylor3473f882001-02-23 17:55:21 +00001022
1023 /*
1024 * We are parsing a new node.
1025 */
1026#ifdef DEBUG_SAX_TREE
1027 xmlGenericError(xmlGenericErrorContext, "pushing(%s)\n", name);
1028#endif
1029 nodePush(ctxt, ret);
1030
1031 /*
1032 * Link the child element
1033 */
1034 if (parent != NULL) {
1035 if (parent->type == XML_ELEMENT_NODE) {
1036#ifdef DEBUG_SAX_TREE
1037 xmlGenericError(xmlGenericErrorContext,
1038 "adding child %s to %s\n", name, parent->name);
1039#endif
1040 xmlAddChild(parent, ret);
1041 } else {
1042#ifdef DEBUG_SAX_TREE
1043 xmlGenericError(xmlGenericErrorContext,
1044 "adding sibling %s to ", name);
1045 xmlDebugDumpOneNode(stderr, parent, 0);
1046#endif
1047 xmlAddSibling(parent, ret);
1048 }
1049 }
1050
1051 /*
Daniel Veillard48da9102001-08-07 01:10:10 +00001052 * Insert all the defaulted attributes from the DTD especially namespaces
1053 */
1054 if ((!ctxt->html) &&
1055 ((ctxt->myDoc->intSubset != NULL) ||
1056 (ctxt->myDoc->extSubset != NULL))) {
1057 xmlElementPtr elemDecl = NULL;
1058
1059 if (prefix != NULL) {
1060 if (ctxt->myDoc->intSubset != NULL)
1061 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset,
1062 name, prefix);
1063 if ((elemDecl == NULL) && (ctxt->myDoc->extSubset != NULL))
1064 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
1065 name, prefix);
1066 } else {
1067 if (ctxt->myDoc->intSubset != NULL)
1068 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset,
1069 name, prefix);
1070 if ((elemDecl == NULL) && (ctxt->myDoc->extSubset != NULL))
1071 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
1072 name, prefix);
1073 }
1074 if (elemDecl != NULL) {
1075 xmlAttributePtr attr = elemDecl->attributes;
1076 while (attr != NULL) {
1077 if (attr->defaultValue != NULL) {
1078 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001079 * the element should be instantiated in the tree if:
Daniel Veillard48da9102001-08-07 01:10:10 +00001080 * - this is a namespace prefix
1081 * - the user required for completion in the tree
1082 * like XSLT
1083 */
1084 if (((attr->prefix != NULL) &&
1085 (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
1086 ((attr->prefix == NULL) &&
1087 (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
1088 (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
Daniel Veillard963d2ae2002-01-20 22:08:18 +00001089 xmlChar *fulln;
Daniel Veillard48da9102001-08-07 01:10:10 +00001090
1091 if (attr->prefix != NULL) {
Daniel Veillard963d2ae2002-01-20 22:08:18 +00001092 fulln = xmlStrdup(attr->prefix);
1093 fulln = xmlStrcat(fulln, BAD_CAST ":");
1094 fulln = xmlStrcat(fulln, attr->name);
1095 } else {
1096 fulln = xmlStrdup(attr->name);
Daniel Veillard48da9102001-08-07 01:10:10 +00001097 }
1098
1099 /*
1100 * Check that the attribute is not declared in the
1101 * serialization
1102 */
1103 att = NULL;
1104 if (atts != NULL) {
1105 i = 0;
1106 att = atts[i];
1107 while (att != NULL) {
1108 if (xmlStrEqual(att, fulln))
1109 break;
1110 i += 2;
1111 att = atts[i];
1112 }
1113 }
1114 if (att == NULL)
1115 attribute(ctxt, fulln, attr->defaultValue);
Daniel Veillard963d2ae2002-01-20 22:08:18 +00001116 xmlFree(fulln);
Daniel Veillard48da9102001-08-07 01:10:10 +00001117 }
1118 }
1119 attr = attr->nexth;
1120 }
1121 }
1122 }
1123
1124 /*
Owen Taylor3473f882001-02-23 17:55:21 +00001125 * process all the attributes whose name start with "xml"
1126 */
1127 if (atts != NULL) {
1128 i = 0;
1129 att = atts[i++];
1130 value = atts[i++];
1131 if (!ctxt->html) {
1132 while ((att != NULL) && (value != NULL)) {
1133 if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l'))
1134 attribute(ctxt, att, value);
1135
1136 att = atts[i++];
1137 value = atts[i++];
1138 }
1139 }
1140 }
1141
1142 /*
1143 * Search the namespace, note that since the attributes have been
1144 * processed, the local namespaces are available.
1145 */
1146 ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
1147 if ((ns == NULL) && (parent != NULL))
1148 ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
1149 if ((prefix != NULL) && (ns == NULL)) {
1150 ns = xmlNewNs(ret, NULL, prefix);
1151 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
1152 ctxt->sax->warning(ctxt->userData,
1153 "Namespace prefix %s is not defined\n", prefix);
1154 }
Daniel Veillard143b04f2001-09-10 18:14:14 +00001155
1156 /*
1157 * set the namespace node, making sure that if the default namspace
1158 * is unbound on a parent we simply kee it NULL
1159 */
Daniel Veillard651f9472001-10-04 14:51:06 +00001160 if ((ns != NULL) && (ns->href != NULL) && (ns->href[0] != 0))
Daniel Veillard143b04f2001-09-10 18:14:14 +00001161 xmlSetNs(ret, ns);
Owen Taylor3473f882001-02-23 17:55:21 +00001162
1163 /*
1164 * process all the other attributes
1165 */
1166 if (atts != NULL) {
1167 i = 0;
1168 att = atts[i++];
1169 value = atts[i++];
1170 if (ctxt->html) {
1171 while (att != NULL) {
1172 attribute(ctxt, att, value);
1173 att = atts[i++];
1174 value = atts[i++];
1175 }
1176 } else {
1177 while ((att != NULL) && (value != NULL)) {
1178 if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l'))
1179 attribute(ctxt, att, value);
1180
1181 /*
1182 * Next ones
1183 */
1184 att = atts[i++];
1185 value = atts[i++];
1186 }
1187 }
1188 }
1189
1190 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001191 * If it's the Document root, finish the DTD validation and
Owen Taylor3473f882001-02-23 17:55:21 +00001192 * check the document root element for validity
1193 */
1194 if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) {
1195 ctxt->valid &= xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
1196 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
1197 ctxt->vctxt.finishDtd = 1;
1198 }
1199
1200 if (prefix != NULL)
1201 xmlFree(prefix);
1202 if (name != NULL)
1203 xmlFree(name);
1204
1205}
1206
1207/**
1208 * endElement:
1209 * @ctx: the user data (XML parser context)
1210 * @name: The element name
1211 *
1212 * called when the end of an element has been detected.
1213 */
1214void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +00001215endElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +00001216{
1217 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1218 xmlParserNodeInfo node_info;
1219 xmlNodePtr cur = ctxt->node;
1220
1221#ifdef DEBUG_SAX
1222 if (name == NULL)
1223 xmlGenericError(xmlGenericErrorContext, "SAX.endElement(NULL)\n");
1224 else
1225 xmlGenericError(xmlGenericErrorContext, "SAX.endElement(%s)\n", name);
1226#endif
1227
1228 /* Capture end position and add node */
1229 if (cur != NULL && ctxt->record_info) {
1230 node_info.end_pos = ctxt->input->cur - ctxt->input->base;
1231 node_info.end_line = ctxt->input->line;
1232 node_info.node = cur;
1233 xmlParserAddNodeInfo(ctxt, &node_info);
1234 }
1235 ctxt->nodemem = -1;
1236
1237 if (ctxt->validate && ctxt->wellFormed &&
1238 ctxt->myDoc && ctxt->myDoc->intSubset)
1239 ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
1240 cur);
1241
1242
1243 /*
1244 * end of parsing of this node.
1245 */
1246#ifdef DEBUG_SAX_TREE
1247 xmlGenericError(xmlGenericErrorContext, "popping(%s)\n", cur->name);
1248#endif
1249 nodePop(ctxt);
1250}
1251
1252/**
1253 * reference:
1254 * @ctx: the user data (XML parser context)
1255 * @name: The entity name
1256 *
1257 * called when an entity reference is detected.
1258 */
1259void
1260reference(void *ctx, const xmlChar *name)
1261{
1262 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1263 xmlNodePtr ret;
1264
1265#ifdef DEBUG_SAX
1266 xmlGenericError(xmlGenericErrorContext,
1267 "SAX.reference(%s)\n", name);
1268#endif
1269 if (name[0] == '#')
1270 ret = xmlNewCharRef(ctxt->myDoc, name);
1271 else
1272 ret = xmlNewReference(ctxt->myDoc, name);
1273#ifdef DEBUG_SAX_TREE
1274 xmlGenericError(xmlGenericErrorContext,
1275 "add reference %s to %s \n", name, ctxt->node->name);
1276#endif
1277 xmlAddChild(ctxt->node, ret);
1278}
1279
1280/**
1281 * characters:
1282 * @ctx: the user data (XML parser context)
1283 * @ch: a xmlChar string
1284 * @len: the number of xmlChar
1285 *
1286 * receiving some chars from the parser.
Owen Taylor3473f882001-02-23 17:55:21 +00001287 */
1288void
1289characters(void *ctx, const xmlChar *ch, int len)
1290{
1291 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1292 xmlNodePtr lastChild;
1293
1294#ifdef DEBUG_SAX
1295 xmlGenericError(xmlGenericErrorContext,
1296 "SAX.characters(%.30s, %d)\n", ch, len);
1297#endif
1298 /*
1299 * Handle the data if any. If there is no child
1300 * add it as content, otherwise if the last child is text,
1301 * concatenate it, else create a new node of type text.
1302 */
1303
1304 if (ctxt->node == NULL) {
1305#ifdef DEBUG_SAX_TREE
1306 xmlGenericError(xmlGenericErrorContext,
1307 "add chars: ctxt->node == NULL !\n");
1308#endif
1309 return;
1310 }
1311 lastChild = xmlGetLastChild(ctxt->node);
1312#ifdef DEBUG_SAX_TREE
1313 xmlGenericError(xmlGenericErrorContext,
1314 "add chars to %s \n", ctxt->node->name);
1315#endif
1316
1317 /*
1318 * Here we needed an accelerator mechanism in case of very large
1319 * elements. Use an attribute in the structure !!!
1320 */
1321 if (lastChild == NULL) {
1322 /* first node, first time */
1323 xmlNodeAddContentLen(ctxt->node, ch, len);
1324#ifndef XML_USE_BUFFER_CONTENT
1325 if (ctxt->node->children != NULL) {
1326 ctxt->nodelen = len;
1327 ctxt->nodemem = len + 1;
1328 }
1329#endif
1330 } else {
Daniel Veillardf300b7e2001-08-13 10:43:15 +00001331 int coalesceText = (lastChild != NULL) &&
1332 (lastChild->type == XML_TEXT_NODE) &&
1333 (lastChild->name == xmlStringText);
1334 if ((coalesceText) && (ctxt->nodemem != 0)) {
Owen Taylor3473f882001-02-23 17:55:21 +00001335#ifndef XML_USE_BUFFER_CONTENT
1336 /*
1337 * The whole point of maintaining nodelen and nodemem,
Daniel Veillard60087f32001-10-10 09:45:09 +00001338 * xmlTextConcat is too costly, i.e. compute length,
Owen Taylor3473f882001-02-23 17:55:21 +00001339 * reallocate a new buffer, move data, append ch. Here
1340 * We try to minimaze realloc() uses and avoid copying
Daniel Veillard60087f32001-10-10 09:45:09 +00001341 * and recomputing length over and over.
Owen Taylor3473f882001-02-23 17:55:21 +00001342 */
1343 if (ctxt->nodelen + len >= ctxt->nodemem) {
1344 xmlChar *newbuf;
1345 int size;
1346
1347 size = ctxt->nodemem + len;
1348 size *= 2;
1349 newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
1350 if (newbuf == NULL) {
1351 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1352 ctxt->sax->error(ctxt->userData,
1353 "SAX.characters(): out of memory\n");
1354 return;
1355 }
1356 ctxt->nodemem = size;
1357 lastChild->content = newbuf;
1358 }
1359 memcpy(&lastChild->content[ctxt->nodelen], ch, len);
1360 ctxt->nodelen += len;
1361 lastChild->content[ctxt->nodelen] = 0;
1362#else
1363 xmlTextConcat(lastChild, ch, len);
1364#endif
Daniel Veillardf300b7e2001-08-13 10:43:15 +00001365 } else if (coalesceText) {
Daniel Veillard80f32572001-03-07 19:45:40 +00001366 xmlTextConcat(lastChild, ch, len);
1367 if (ctxt->node->children != NULL) {
1368 ctxt->nodelen = xmlStrlen(lastChild->content);
1369 ctxt->nodemem = ctxt->nodelen + 1;
1370 }
Owen Taylor3473f882001-02-23 17:55:21 +00001371 } else {
1372 /* Mixed content, first time */
1373 lastChild = xmlNewTextLen(ch, len);
1374 xmlAddChild(ctxt->node, lastChild);
1375#ifndef XML_USE_BUFFER_CONTENT
1376 if (ctxt->node->children != NULL) {
1377 ctxt->nodelen = len;
1378 ctxt->nodemem = len + 1;
1379 }
1380#endif
1381 }
1382 }
1383}
1384
1385/**
1386 * ignorableWhitespace:
1387 * @ctx: the user data (XML parser context)
1388 * @ch: a xmlChar string
1389 * @len: the number of xmlChar
1390 *
1391 * receiving some ignorable whitespaces from the parser.
Daniel Veillard05c13a22001-09-09 08:38:09 +00001392 * UNUSED: by default the DOM building will use characters
Owen Taylor3473f882001-02-23 17:55:21 +00001393 */
1394void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +00001395ignorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +00001396{
1397 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
1398#ifdef DEBUG_SAX
1399 xmlGenericError(xmlGenericErrorContext,
1400 "SAX.ignorableWhitespace(%.30s, %d)\n", ch, len);
1401#endif
1402}
1403
1404/**
1405 * processingInstruction:
1406 * @ctx: the user data (XML parser context)
1407 * @target: the target name
1408 * @data: the PI data's
1409 *
1410 * A processing instruction has been parsed.
1411 */
1412void
1413processingInstruction(void *ctx, const xmlChar *target,
1414 const xmlChar *data)
1415{
1416 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1417 xmlNodePtr ret;
1418 xmlNodePtr parent = ctxt->node;
1419
1420#ifdef DEBUG_SAX
1421 xmlGenericError(xmlGenericErrorContext,
1422 "SAX.processingInstruction(%s, %s)\n", target, data);
1423#endif
1424
1425 ret = xmlNewPI(target, data);
1426 if (ret == NULL) return;
1427 parent = ctxt->node;
1428
1429 if (ctxt->inSubset == 1) {
1430 xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
1431 return;
1432 } else if (ctxt->inSubset == 2) {
1433 xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
1434 return;
1435 }
1436 if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
1437#ifdef DEBUG_SAX_TREE
1438 xmlGenericError(xmlGenericErrorContext,
1439 "Setting PI %s as root\n", target);
1440#endif
1441 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1442 return;
1443 }
1444 if (parent->type == XML_ELEMENT_NODE) {
1445#ifdef DEBUG_SAX_TREE
1446 xmlGenericError(xmlGenericErrorContext,
1447 "adding PI %s child to %s\n", target, parent->name);
1448#endif
1449 xmlAddChild(parent, ret);
1450 } else {
1451#ifdef DEBUG_SAX_TREE
1452 xmlGenericError(xmlGenericErrorContext,
1453 "adding PI %s sibling to ", target);
1454 xmlDebugDumpOneNode(stderr, parent, 0);
1455#endif
1456 xmlAddSibling(parent, ret);
1457 }
1458}
1459
1460/**
1461 * globalNamespace:
1462 * @ctx: the user data (XML parser context)
1463 * @href: the namespace associated URN
1464 * @prefix: the namespace prefix
1465 *
1466 * An old global namespace has been parsed.
1467 */
1468void
1469globalNamespace(void *ctx, const xmlChar *href, const xmlChar *prefix)
1470{
1471 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1472#ifdef DEBUG_SAX
1473 xmlGenericError(xmlGenericErrorContext,
1474 "SAX.globalNamespace(%s, %s)\n", href, prefix);
1475#endif
1476 xmlNewGlobalNs(ctxt->myDoc, href, prefix);
1477}
1478
1479/**
1480 * setNamespace:
1481 * @ctx: the user data (XML parser context)
1482 * @name: the namespace prefix
1483 *
1484 * Set the current element namespace.
1485 */
1486
1487void
1488setNamespace(void *ctx, const xmlChar *name)
1489{
1490 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1491 xmlNsPtr ns;
1492 xmlNodePtr parent;
1493
1494#ifdef DEBUG_SAX
1495 xmlGenericError(xmlGenericErrorContext, "SAX.setNamespace(%s)\n", name);
1496#endif
1497 ns = xmlSearchNs(ctxt->myDoc, ctxt->node, name);
1498 if (ns == NULL) { /* ctxt->node may not have a parent yet ! */
1499 if (ctxt->nodeNr >= 2) {
1500 parent = ctxt->nodeTab[ctxt->nodeNr - 2];
1501 if (parent != NULL)
1502 ns = xmlSearchNs(ctxt->myDoc, parent, name);
1503 }
1504 }
1505 xmlSetNs(ctxt->node, ns);
1506}
1507
1508/**
1509 * getNamespace:
1510 * @ctx: the user data (XML parser context)
1511 *
1512 * Get the current element namespace.
1513 *
1514 * Returns the xmlNsPtr or NULL if none
1515 */
1516
1517xmlNsPtr
1518getNamespace(void *ctx)
1519{
1520 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1521 xmlNsPtr ret;
1522
1523#ifdef DEBUG_SAX
1524 xmlGenericError(xmlGenericErrorContext, "SAX.getNamespace()\n");
1525#endif
1526 ret = ctxt->node->ns;
1527 return(ret);
1528}
1529
1530/**
1531 * checkNamespace:
1532 * @ctx: the user data (XML parser context)
1533 * @namespace: the namespace to check against
1534 *
1535 * Check that the current element namespace is the same as the
1536 * one read upon parsing.
1537 *
1538 * Returns 1 if true 0 otherwise
1539 */
1540
1541int
1542checkNamespace(void *ctx, xmlChar *namespace)
1543{
1544 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1545 xmlNodePtr cur = ctxt->node;
1546
1547#ifdef DEBUG_SAX
1548 xmlGenericError(xmlGenericErrorContext,
1549 "SAX.checkNamespace(%s)\n", namespace);
1550#endif
1551
1552 /*
1553 * Check that the Name in the ETag is the same as in the STag.
1554 */
1555 if (namespace == NULL) {
1556 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
1557 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1558 ctxt->sax->error(ctxt,
1559 "End tags for %s don't hold the namespace %s\n",
1560 cur->name, cur->ns->prefix);
1561 ctxt->wellFormed = 0;
1562 }
1563 } else {
1564 if ((cur->ns == NULL) || (cur->ns->prefix == NULL)) {
1565 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1566 ctxt->sax->error(ctxt,
1567 "End tags %s holds a prefix %s not used by the open tag\n",
1568 cur->name, namespace);
1569 ctxt->wellFormed = 0;
1570 } else if (!xmlStrEqual(namespace, cur->ns->prefix)) {
1571 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1572 ctxt->sax->error(ctxt,
1573 "Start and End tags for %s don't use the same namespaces: %s and %s\n",
1574 cur->name, cur->ns->prefix, namespace);
1575 ctxt->wellFormed = 0;
1576 } else
1577 return(1);
1578 }
1579 return(0);
1580}
1581
1582/**
1583 * namespaceDecl:
1584 * @ctx: the user data (XML parser context)
1585 * @href: the namespace associated URN
1586 * @prefix: the namespace prefix
1587 *
1588 * A namespace has been parsed.
1589 */
1590void
1591namespaceDecl(void *ctx, const xmlChar *href, const xmlChar *prefix)
1592{
1593 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1594#ifdef DEBUG_SAX
1595 if (prefix == NULL)
1596 xmlGenericError(xmlGenericErrorContext,
1597 "SAX.namespaceDecl(%s, NULL)\n", href);
1598 else
1599 xmlGenericError(xmlGenericErrorContext,
1600 "SAX.namespaceDecl(%s, %s)\n", href, prefix);
1601#endif
1602 xmlNewNs(ctxt->node, href, prefix);
1603}
1604
1605/**
1606 * comment:
1607 * @ctx: the user data (XML parser context)
1608 * @value: the comment content
1609 *
1610 * A comment has been parsed.
1611 */
1612void
1613comment(void *ctx, const xmlChar *value)
1614{
1615 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1616 xmlNodePtr ret;
1617 xmlNodePtr parent = ctxt->node;
1618
1619#ifdef DEBUG_SAX
1620 xmlGenericError(xmlGenericErrorContext, "SAX.comment(%s)\n", value);
1621#endif
1622 ret = xmlNewDocComment(ctxt->myDoc, value);
1623 if (ret == NULL) return;
1624
1625 if (ctxt->inSubset == 1) {
1626 xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
1627 return;
1628 } else if (ctxt->inSubset == 2) {
1629 xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
1630 return;
1631 }
1632 if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
1633#ifdef DEBUG_SAX_TREE
1634 xmlGenericError(xmlGenericErrorContext,
1635 "Setting comment as root\n");
1636#endif
1637 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1638 return;
1639 }
1640 if (parent->type == XML_ELEMENT_NODE) {
1641#ifdef DEBUG_SAX_TREE
1642 xmlGenericError(xmlGenericErrorContext,
1643 "adding comment child to %s\n", parent->name);
1644#endif
1645 xmlAddChild(parent, ret);
1646 } else {
1647#ifdef DEBUG_SAX_TREE
1648 xmlGenericError(xmlGenericErrorContext,
1649 "adding comment sibling to ");
1650 xmlDebugDumpOneNode(stderr, parent, 0);
1651#endif
1652 xmlAddSibling(parent, ret);
1653 }
1654}
1655
1656/**
1657 * cdataBlock:
1658 * @ctx: the user data (XML parser context)
1659 * @value: The pcdata content
1660 * @len: the block length
1661 *
1662 * called when a pcdata block has been parsed
1663 */
1664void
1665cdataBlock(void *ctx, const xmlChar *value, int len)
1666{
1667 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1668 xmlNodePtr ret, lastChild;
1669
1670#ifdef DEBUG_SAX
1671 xmlGenericError(xmlGenericErrorContext,
1672 "SAX.pcdata(%.10s, %d)\n", value, len);
1673#endif
1674 lastChild = xmlGetLastChild(ctxt->node);
1675#ifdef DEBUG_SAX_TREE
1676 xmlGenericError(xmlGenericErrorContext,
1677 "add chars to %s \n", ctxt->node->name);
1678#endif
1679 if ((lastChild != NULL) &&
1680 (lastChild->type == XML_CDATA_SECTION_NODE)) {
1681 xmlTextConcat(lastChild, value, len);
1682 } else {
1683 ret = xmlNewCDataBlock(ctxt->myDoc, value, len);
1684 xmlAddChild(ctxt->node, ret);
1685 }
1686}
1687
Daniel Veillardd0463562001-10-13 09:15:48 +00001688/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001689 * initxmlDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001690 * @hdlr: the SAX handler
1691 * @warning: flag if non-zero sets the handler warning procedure
Daniel Veillardd0463562001-10-13 09:15:48 +00001692 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001693 * Initialize the default XML SAX handler
Owen Taylor3473f882001-02-23 17:55:21 +00001694 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001695void
1696initxmlDefaultSAXHandler(xmlSAXHandler *hdlr, int warning)
1697{
1698 if(hdlr->initialized == 1)
1699 return;
1700
1701 hdlr->internalSubset = internalSubset;
1702 hdlr->externalSubset = externalSubset;
1703 hdlr->isStandalone = isStandalone;
1704 hdlr->hasInternalSubset = hasInternalSubset;
1705 hdlr->hasExternalSubset = hasExternalSubset;
1706 hdlr->resolveEntity = resolveEntity;
1707 hdlr->getEntity = getEntity;
1708 hdlr->getParameterEntity = getParameterEntity;
1709 hdlr->entityDecl = entityDecl;
1710 hdlr->attributeDecl = attributeDecl;
1711 hdlr->elementDecl = elementDecl;
1712 hdlr->notationDecl = notationDecl;
1713 hdlr->unparsedEntityDecl = unparsedEntityDecl;
1714 hdlr->setDocumentLocator = setDocumentLocator;
1715 hdlr->startDocument = startDocument;
1716 hdlr->endDocument = endDocument;
1717 hdlr->startElement = startElement;
1718 hdlr->endElement = endElement;
1719 hdlr->reference = reference;
1720 hdlr->characters = characters;
1721 hdlr->cdataBlock = cdataBlock;
1722 hdlr->ignorableWhitespace = characters;
1723 hdlr->processingInstruction = processingInstruction;
1724 hdlr->comment = comment;
1725 /* if (xmlGetWarningsDefaultValue == 0) */
1726 if (warning == 0)
1727 hdlr->warning = NULL;
1728 else
1729 hdlr->warning = xmlParserWarning;
1730 hdlr->error = xmlParserError;
1731 hdlr->fatalError = xmlParserError;
1732
1733 hdlr->initialized = 1;
1734}
Owen Taylor3473f882001-02-23 17:55:21 +00001735
1736/**
1737 * xmlDefaultSAXHandlerInit:
1738 *
1739 * Initialize the default SAX handler
1740 */
1741void
1742xmlDefaultSAXHandlerInit(void)
1743{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +00001744 initxmlDefaultSAXHandler(&xmlDefaultSAXHandler, xmlGetWarningsDefaultValue);
Owen Taylor3473f882001-02-23 17:55:21 +00001745}
1746
Daniel Veillardeae522a2001-04-23 13:41:34 +00001747#ifdef LIBXML_HTML_ENABLED
Daniel Veillardd0463562001-10-13 09:15:48 +00001748
1749/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001750 * inithtmlDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001751 * @hdlr: the SAX handler
Daniel Veillardd0463562001-10-13 09:15:48 +00001752 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001753 * Initialize the default HTML SAX handler
Owen Taylor3473f882001-02-23 17:55:21 +00001754 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001755void
1756inithtmlDefaultSAXHandler(xmlSAXHandler *hdlr)
1757{
1758 if(hdlr->initialized == 1)
1759 return;
1760
1761 hdlr->internalSubset = internalSubset;
1762 hdlr->externalSubset = NULL;
1763 hdlr->isStandalone = NULL;
1764 hdlr->hasInternalSubset = NULL;
1765 hdlr->hasExternalSubset = NULL;
1766 hdlr->resolveEntity = NULL;
1767 hdlr->getEntity = getEntity;
1768 hdlr->getParameterEntity = NULL;
1769 hdlr->entityDecl = NULL;
1770 hdlr->attributeDecl = NULL;
1771 hdlr->elementDecl = NULL;
1772 hdlr->notationDecl = NULL;
1773 hdlr->unparsedEntityDecl = NULL;
1774 hdlr->setDocumentLocator = setDocumentLocator;
1775 hdlr->startDocument = startDocument;
1776 hdlr->endDocument = endDocument;
1777 hdlr->startElement = startElement;
1778 hdlr->endElement = endElement;
1779 hdlr->reference = NULL;
1780 hdlr->characters = characters;
1781 hdlr->cdataBlock = cdataBlock;
1782 hdlr->ignorableWhitespace = ignorableWhitespace;
1783 hdlr->processingInstruction = NULL;
1784 hdlr->comment = comment;
1785 hdlr->warning = xmlParserWarning;
1786 hdlr->error = xmlParserError;
1787 hdlr->fatalError = xmlParserError;
1788
1789 hdlr->initialized = 1;
1790}
Owen Taylor3473f882001-02-23 17:55:21 +00001791
1792/**
1793 * htmlDefaultSAXHandlerInit:
1794 *
1795 * Initialize the default SAX handler
1796 */
1797void
1798htmlDefaultSAXHandlerInit(void)
1799{
Daniel Veillardd0463562001-10-13 09:15:48 +00001800 inithtmlDefaultSAXHandler(&htmlDefaultSAXHandler);
Owen Taylor3473f882001-02-23 17:55:21 +00001801}
Daniel Veillardd0463562001-10-13 09:15:48 +00001802
Daniel Veillardeae522a2001-04-23 13:41:34 +00001803#endif /* LIBXML_HTML_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +00001804
Daniel Veillardeae522a2001-04-23 13:41:34 +00001805#ifdef LIBXML_DOCB_ENABLED
Daniel Veillardd0463562001-10-13 09:15:48 +00001806
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001807/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001808 * initdocbDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001809 * @hdlr: the SAX handler
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001810 *
1811 * Initialize the default DocBook SAX handler
1812 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001813void
1814initdocbDefaultSAXHandler(xmlSAXHandler *hdlr)
1815{
1816 if(hdlr->initialized == 1)
1817 return;
1818
1819 hdlr->internalSubset = internalSubset;
1820 hdlr->externalSubset = NULL;
1821 hdlr->isStandalone = isStandalone;
1822 hdlr->hasInternalSubset = hasInternalSubset;
1823 hdlr->hasExternalSubset = hasExternalSubset;
1824 hdlr->resolveEntity = resolveEntity;
1825 hdlr->getEntity = getEntity;
1826 hdlr->getParameterEntity = NULL;
1827 hdlr->entityDecl = entityDecl;
1828 hdlr->attributeDecl = NULL;
1829 hdlr->elementDecl = NULL;
1830 hdlr->notationDecl = NULL;
1831 hdlr->unparsedEntityDecl = NULL;
1832 hdlr->setDocumentLocator = setDocumentLocator;
1833 hdlr->startDocument = startDocument;
1834 hdlr->endDocument = endDocument;
1835 hdlr->startElement = startElement;
1836 hdlr->endElement = endElement;
1837 hdlr->reference = reference;
1838 hdlr->characters = characters;
1839 hdlr->cdataBlock = NULL;
1840 hdlr->ignorableWhitespace = ignorableWhitespace;
1841 hdlr->processingInstruction = NULL;
1842 hdlr->comment = comment;
1843 hdlr->warning = xmlParserWarning;
1844 hdlr->error = xmlParserError;
1845 hdlr->fatalError = xmlParserError;
1846
1847 hdlr->initialized = 1;
1848}
Owen Taylor3473f882001-02-23 17:55:21 +00001849
1850/**
Daniel Veillardeae522a2001-04-23 13:41:34 +00001851 * docbDefaultSAXHandlerInit:
Owen Taylor3473f882001-02-23 17:55:21 +00001852 *
1853 * Initialize the default SAX handler
1854 */
1855void
Daniel Veillardeae522a2001-04-23 13:41:34 +00001856docbDefaultSAXHandlerInit(void)
Owen Taylor3473f882001-02-23 17:55:21 +00001857{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +00001858 initdocbDefaultSAXHandler(&docbDefaultSAXHandler);
Owen Taylor3473f882001-02-23 17:55:21 +00001859}
Daniel Veillardeae522a2001-04-23 13:41:34 +00001860
1861#endif /* LIBXML_DOCB_ENABLED */