blob: cbf21cf250d396fa12a1acb610f08974ee742418 [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
Daniel Veillard28757702002-02-18 11:19:30 +0000347 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->standalone == 1)) {
348 if (ctxt->inSubset == 2) {
349 ctxt->myDoc->standalone = 0;
350 ret = xmlGetDocEntity(ctxt->myDoc, name);
351 ctxt->myDoc->standalone = 1;
352 } else {
353 ret = xmlGetDocEntity(ctxt->myDoc, name);
354 if (ret == NULL) {
355 ctxt->myDoc->standalone = 0;
356 ret = xmlGetDocEntity(ctxt->myDoc, name);
357 if (ret != NULL) {
358 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
359 ctxt->sax->error(ctxt,
360 "Entity(%s) document marked standalone but require external subset\n",
361 name);
362 ctxt->valid = 0;
363 ctxt->wellFormed = 0;
364 }
365 ctxt->myDoc->standalone = 1;
366 }
367 }
368 } else {
369 ret = xmlGetDocEntity(ctxt->myDoc, name);
370 }
Owen Taylor3473f882001-02-23 17:55:21 +0000371 if ((ret != NULL) && (ctxt->validate) && (ret->children == NULL) &&
372 (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
373 /*
374 * for validation purposes we really need to fetch and
375 * parse the external entity
376 */
Owen Taylor3473f882001-02-23 17:55:21 +0000377 xmlNodePtr children;
378
Daniel Veillard5015b712001-08-17 09:37:52 +0000379 xmlParseCtxtExternalEntity(ctxt, ret->URI, ret->ExternalID, &children);
Owen Taylor3473f882001-02-23 17:55:21 +0000380 xmlAddChildList((xmlNodePtr) ret, children);
381 }
382 return(ret);
383}
384
385/**
386 * getParameterEntity:
387 * @ctx: the user data (XML parser context)
388 * @name: The entity name
389 *
390 * Get a parameter entity by name
391 *
392 * Returns the xmlEntityPtr if found.
393 */
394xmlEntityPtr
395getParameterEntity(void *ctx, const xmlChar *name)
396{
397 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
398 xmlEntityPtr ret;
399
400#ifdef DEBUG_SAX
401 xmlGenericError(xmlGenericErrorContext,
402 "SAX.getParameterEntity(%s)\n", name);
403#endif
404
405 ret = xmlGetParameterEntity(ctxt->myDoc, name);
406 return(ret);
407}
408
409
410/**
411 * entityDecl:
412 * @ctx: the user data (XML parser context)
413 * @name: the entity name
414 * @type: the entity type
415 * @publicId: The public ID of the entity
416 * @systemId: The system ID of the entity
417 * @content: the entity value (without processing).
418 *
419 * An entity definition has been parsed
420 */
421void
422entityDecl(void *ctx, const xmlChar *name, int type,
423 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
424{
425 xmlEntityPtr ent;
426 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
427
428#ifdef DEBUG_SAX
429 xmlGenericError(xmlGenericErrorContext,
430 "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
431 name, type, publicId, systemId, content);
432#endif
433 if (ctxt->inSubset == 1) {
434 ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId,
435 systemId, content);
436 if ((ent == NULL) && (ctxt->pedantic) &&
437 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
438 ctxt->sax->warning(ctxt,
439 "Entity(%s) already defined in the internal subset\n", name);
440 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
441 xmlChar *URI;
442 const char *base = NULL;
443
444 if (ctxt->input != NULL)
445 base = ctxt->input->filename;
446 if (base == NULL)
447 base = ctxt->directory;
448
449 URI = xmlBuildURI(systemId, (const xmlChar *) base);
450 ent->URI = URI;
451 }
452 } else if (ctxt->inSubset == 2) {
453 ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,
454 systemId, content);
455 if ((ent == NULL) && (ctxt->pedantic) &&
456 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
457 ctxt->sax->warning(ctxt,
458 "Entity(%s) already defined in the external subset\n", name);
459 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
460 xmlChar *URI;
461 const char *base = NULL;
462
463 if (ctxt->input != NULL)
464 base = ctxt->input->filename;
465 if (base == NULL)
466 base = ctxt->directory;
467
468 URI = xmlBuildURI(systemId, (const xmlChar *) base);
469 ent->URI = URI;
470 }
471 } else {
472 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
473 ctxt->sax->error(ctxt,
474 "SAX.entityDecl(%s) called while not in subset\n", name);
475 }
476}
477
478/**
479 * attributeDecl:
480 * @ctx: the user data (XML parser context)
481 * @elem: the name of the element
482 * @fullname: the attribute name
483 * @type: the attribute type
484 * @def: the type of default value
485 * @defaultValue: the attribute default value
486 * @tree: the tree of enumerated value set
487 *
488 * An attribute definition has been parsed
489 */
490void
491attributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
492 int type, int def, const xmlChar *defaultValue,
493 xmlEnumerationPtr tree)
494{
495 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
496 xmlAttributePtr attr;
497 xmlChar *name = NULL, *prefix = NULL;
498
499#ifdef DEBUG_SAX
500 xmlGenericError(xmlGenericErrorContext,
501 "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
502 elem, fullname, type, def, defaultValue);
503#endif
504 name = xmlSplitQName(ctxt, fullname, &prefix);
Daniel Veillardc7612992002-02-17 22:47:37 +0000505 ctxt->vctxt.valid = 1;
Owen Taylor3473f882001-02-23 17:55:21 +0000506 if (ctxt->inSubset == 1)
507 attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,
508 name, prefix, (xmlAttributeType) type,
509 (xmlAttributeDefault) def, defaultValue, tree);
510 else if (ctxt->inSubset == 2)
511 attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,
512 name, prefix, (xmlAttributeType) type,
513 (xmlAttributeDefault) def, defaultValue, tree);
514 else {
515 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
516 ctxt->sax->error(ctxt,
517 "SAX.attributeDecl(%s) called while not in subset\n", name);
518 return;
519 }
Daniel Veillardc7612992002-02-17 22:47:37 +0000520 if (ctxt->vctxt.valid == 0)
521 ctxt->valid = 0;
Owen Taylor3473f882001-02-23 17:55:21 +0000522 if (ctxt->validate && ctxt->wellFormed &&
523 ctxt->myDoc && ctxt->myDoc->intSubset)
524 ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
525 attr);
526 if (prefix != NULL)
527 xmlFree(prefix);
528 if (name != NULL)
529 xmlFree(name);
530}
531
532/**
533 * elementDecl:
534 * @ctx: the user data (XML parser context)
535 * @name: the element name
536 * @type: the element type
537 * @content: the element value tree
538 *
539 * An element definition has been parsed
540 */
541void
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000542elementDecl(void *ctx, const xmlChar * name, int type,
543 xmlElementContentPtr content)
Owen Taylor3473f882001-02-23 17:55:21 +0000544{
545 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
546 xmlElementPtr elem = NULL;
547
548#ifdef DEBUG_SAX
549 xmlGenericError(xmlGenericErrorContext,
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000550 "SAX.elementDecl(%s, %d, ...)\n", name, type);
Owen Taylor3473f882001-02-23 17:55:21 +0000551#endif
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000552
Owen Taylor3473f882001-02-23 17:55:21 +0000553 if (ctxt->inSubset == 1)
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000554 elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,
555 name, (xmlElementTypeVal) type, content);
Owen Taylor3473f882001-02-23 17:55:21 +0000556 else if (ctxt->inSubset == 2)
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000557 elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
558 name, (xmlElementTypeVal) type, content);
Owen Taylor3473f882001-02-23 17:55:21 +0000559 else {
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000560 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
561 ctxt->sax->error(ctxt,
562 "SAX.elementDecl(%s) called while not in subset\n",
563 name);
564 return;
Owen Taylor3473f882001-02-23 17:55:21 +0000565 }
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000566 if (elem == NULL)
567 ctxt->valid = 0;
Owen Taylor3473f882001-02-23 17:55:21 +0000568 if (ctxt->validate && ctxt->wellFormed &&
569 ctxt->myDoc && ctxt->myDoc->intSubset)
Daniel Veillard1fd36d22001-07-04 22:54:28 +0000570 ctxt->valid &=
571 xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);
Owen Taylor3473f882001-02-23 17:55:21 +0000572}
573
574/**
575 * notationDecl:
576 * @ctx: the user data (XML parser context)
577 * @name: The name of the notation
578 * @publicId: The public ID of the entity
579 * @systemId: The system ID of the entity
580 *
581 * What to do when a notation declaration has been parsed.
582 */
583void
584notationDecl(void *ctx, const xmlChar *name,
585 const xmlChar *publicId, const xmlChar *systemId)
586{
587 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
588 xmlNotationPtr nota = NULL;
589
590#ifdef DEBUG_SAX
591 xmlGenericError(xmlGenericErrorContext,
592 "SAX.notationDecl(%s, %s, %s)\n", name, publicId, systemId);
593#endif
594
Daniel Veillard7aea52d2002-02-17 23:07:47 +0000595 if ((publicId == NULL) && (systemId == NULL)) {
596 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
597 ctxt->sax->error(ctxt,
598 "SAX.notationDecl(%s) externalID or PublicID missing\n", name);
599 ctxt->valid = 0;
600 ctxt->wellFormed = 0;
601 return;
602 } else if (ctxt->inSubset == 1)
Owen Taylor3473f882001-02-23 17:55:21 +0000603 nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
604 publicId, systemId);
605 else if (ctxt->inSubset == 2)
Daniel Veillard25239c12001-03-14 13:56:48 +0000606 nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
Owen Taylor3473f882001-02-23 17:55:21 +0000607 publicId, systemId);
608 else {
609 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
610 ctxt->sax->error(ctxt,
611 "SAX.notationDecl(%s) called while not in subset\n", name);
612 return;
613 }
614 if (nota == NULL) ctxt->valid = 0;
615 if (ctxt->validate && ctxt->wellFormed &&
616 ctxt->myDoc && ctxt->myDoc->intSubset)
617 ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
618 nota);
619}
620
621/**
622 * unparsedEntityDecl:
623 * @ctx: the user data (XML parser context)
624 * @name: The name of the entity
625 * @publicId: The public ID of the entity
626 * @systemId: The system ID of the entity
627 * @notationName: the name of the notation
628 *
629 * What to do when an unparsed entity declaration is parsed
630 */
631void
632unparsedEntityDecl(void *ctx, const xmlChar *name,
633 const xmlChar *publicId, const xmlChar *systemId,
634 const xmlChar *notationName)
635{
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000636 xmlEntityPtr ent;
Owen Taylor3473f882001-02-23 17:55:21 +0000637 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
638#ifdef DEBUG_SAX
639 xmlGenericError(xmlGenericErrorContext,
640 "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
641 name, publicId, systemId, notationName);
642#endif
Daniel Veillard8ab0f582002-02-18 18:31:38 +0000643#if 0
644 Done in xmlValidateDtdFinal now.
Daniel Veillard28757702002-02-18 11:19:30 +0000645 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc) {
646 int ret;
647 ret = xmlValidateNotationUse(&ctxt->vctxt, ctxt->myDoc,
Owen Taylor3473f882001-02-23 17:55:21 +0000648 notationName);
Daniel Veillard28757702002-02-18 11:19:30 +0000649 if (ret == 0) {
650 ctxt->wellFormed = 0;
651 ctxt->valid = 0;
652 }
653 }
Daniel Veillard8ab0f582002-02-18 18:31:38 +0000654#endif
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000655 if (ctxt->inSubset == 1) {
656 ent = xmlAddDocEntity(ctxt->myDoc, name,
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000657 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
658 publicId, systemId, notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000659 if ((ent == NULL) && (ctxt->pedantic) &&
660 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
661 ctxt->sax->warning(ctxt,
662 "Entity(%s) already defined in the internal subset\n", name);
663 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
664 xmlChar *URI;
665 const char *base = NULL;
666
667 if (ctxt->input != NULL)
668 base = ctxt->input->filename;
669 if (base == NULL)
670 base = ctxt->directory;
671
672 URI = xmlBuildURI(systemId, (const xmlChar *) base);
673 ent->URI = URI;
674 }
675 } else if (ctxt->inSubset == 2) {
676 ent = xmlAddDtdEntity(ctxt->myDoc, name,
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000677 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
678 publicId, systemId, notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000679 if ((ent == NULL) && (ctxt->pedantic) &&
680 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
681 ctxt->sax->warning(ctxt,
682 "Entity(%s) already defined in the external subset\n", name);
683 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
684 xmlChar *URI;
685 const char *base = NULL;
686
687 if (ctxt->input != NULL)
688 base = ctxt->input->filename;
689 if (base == NULL)
690 base = ctxt->directory;
691
692 URI = xmlBuildURI(systemId, (const xmlChar *) base);
693 ent->URI = URI;
694 }
695 } else {
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000696 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
697 ctxt->sax->error(ctxt,
698 "SAX.unparsedEntityDecl(%s) called while not in subset\n", name);
699 }
Owen Taylor3473f882001-02-23 17:55:21 +0000700}
701
702/**
703 * setDocumentLocator:
704 * @ctx: the user data (XML parser context)
705 * @loc: A SAX Locator
706 *
707 * Receive the document locator at startup, actually xmlDefaultSAXLocator
708 * Everything is available on the context, so this is useless in our case.
709 */
710void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000711setDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +0000712{
713 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
714#ifdef DEBUG_SAX
715 xmlGenericError(xmlGenericErrorContext,
716 "SAX.setDocumentLocator()\n");
717#endif
718}
719
720/**
721 * startDocument:
722 * @ctx: the user data (XML parser context)
723 *
724 * called when the document start being processed.
725 */
726void
727startDocument(void *ctx)
728{
729 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
730 xmlDocPtr doc;
731
732#ifdef DEBUG_SAX
733 xmlGenericError(xmlGenericErrorContext,
734 "SAX.startDocument()\n");
735#endif
736 if (ctxt->html) {
737 if (ctxt->myDoc == NULL)
738#ifdef LIBXML_HTML_ENABLED
739 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
740#else
741 xmlGenericError(xmlGenericErrorContext,
742 "libxml2 built without HTML support\n");
743#endif
744 } else {
745 doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
746 if (doc != NULL) {
747 if (ctxt->encoding != NULL)
748 doc->encoding = xmlStrdup(ctxt->encoding);
749 else
750 doc->encoding = NULL;
751 doc->standalone = ctxt->standalone;
752 }
753 }
754 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
755 (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000756 ctxt->myDoc->URL = xmlStrdup((const xmlChar *) ctxt->input->filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000757 }
758}
759
760/**
761 * endDocument:
762 * @ctx: the user data (XML parser context)
763 *
764 * called when the document end has been detected.
765 */
766void
767endDocument(void *ctx)
768{
769 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
770#ifdef DEBUG_SAX
771 xmlGenericError(xmlGenericErrorContext,
772 "SAX.endDocument()\n");
773#endif
774 if (ctxt->validate && ctxt->wellFormed &&
775 ctxt->myDoc && ctxt->myDoc->intSubset)
776 ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
777
778 /*
779 * Grab the encoding if it was added on-the-fly
780 */
781 if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) &&
782 (ctxt->myDoc->encoding == NULL)) {
783 ctxt->myDoc->encoding = ctxt->encoding;
784 ctxt->encoding = NULL;
785 }
786 if ((ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) &&
787 (ctxt->myDoc->encoding == NULL)) {
788 ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding);
789 }
790 if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) &&
791 (ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) {
792 ctxt->myDoc->charset = ctxt->charset;
793 }
794}
795
796/**
797 * attribute:
798 * @ctx: the user data (XML parser context)
799 * @fullname: The attribute name, including namespace prefix
800 * @value: The attribute value
801 *
802 * Handle an attribute that has been read by the parser.
803 * The default handling is to convert the attribute into an
804 * DOM subtree and past it in a new xmlAttr element added to
805 * the element.
806 */
807void
808attribute(void *ctx, const xmlChar *fullname, const xmlChar *value)
809{
810 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
811 xmlAttrPtr ret;
812 xmlChar *name;
813 xmlChar *ns;
814 xmlChar *nval;
815 xmlNsPtr namespace;
816
817/****************
818#ifdef DEBUG_SAX
819 xmlGenericError(xmlGenericErrorContext,
820 "SAX.attribute(%s, %s)\n", fullname, value);
821#endif
822 ****************/
823 /*
824 * Split the full name into a namespace prefix and the tag name
825 */
826 name = xmlSplitQName(ctxt, fullname, &ns);
827
828 /*
829 * Do the last stage of the attribute normalization
830 * Needed for HTML too:
831 * http://www.w3.org/TR/html4/types.html#h-6.2
832 */
833 nval = xmlValidNormalizeAttributeValue(ctxt->myDoc, ctxt->node,
834 fullname, value);
835 if (nval != NULL)
836 value = nval;
837
838 /*
839 * Check whether it's a namespace definition
840 */
841 if ((!ctxt->html) && (ns == NULL) &&
842 (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
843 (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
844 if (value[0] != 0) {
845 xmlURIPtr uri;
846
847 uri = xmlParseURI((const char *)value);
848 if (uri == NULL) {
849 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
850 ctxt->sax->warning(ctxt->userData,
851 "nmlns: %s not a valid URI\n", value);
852 } else {
853 if (uri->scheme == NULL) {
854 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
855 ctxt->sax->warning(ctxt->userData,
856 "nmlns: URI %s is not absolute\n", value);
857 }
858 xmlFreeURI(uri);
859 }
860 }
861
862 /* a default namespace definition */
863 xmlNewNs(ctxt->node, value, NULL);
864 if (name != NULL)
865 xmlFree(name);
866 if (nval != NULL)
867 xmlFree(nval);
868 return;
869 }
870 if ((!ctxt->html) &&
871 (ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
872 (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
873 /*
874 * Validate also for namespace decls, they are attributes from
875 * an XML-1.0 perspective
876 TODO ... doesn't map well with current API
877 if (ctxt->validate && ctxt->wellFormed &&
878 ctxt->myDoc && ctxt->myDoc->intSubset)
879 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
880 ctxt->node, ret, value);
881 */
882 /* a standard namespace definition */
883 xmlNewNs(ctxt->node, value, name);
884 xmlFree(ns);
885 if (name != NULL)
886 xmlFree(name);
887 if (nval != NULL)
888 xmlFree(nval);
889 return;
890 }
891
892 if (ns != NULL)
893 namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
894 else {
895 namespace = NULL;
896 }
897
898 /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */
899 ret = xmlNewNsProp(ctxt->node, namespace, name, NULL);
900
901 if (ret != NULL) {
902 if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
903 xmlNodePtr tmp;
904
905 ret->children = xmlStringGetNodeList(ctxt->myDoc, value);
906 tmp = ret->children;
907 while (tmp != NULL) {
908 tmp->parent = (xmlNodePtr) ret;
909 if (tmp->next == NULL)
910 ret->last = tmp;
911 tmp = tmp->next;
912 }
913 } else if (value != NULL) {
914 ret->children = xmlNewDocText(ctxt->myDoc, value);
915 ret->last = ret->children;
916 if (ret->children != NULL)
917 ret->children->parent = (xmlNodePtr) ret;
918 }
919 }
920
921 if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
922 ctxt->myDoc && ctxt->myDoc->intSubset) {
923
924 /*
925 * If we don't substitute entities, the validation should be
926 * done on a value with replaced entities anyway.
927 */
928 if (!ctxt->replaceEntities) {
929 xmlChar *val;
930
931 ctxt->depth++;
932 val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
933 0,0,0);
934 ctxt->depth--;
Daniel Veillardc7612992002-02-17 22:47:37 +0000935
Owen Taylor3473f882001-02-23 17:55:21 +0000936 if (val == NULL)
937 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
938 ctxt->myDoc, ctxt->node, ret, value);
939 else {
Daniel Veillardc7612992002-02-17 22:47:37 +0000940 xmlChar *nvalnorm;
941
942 /*
943 * Do the last stage of the attribute normalization
944 * It need to be done twice ... it's an extra burden related
945 * to the ability to keep references in attributes
946 */
947 nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc,
948 ctxt->node, fullname, val);
949 if (nvalnorm != NULL) {
950 xmlFree(val);
951 val = nvalnorm;
952 }
953
Owen Taylor3473f882001-02-23 17:55:21 +0000954 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
955 ctxt->myDoc, ctxt->node, ret, val);
956 xmlFree(val);
957 }
958 } else {
959 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
960 ctxt->node, ret, value);
961 }
Daniel Veillard62f313b2001-07-04 19:49:14 +0000962 } else if (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
963 ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0))) {
Owen Taylor3473f882001-02-23 17:55:21 +0000964 /*
965 * when validating, the ID registration is done at the attribute
966 * validation level. Otherwise we have to do specific handling here.
967 */
968 if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
969 xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
970 else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
971 xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
972 }
973
974 if (nval != NULL)
975 xmlFree(nval);
976 if (name != NULL)
977 xmlFree(name);
978 if (ns != NULL)
979 xmlFree(ns);
980}
981
Daniel Veillard878eab02002-02-19 13:46:09 +0000982/*
983 * xmlCheckDefaultedAttributes:
984 *
985 * Check defaulted attributes from the DTD
986 */
987static void
988xmlCheckDefaultedAttributesFromDtd(xmlParserCtxtPtr ctxt,
989 xmlDtdPtr dtd, const xmlChar *name,
990 const xmlChar *prefix, const xmlChar **atts) {
991 xmlElementPtr elemDecl;
992 const xmlChar *att;
993 int i;
994
995 if ((dtd == NULL) || (name == NULL))
996 return;
997 elemDecl = xmlGetDtdQElementDesc(dtd, name, prefix);
998 if (elemDecl != NULL) {
999 xmlAttributePtr attr = elemDecl->attributes;
1000 /*
1001 * Check against defaulted attributes from the external subset
1002 * if the document is stamped as standalone
1003 */
1004 if ((ctxt->myDoc->standalone == 1) &&
1005 (ctxt->myDoc->extSubset != NULL) &&
1006 (ctxt->validate)) {
1007 while (attr != NULL) {
1008 if ((attr->defaultValue != NULL) &&
1009 (xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,
1010 attr->elem, attr->name,
1011 attr->prefix) == attr)) {
1012 xmlChar *fulln;
1013
1014 if (attr->prefix != NULL) {
1015 fulln = xmlStrdup(attr->prefix);
1016 fulln = xmlStrcat(fulln, BAD_CAST ":");
1017 fulln = xmlStrcat(fulln, attr->name);
1018 } else {
1019 fulln = xmlStrdup(attr->name);
1020 }
1021
1022 /*
1023 * Check that the attribute is not declared in the
1024 * serialization
1025 */
1026 att = NULL;
1027 if (atts != NULL) {
1028 i = 0;
1029 att = atts[i];
1030 while (att != NULL) {
1031 if (xmlStrEqual(att, fulln))
1032 break;
1033 i += 2;
1034 att = atts[i];
1035 }
1036 }
1037 if (att == NULL) {
1038 if (ctxt->vctxt.error != NULL)
1039 ctxt->vctxt.error(ctxt->vctxt.userData,
1040 "standalone: attribute %s on %s defaulted from external subset\n",
1041 fulln, attr->elem);
1042 /* Waiting on the XML Core WG decision on this
1043 ctxt->valid = 0;
1044 */
1045 }
1046 }
1047 attr = attr->nexth;
1048 }
1049 }
1050
1051 /*
1052 * Actually insert defaulted values when needed
1053 */
1054 attr = elemDecl->attributes;
1055 while (attr != NULL) {
1056 if (attr->defaultValue != NULL) {
1057 /*
1058 * the element should be instantiated in the tree if:
1059 * - this is a namespace prefix
1060 * - the user required for completion in the tree
1061 * like XSLT
1062 */
1063 if (((attr->prefix != NULL) &&
1064 (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
1065 ((attr->prefix == NULL) &&
1066 (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
1067 (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
1068 xmlChar *fulln;
1069
1070 if (attr->prefix != NULL) {
1071 fulln = xmlStrdup(attr->prefix);
1072 fulln = xmlStrcat(fulln, BAD_CAST ":");
1073 fulln = xmlStrcat(fulln, attr->name);
1074 } else {
1075 fulln = xmlStrdup(attr->name);
1076 }
1077
1078 /*
1079 * Check that the attribute is not declared in the
1080 * serialization
1081 */
1082 att = NULL;
1083 if (atts != NULL) {
1084 i = 0;
1085 att = atts[i];
1086 while (att != NULL) {
1087 if (xmlStrEqual(att, fulln))
1088 break;
1089 i += 2;
1090 att = atts[i];
1091 }
1092 }
1093 if (att == NULL)
1094 attribute(ctxt, fulln, attr->defaultValue);
1095 xmlFree(fulln);
1096 }
1097 }
1098 attr = attr->nexth;
1099 }
1100 }
1101}
1102
Owen Taylor3473f882001-02-23 17:55:21 +00001103/**
1104 * startElement:
1105 * @ctx: the user data (XML parser context)
1106 * @fullname: The element name, including namespace prefix
1107 * @atts: An array of name/value attributes pairs, NULL terminated
1108 *
1109 * called when an opening tag has been processed.
1110 */
1111void
1112startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
1113{
1114 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1115 xmlNodePtr ret;
1116 xmlNodePtr parent = ctxt->node;
1117 xmlNsPtr ns;
1118 xmlChar *name;
1119 xmlChar *prefix;
1120 const xmlChar *att;
1121 const xmlChar *value;
1122 int i;
1123
1124#ifdef DEBUG_SAX
1125 xmlGenericError(xmlGenericErrorContext,
1126 "SAX.startElement(%s)\n", fullname);
1127#endif
1128
1129 /*
1130 * First check on validity:
1131 */
1132 if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
1133 ((ctxt->myDoc->intSubset == NULL) ||
1134 ((ctxt->myDoc->intSubset->notations == NULL) &&
1135 (ctxt->myDoc->intSubset->elements == NULL) &&
1136 (ctxt->myDoc->intSubset->attributes == NULL) &&
1137 (ctxt->myDoc->intSubset->entities == NULL)))) {
1138 if (ctxt->vctxt.error != NULL) {
1139 ctxt->vctxt.error(ctxt->vctxt.userData,
1140 "Validation failed: no DTD found !\n");
1141 }
1142 ctxt->validate = 0;
Daniel Veillard7a51d6d2001-09-10 14:40:43 +00001143 ctxt->valid = 0;
1144 ctxt->errNo = XML_ERR_NO_DTD;
Owen Taylor3473f882001-02-23 17:55:21 +00001145 }
1146
1147
1148 /*
1149 * Split the full name into a namespace prefix and the tag name
1150 */
1151 name = xmlSplitQName(ctxt, fullname, &prefix);
1152
1153
1154 /*
1155 * Note : the namespace resolution is deferred until the end of the
1156 * attributes parsing, since local namespace can be defined as
1157 * an attribute at this level.
1158 */
1159 ret = xmlNewDocNode(ctxt->myDoc, NULL, name, NULL);
1160 if (ret == NULL) return;
1161 if (ctxt->myDoc->children == NULL) {
1162#ifdef DEBUG_SAX_TREE
1163 xmlGenericError(xmlGenericErrorContext, "Setting %s as root\n", name);
1164#endif
1165 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1166 } else if (parent == NULL) {
1167 parent = ctxt->myDoc->children;
1168 }
1169 ctxt->nodemem = -1;
Daniel Veillardd9bad132001-07-23 19:39:43 +00001170 if (ctxt->linenumbers) {
1171 if (ctxt->input != NULL)
1172 ret->content = (void *) (long) ctxt->input->line;
1173 }
Owen Taylor3473f882001-02-23 17:55:21 +00001174
1175 /*
1176 * We are parsing a new node.
1177 */
1178#ifdef DEBUG_SAX_TREE
1179 xmlGenericError(xmlGenericErrorContext, "pushing(%s)\n", name);
1180#endif
1181 nodePush(ctxt, ret);
1182
1183 /*
1184 * Link the child element
1185 */
1186 if (parent != NULL) {
1187 if (parent->type == XML_ELEMENT_NODE) {
1188#ifdef DEBUG_SAX_TREE
1189 xmlGenericError(xmlGenericErrorContext,
1190 "adding child %s to %s\n", name, parent->name);
1191#endif
1192 xmlAddChild(parent, ret);
1193 } else {
1194#ifdef DEBUG_SAX_TREE
1195 xmlGenericError(xmlGenericErrorContext,
1196 "adding sibling %s to ", name);
1197 xmlDebugDumpOneNode(stderr, parent, 0);
1198#endif
1199 xmlAddSibling(parent, ret);
1200 }
1201 }
1202
1203 /*
Daniel Veillard48da9102001-08-07 01:10:10 +00001204 * Insert all the defaulted attributes from the DTD especially namespaces
1205 */
1206 if ((!ctxt->html) &&
1207 ((ctxt->myDoc->intSubset != NULL) ||
1208 (ctxt->myDoc->extSubset != NULL))) {
Daniel Veillard878eab02002-02-19 13:46:09 +00001209 if (ctxt->myDoc->intSubset != NULL)
1210 xmlCheckDefaultedAttributesFromDtd(ctxt, ctxt->myDoc->intSubset,
1211 name, prefix, atts);
1212 if (ctxt->myDoc->extSubset != NULL)
1213 xmlCheckDefaultedAttributesFromDtd(ctxt, ctxt->myDoc->extSubset,
1214 name, prefix, atts);
Daniel Veillard48da9102001-08-07 01:10:10 +00001215 }
1216
1217 /*
Owen Taylor3473f882001-02-23 17:55:21 +00001218 * process all the attributes whose name start with "xml"
1219 */
1220 if (atts != NULL) {
1221 i = 0;
1222 att = atts[i++];
1223 value = atts[i++];
1224 if (!ctxt->html) {
1225 while ((att != NULL) && (value != NULL)) {
1226 if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l'))
1227 attribute(ctxt, att, value);
1228
1229 att = atts[i++];
1230 value = atts[i++];
1231 }
1232 }
1233 }
1234
1235 /*
1236 * Search the namespace, note that since the attributes have been
1237 * processed, the local namespaces are available.
1238 */
1239 ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
1240 if ((ns == NULL) && (parent != NULL))
1241 ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
1242 if ((prefix != NULL) && (ns == NULL)) {
1243 ns = xmlNewNs(ret, NULL, prefix);
1244 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
1245 ctxt->sax->warning(ctxt->userData,
1246 "Namespace prefix %s is not defined\n", prefix);
1247 }
Daniel Veillard143b04f2001-09-10 18:14:14 +00001248
1249 /*
1250 * set the namespace node, making sure that if the default namspace
1251 * is unbound on a parent we simply kee it NULL
1252 */
Daniel Veillard651f9472001-10-04 14:51:06 +00001253 if ((ns != NULL) && (ns->href != NULL) && (ns->href[0] != 0))
Daniel Veillard143b04f2001-09-10 18:14:14 +00001254 xmlSetNs(ret, ns);
Owen Taylor3473f882001-02-23 17:55:21 +00001255
1256 /*
1257 * process all the other attributes
1258 */
1259 if (atts != NULL) {
1260 i = 0;
1261 att = atts[i++];
1262 value = atts[i++];
1263 if (ctxt->html) {
1264 while (att != NULL) {
1265 attribute(ctxt, att, value);
1266 att = atts[i++];
1267 value = atts[i++];
1268 }
1269 } else {
1270 while ((att != NULL) && (value != NULL)) {
1271 if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l'))
1272 attribute(ctxt, att, value);
1273
1274 /*
1275 * Next ones
1276 */
1277 att = atts[i++];
1278 value = atts[i++];
1279 }
1280 }
1281 }
1282
1283 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001284 * If it's the Document root, finish the DTD validation and
Owen Taylor3473f882001-02-23 17:55:21 +00001285 * check the document root element for validity
1286 */
1287 if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) {
Daniel Veillard8ab0f582002-02-18 18:31:38 +00001288 int chk;
1289
1290 chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
1291 if (chk <= 0)
1292 ctxt->valid = 0;
1293 if (chk < 0)
1294 ctxt->wellFormed = 0;
Owen Taylor3473f882001-02-23 17:55:21 +00001295 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
1296 ctxt->vctxt.finishDtd = 1;
1297 }
1298
1299 if (prefix != NULL)
1300 xmlFree(prefix);
1301 if (name != NULL)
1302 xmlFree(name);
1303
1304}
1305
1306/**
1307 * endElement:
1308 * @ctx: the user data (XML parser context)
1309 * @name: The element name
1310 *
1311 * called when the end of an element has been detected.
1312 */
1313void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +00001314endElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +00001315{
1316 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1317 xmlParserNodeInfo node_info;
1318 xmlNodePtr cur = ctxt->node;
1319
1320#ifdef DEBUG_SAX
1321 if (name == NULL)
1322 xmlGenericError(xmlGenericErrorContext, "SAX.endElement(NULL)\n");
1323 else
1324 xmlGenericError(xmlGenericErrorContext, "SAX.endElement(%s)\n", name);
1325#endif
1326
1327 /* Capture end position and add node */
1328 if (cur != NULL && ctxt->record_info) {
1329 node_info.end_pos = ctxt->input->cur - ctxt->input->base;
1330 node_info.end_line = ctxt->input->line;
1331 node_info.node = cur;
1332 xmlParserAddNodeInfo(ctxt, &node_info);
1333 }
1334 ctxt->nodemem = -1;
1335
1336 if (ctxt->validate && ctxt->wellFormed &&
1337 ctxt->myDoc && ctxt->myDoc->intSubset)
1338 ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
1339 cur);
1340
1341
1342 /*
1343 * end of parsing of this node.
1344 */
1345#ifdef DEBUG_SAX_TREE
1346 xmlGenericError(xmlGenericErrorContext, "popping(%s)\n", cur->name);
1347#endif
1348 nodePop(ctxt);
1349}
1350
1351/**
1352 * reference:
1353 * @ctx: the user data (XML parser context)
1354 * @name: The entity name
1355 *
1356 * called when an entity reference is detected.
1357 */
1358void
1359reference(void *ctx, const xmlChar *name)
1360{
1361 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1362 xmlNodePtr ret;
1363
1364#ifdef DEBUG_SAX
1365 xmlGenericError(xmlGenericErrorContext,
1366 "SAX.reference(%s)\n", name);
1367#endif
1368 if (name[0] == '#')
1369 ret = xmlNewCharRef(ctxt->myDoc, name);
1370 else
1371 ret = xmlNewReference(ctxt->myDoc, name);
1372#ifdef DEBUG_SAX_TREE
1373 xmlGenericError(xmlGenericErrorContext,
1374 "add reference %s to %s \n", name, ctxt->node->name);
1375#endif
1376 xmlAddChild(ctxt->node, ret);
1377}
1378
1379/**
1380 * characters:
1381 * @ctx: the user data (XML parser context)
1382 * @ch: a xmlChar string
1383 * @len: the number of xmlChar
1384 *
1385 * receiving some chars from the parser.
Owen Taylor3473f882001-02-23 17:55:21 +00001386 */
1387void
1388characters(void *ctx, const xmlChar *ch, int len)
1389{
1390 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1391 xmlNodePtr lastChild;
1392
1393#ifdef DEBUG_SAX
1394 xmlGenericError(xmlGenericErrorContext,
1395 "SAX.characters(%.30s, %d)\n", ch, len);
1396#endif
1397 /*
1398 * Handle the data if any. If there is no child
1399 * add it as content, otherwise if the last child is text,
1400 * concatenate it, else create a new node of type text.
1401 */
1402
1403 if (ctxt->node == NULL) {
1404#ifdef DEBUG_SAX_TREE
1405 xmlGenericError(xmlGenericErrorContext,
1406 "add chars: ctxt->node == NULL !\n");
1407#endif
1408 return;
1409 }
1410 lastChild = xmlGetLastChild(ctxt->node);
1411#ifdef DEBUG_SAX_TREE
1412 xmlGenericError(xmlGenericErrorContext,
1413 "add chars to %s \n", ctxt->node->name);
1414#endif
1415
1416 /*
1417 * Here we needed an accelerator mechanism in case of very large
1418 * elements. Use an attribute in the structure !!!
1419 */
1420 if (lastChild == NULL) {
1421 /* first node, first time */
1422 xmlNodeAddContentLen(ctxt->node, ch, len);
1423#ifndef XML_USE_BUFFER_CONTENT
1424 if (ctxt->node->children != NULL) {
1425 ctxt->nodelen = len;
1426 ctxt->nodemem = len + 1;
1427 }
1428#endif
1429 } else {
Daniel Veillardf300b7e2001-08-13 10:43:15 +00001430 int coalesceText = (lastChild != NULL) &&
1431 (lastChild->type == XML_TEXT_NODE) &&
1432 (lastChild->name == xmlStringText);
1433 if ((coalesceText) && (ctxt->nodemem != 0)) {
Owen Taylor3473f882001-02-23 17:55:21 +00001434#ifndef XML_USE_BUFFER_CONTENT
1435 /*
1436 * The whole point of maintaining nodelen and nodemem,
Daniel Veillard60087f32001-10-10 09:45:09 +00001437 * xmlTextConcat is too costly, i.e. compute length,
Owen Taylor3473f882001-02-23 17:55:21 +00001438 * reallocate a new buffer, move data, append ch. Here
1439 * We try to minimaze realloc() uses and avoid copying
Daniel Veillard60087f32001-10-10 09:45:09 +00001440 * and recomputing length over and over.
Owen Taylor3473f882001-02-23 17:55:21 +00001441 */
1442 if (ctxt->nodelen + len >= ctxt->nodemem) {
1443 xmlChar *newbuf;
1444 int size;
1445
1446 size = ctxt->nodemem + len;
1447 size *= 2;
1448 newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
1449 if (newbuf == NULL) {
1450 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1451 ctxt->sax->error(ctxt->userData,
1452 "SAX.characters(): out of memory\n");
1453 return;
1454 }
1455 ctxt->nodemem = size;
1456 lastChild->content = newbuf;
1457 }
1458 memcpy(&lastChild->content[ctxt->nodelen], ch, len);
1459 ctxt->nodelen += len;
1460 lastChild->content[ctxt->nodelen] = 0;
1461#else
1462 xmlTextConcat(lastChild, ch, len);
1463#endif
Daniel Veillardf300b7e2001-08-13 10:43:15 +00001464 } else if (coalesceText) {
Daniel Veillard80f32572001-03-07 19:45:40 +00001465 xmlTextConcat(lastChild, ch, len);
1466 if (ctxt->node->children != NULL) {
1467 ctxt->nodelen = xmlStrlen(lastChild->content);
1468 ctxt->nodemem = ctxt->nodelen + 1;
1469 }
Owen Taylor3473f882001-02-23 17:55:21 +00001470 } else {
1471 /* Mixed content, first time */
1472 lastChild = xmlNewTextLen(ch, len);
1473 xmlAddChild(ctxt->node, lastChild);
1474#ifndef XML_USE_BUFFER_CONTENT
1475 if (ctxt->node->children != NULL) {
1476 ctxt->nodelen = len;
1477 ctxt->nodemem = len + 1;
1478 }
1479#endif
1480 }
1481 }
1482}
1483
1484/**
1485 * ignorableWhitespace:
1486 * @ctx: the user data (XML parser context)
1487 * @ch: a xmlChar string
1488 * @len: the number of xmlChar
1489 *
1490 * receiving some ignorable whitespaces from the parser.
Daniel Veillard05c13a22001-09-09 08:38:09 +00001491 * UNUSED: by default the DOM building will use characters
Owen Taylor3473f882001-02-23 17:55:21 +00001492 */
1493void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +00001494ignorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +00001495{
1496 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
1497#ifdef DEBUG_SAX
1498 xmlGenericError(xmlGenericErrorContext,
1499 "SAX.ignorableWhitespace(%.30s, %d)\n", ch, len);
1500#endif
1501}
1502
1503/**
1504 * processingInstruction:
1505 * @ctx: the user data (XML parser context)
1506 * @target: the target name
1507 * @data: the PI data's
1508 *
1509 * A processing instruction has been parsed.
1510 */
1511void
1512processingInstruction(void *ctx, const xmlChar *target,
1513 const xmlChar *data)
1514{
1515 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1516 xmlNodePtr ret;
1517 xmlNodePtr parent = ctxt->node;
1518
1519#ifdef DEBUG_SAX
1520 xmlGenericError(xmlGenericErrorContext,
1521 "SAX.processingInstruction(%s, %s)\n", target, data);
1522#endif
1523
1524 ret = xmlNewPI(target, data);
1525 if (ret == NULL) return;
1526 parent = ctxt->node;
1527
1528 if (ctxt->inSubset == 1) {
1529 xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
1530 return;
1531 } else if (ctxt->inSubset == 2) {
1532 xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
1533 return;
1534 }
1535 if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
1536#ifdef DEBUG_SAX_TREE
1537 xmlGenericError(xmlGenericErrorContext,
1538 "Setting PI %s as root\n", target);
1539#endif
1540 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1541 return;
1542 }
1543 if (parent->type == XML_ELEMENT_NODE) {
1544#ifdef DEBUG_SAX_TREE
1545 xmlGenericError(xmlGenericErrorContext,
1546 "adding PI %s child to %s\n", target, parent->name);
1547#endif
1548 xmlAddChild(parent, ret);
1549 } else {
1550#ifdef DEBUG_SAX_TREE
1551 xmlGenericError(xmlGenericErrorContext,
1552 "adding PI %s sibling to ", target);
1553 xmlDebugDumpOneNode(stderr, parent, 0);
1554#endif
1555 xmlAddSibling(parent, ret);
1556 }
1557}
1558
1559/**
1560 * globalNamespace:
1561 * @ctx: the user data (XML parser context)
1562 * @href: the namespace associated URN
1563 * @prefix: the namespace prefix
1564 *
1565 * An old global namespace has been parsed.
1566 */
1567void
1568globalNamespace(void *ctx, const xmlChar *href, const xmlChar *prefix)
1569{
1570 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1571#ifdef DEBUG_SAX
1572 xmlGenericError(xmlGenericErrorContext,
1573 "SAX.globalNamespace(%s, %s)\n", href, prefix);
1574#endif
1575 xmlNewGlobalNs(ctxt->myDoc, href, prefix);
1576}
1577
1578/**
1579 * setNamespace:
1580 * @ctx: the user data (XML parser context)
1581 * @name: the namespace prefix
1582 *
1583 * Set the current element namespace.
1584 */
1585
1586void
1587setNamespace(void *ctx, const xmlChar *name)
1588{
1589 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1590 xmlNsPtr ns;
1591 xmlNodePtr parent;
1592
1593#ifdef DEBUG_SAX
1594 xmlGenericError(xmlGenericErrorContext, "SAX.setNamespace(%s)\n", name);
1595#endif
1596 ns = xmlSearchNs(ctxt->myDoc, ctxt->node, name);
1597 if (ns == NULL) { /* ctxt->node may not have a parent yet ! */
1598 if (ctxt->nodeNr >= 2) {
1599 parent = ctxt->nodeTab[ctxt->nodeNr - 2];
1600 if (parent != NULL)
1601 ns = xmlSearchNs(ctxt->myDoc, parent, name);
1602 }
1603 }
1604 xmlSetNs(ctxt->node, ns);
1605}
1606
1607/**
1608 * getNamespace:
1609 * @ctx: the user data (XML parser context)
1610 *
1611 * Get the current element namespace.
1612 *
1613 * Returns the xmlNsPtr or NULL if none
1614 */
1615
1616xmlNsPtr
1617getNamespace(void *ctx)
1618{
1619 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1620 xmlNsPtr ret;
1621
1622#ifdef DEBUG_SAX
1623 xmlGenericError(xmlGenericErrorContext, "SAX.getNamespace()\n");
1624#endif
1625 ret = ctxt->node->ns;
1626 return(ret);
1627}
1628
1629/**
1630 * checkNamespace:
1631 * @ctx: the user data (XML parser context)
1632 * @namespace: the namespace to check against
1633 *
1634 * Check that the current element namespace is the same as the
1635 * one read upon parsing.
1636 *
1637 * Returns 1 if true 0 otherwise
1638 */
1639
1640int
1641checkNamespace(void *ctx, xmlChar *namespace)
1642{
1643 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1644 xmlNodePtr cur = ctxt->node;
1645
1646#ifdef DEBUG_SAX
1647 xmlGenericError(xmlGenericErrorContext,
1648 "SAX.checkNamespace(%s)\n", namespace);
1649#endif
1650
1651 /*
1652 * Check that the Name in the ETag is the same as in the STag.
1653 */
1654 if (namespace == NULL) {
1655 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
1656 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1657 ctxt->sax->error(ctxt,
1658 "End tags for %s don't hold the namespace %s\n",
1659 cur->name, cur->ns->prefix);
1660 ctxt->wellFormed = 0;
1661 }
1662 } else {
1663 if ((cur->ns == NULL) || (cur->ns->prefix == NULL)) {
1664 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1665 ctxt->sax->error(ctxt,
1666 "End tags %s holds a prefix %s not used by the open tag\n",
1667 cur->name, namespace);
1668 ctxt->wellFormed = 0;
1669 } else if (!xmlStrEqual(namespace, cur->ns->prefix)) {
1670 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1671 ctxt->sax->error(ctxt,
1672 "Start and End tags for %s don't use the same namespaces: %s and %s\n",
1673 cur->name, cur->ns->prefix, namespace);
1674 ctxt->wellFormed = 0;
1675 } else
1676 return(1);
1677 }
1678 return(0);
1679}
1680
1681/**
1682 * namespaceDecl:
1683 * @ctx: the user data (XML parser context)
1684 * @href: the namespace associated URN
1685 * @prefix: the namespace prefix
1686 *
1687 * A namespace has been parsed.
1688 */
1689void
1690namespaceDecl(void *ctx, const xmlChar *href, const xmlChar *prefix)
1691{
1692 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1693#ifdef DEBUG_SAX
1694 if (prefix == NULL)
1695 xmlGenericError(xmlGenericErrorContext,
1696 "SAX.namespaceDecl(%s, NULL)\n", href);
1697 else
1698 xmlGenericError(xmlGenericErrorContext,
1699 "SAX.namespaceDecl(%s, %s)\n", href, prefix);
1700#endif
1701 xmlNewNs(ctxt->node, href, prefix);
1702}
1703
1704/**
1705 * comment:
1706 * @ctx: the user data (XML parser context)
1707 * @value: the comment content
1708 *
1709 * A comment has been parsed.
1710 */
1711void
1712comment(void *ctx, const xmlChar *value)
1713{
1714 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1715 xmlNodePtr ret;
1716 xmlNodePtr parent = ctxt->node;
1717
1718#ifdef DEBUG_SAX
1719 xmlGenericError(xmlGenericErrorContext, "SAX.comment(%s)\n", value);
1720#endif
1721 ret = xmlNewDocComment(ctxt->myDoc, value);
1722 if (ret == NULL) return;
1723
1724 if (ctxt->inSubset == 1) {
1725 xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
1726 return;
1727 } else if (ctxt->inSubset == 2) {
1728 xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
1729 return;
1730 }
1731 if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
1732#ifdef DEBUG_SAX_TREE
1733 xmlGenericError(xmlGenericErrorContext,
1734 "Setting comment as root\n");
1735#endif
1736 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1737 return;
1738 }
1739 if (parent->type == XML_ELEMENT_NODE) {
1740#ifdef DEBUG_SAX_TREE
1741 xmlGenericError(xmlGenericErrorContext,
1742 "adding comment child to %s\n", parent->name);
1743#endif
1744 xmlAddChild(parent, ret);
1745 } else {
1746#ifdef DEBUG_SAX_TREE
1747 xmlGenericError(xmlGenericErrorContext,
1748 "adding comment sibling to ");
1749 xmlDebugDumpOneNode(stderr, parent, 0);
1750#endif
1751 xmlAddSibling(parent, ret);
1752 }
1753}
1754
1755/**
1756 * cdataBlock:
1757 * @ctx: the user data (XML parser context)
1758 * @value: The pcdata content
1759 * @len: the block length
1760 *
1761 * called when a pcdata block has been parsed
1762 */
1763void
1764cdataBlock(void *ctx, const xmlChar *value, int len)
1765{
1766 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1767 xmlNodePtr ret, lastChild;
1768
1769#ifdef DEBUG_SAX
1770 xmlGenericError(xmlGenericErrorContext,
1771 "SAX.pcdata(%.10s, %d)\n", value, len);
1772#endif
1773 lastChild = xmlGetLastChild(ctxt->node);
1774#ifdef DEBUG_SAX_TREE
1775 xmlGenericError(xmlGenericErrorContext,
1776 "add chars to %s \n", ctxt->node->name);
1777#endif
1778 if ((lastChild != NULL) &&
1779 (lastChild->type == XML_CDATA_SECTION_NODE)) {
1780 xmlTextConcat(lastChild, value, len);
1781 } else {
1782 ret = xmlNewCDataBlock(ctxt->myDoc, value, len);
1783 xmlAddChild(ctxt->node, ret);
1784 }
1785}
1786
Daniel Veillardd0463562001-10-13 09:15:48 +00001787/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001788 * initxmlDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001789 * @hdlr: the SAX handler
1790 * @warning: flag if non-zero sets the handler warning procedure
Daniel Veillardd0463562001-10-13 09:15:48 +00001791 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001792 * Initialize the default XML SAX handler
Owen Taylor3473f882001-02-23 17:55:21 +00001793 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001794void
1795initxmlDefaultSAXHandler(xmlSAXHandler *hdlr, int warning)
1796{
1797 if(hdlr->initialized == 1)
1798 return;
1799
1800 hdlr->internalSubset = internalSubset;
1801 hdlr->externalSubset = externalSubset;
1802 hdlr->isStandalone = isStandalone;
1803 hdlr->hasInternalSubset = hasInternalSubset;
1804 hdlr->hasExternalSubset = hasExternalSubset;
1805 hdlr->resolveEntity = resolveEntity;
1806 hdlr->getEntity = getEntity;
1807 hdlr->getParameterEntity = getParameterEntity;
1808 hdlr->entityDecl = entityDecl;
1809 hdlr->attributeDecl = attributeDecl;
1810 hdlr->elementDecl = elementDecl;
1811 hdlr->notationDecl = notationDecl;
1812 hdlr->unparsedEntityDecl = unparsedEntityDecl;
1813 hdlr->setDocumentLocator = setDocumentLocator;
1814 hdlr->startDocument = startDocument;
1815 hdlr->endDocument = endDocument;
1816 hdlr->startElement = startElement;
1817 hdlr->endElement = endElement;
1818 hdlr->reference = reference;
1819 hdlr->characters = characters;
1820 hdlr->cdataBlock = cdataBlock;
1821 hdlr->ignorableWhitespace = characters;
1822 hdlr->processingInstruction = processingInstruction;
1823 hdlr->comment = comment;
1824 /* if (xmlGetWarningsDefaultValue == 0) */
1825 if (warning == 0)
1826 hdlr->warning = NULL;
1827 else
1828 hdlr->warning = xmlParserWarning;
1829 hdlr->error = xmlParserError;
1830 hdlr->fatalError = xmlParserError;
1831
1832 hdlr->initialized = 1;
1833}
Owen Taylor3473f882001-02-23 17:55:21 +00001834
1835/**
1836 * xmlDefaultSAXHandlerInit:
1837 *
1838 * Initialize the default SAX handler
1839 */
1840void
1841xmlDefaultSAXHandlerInit(void)
1842{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +00001843 initxmlDefaultSAXHandler(&xmlDefaultSAXHandler, xmlGetWarningsDefaultValue);
Owen Taylor3473f882001-02-23 17:55:21 +00001844}
1845
Daniel Veillardeae522a2001-04-23 13:41:34 +00001846#ifdef LIBXML_HTML_ENABLED
Daniel Veillardd0463562001-10-13 09:15:48 +00001847
1848/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001849 * inithtmlDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001850 * @hdlr: the SAX handler
Daniel Veillardd0463562001-10-13 09:15:48 +00001851 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001852 * Initialize the default HTML SAX handler
Owen Taylor3473f882001-02-23 17:55:21 +00001853 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001854void
1855inithtmlDefaultSAXHandler(xmlSAXHandler *hdlr)
1856{
1857 if(hdlr->initialized == 1)
1858 return;
1859
1860 hdlr->internalSubset = internalSubset;
1861 hdlr->externalSubset = NULL;
1862 hdlr->isStandalone = NULL;
1863 hdlr->hasInternalSubset = NULL;
1864 hdlr->hasExternalSubset = NULL;
1865 hdlr->resolveEntity = NULL;
1866 hdlr->getEntity = getEntity;
1867 hdlr->getParameterEntity = NULL;
1868 hdlr->entityDecl = NULL;
1869 hdlr->attributeDecl = NULL;
1870 hdlr->elementDecl = NULL;
1871 hdlr->notationDecl = NULL;
1872 hdlr->unparsedEntityDecl = NULL;
1873 hdlr->setDocumentLocator = setDocumentLocator;
1874 hdlr->startDocument = startDocument;
1875 hdlr->endDocument = endDocument;
1876 hdlr->startElement = startElement;
1877 hdlr->endElement = endElement;
1878 hdlr->reference = NULL;
1879 hdlr->characters = characters;
1880 hdlr->cdataBlock = cdataBlock;
1881 hdlr->ignorableWhitespace = ignorableWhitespace;
1882 hdlr->processingInstruction = NULL;
1883 hdlr->comment = comment;
1884 hdlr->warning = xmlParserWarning;
1885 hdlr->error = xmlParserError;
1886 hdlr->fatalError = xmlParserError;
1887
1888 hdlr->initialized = 1;
1889}
Owen Taylor3473f882001-02-23 17:55:21 +00001890
1891/**
1892 * htmlDefaultSAXHandlerInit:
1893 *
1894 * Initialize the default SAX handler
1895 */
1896void
1897htmlDefaultSAXHandlerInit(void)
1898{
Daniel Veillardd0463562001-10-13 09:15:48 +00001899 inithtmlDefaultSAXHandler(&htmlDefaultSAXHandler);
Owen Taylor3473f882001-02-23 17:55:21 +00001900}
Daniel Veillardd0463562001-10-13 09:15:48 +00001901
Daniel Veillardeae522a2001-04-23 13:41:34 +00001902#endif /* LIBXML_HTML_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +00001903
Daniel Veillardeae522a2001-04-23 13:41:34 +00001904#ifdef LIBXML_DOCB_ENABLED
Daniel Veillardd0463562001-10-13 09:15:48 +00001905
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001906/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001907 * initdocbDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001908 * @hdlr: the SAX handler
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001909 *
1910 * Initialize the default DocBook SAX handler
1911 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001912void
1913initdocbDefaultSAXHandler(xmlSAXHandler *hdlr)
1914{
1915 if(hdlr->initialized == 1)
1916 return;
1917
1918 hdlr->internalSubset = internalSubset;
1919 hdlr->externalSubset = NULL;
1920 hdlr->isStandalone = isStandalone;
1921 hdlr->hasInternalSubset = hasInternalSubset;
1922 hdlr->hasExternalSubset = hasExternalSubset;
1923 hdlr->resolveEntity = resolveEntity;
1924 hdlr->getEntity = getEntity;
1925 hdlr->getParameterEntity = NULL;
1926 hdlr->entityDecl = entityDecl;
1927 hdlr->attributeDecl = NULL;
1928 hdlr->elementDecl = NULL;
1929 hdlr->notationDecl = NULL;
1930 hdlr->unparsedEntityDecl = NULL;
1931 hdlr->setDocumentLocator = setDocumentLocator;
1932 hdlr->startDocument = startDocument;
1933 hdlr->endDocument = endDocument;
1934 hdlr->startElement = startElement;
1935 hdlr->endElement = endElement;
1936 hdlr->reference = reference;
1937 hdlr->characters = characters;
1938 hdlr->cdataBlock = NULL;
1939 hdlr->ignorableWhitespace = ignorableWhitespace;
1940 hdlr->processingInstruction = NULL;
1941 hdlr->comment = comment;
1942 hdlr->warning = xmlParserWarning;
1943 hdlr->error = xmlParserError;
1944 hdlr->fatalError = xmlParserError;
1945
1946 hdlr->initialized = 1;
1947}
Owen Taylor3473f882001-02-23 17:55:21 +00001948
1949/**
Daniel Veillardeae522a2001-04-23 13:41:34 +00001950 * docbDefaultSAXHandlerInit:
Owen Taylor3473f882001-02-23 17:55:21 +00001951 *
1952 * Initialize the default SAX handler
1953 */
1954void
Daniel Veillardeae522a2001-04-23 13:41:34 +00001955docbDefaultSAXHandlerInit(void)
Owen Taylor3473f882001-02-23 17:55:21 +00001956{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +00001957 initdocbDefaultSAXHandler(&docbDefaultSAXHandler);
Owen Taylor3473f882001-02-23 17:55:21 +00001958}
Daniel Veillardeae522a2001-04-23 13:41:34 +00001959
1960#endif /* LIBXML_DOCB_ENABLED */