blob: ae31245e725602dc6aace9e9390e879af32b510a [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 Veillard28757702002-02-18 11:19:30 +0000643 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc) {
644 int ret;
645 ret = xmlValidateNotationUse(&ctxt->vctxt, ctxt->myDoc,
Owen Taylor3473f882001-02-23 17:55:21 +0000646 notationName);
Daniel Veillard28757702002-02-18 11:19:30 +0000647 if (ret == 0) {
648 ctxt->wellFormed = 0;
649 ctxt->valid = 0;
650 }
651 }
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000652 if (ctxt->inSubset == 1) {
653 ent = xmlAddDocEntity(ctxt->myDoc, name,
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000654 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
655 publicId, systemId, notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000656 if ((ent == NULL) && (ctxt->pedantic) &&
657 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
658 ctxt->sax->warning(ctxt,
659 "Entity(%s) already defined in the internal subset\n", name);
660 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
661 xmlChar *URI;
662 const char *base = NULL;
663
664 if (ctxt->input != NULL)
665 base = ctxt->input->filename;
666 if (base == NULL)
667 base = ctxt->directory;
668
669 URI = xmlBuildURI(systemId, (const xmlChar *) base);
670 ent->URI = URI;
671 }
672 } else if (ctxt->inSubset == 2) {
673 ent = xmlAddDtdEntity(ctxt->myDoc, name,
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000674 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
675 publicId, systemId, notationName);
Daniel Veillard9f4eb912001-08-01 21:22:27 +0000676 if ((ent == NULL) && (ctxt->pedantic) &&
677 (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
678 ctxt->sax->warning(ctxt,
679 "Entity(%s) already defined in the external subset\n", name);
680 if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
681 xmlChar *URI;
682 const char *base = NULL;
683
684 if (ctxt->input != NULL)
685 base = ctxt->input->filename;
686 if (base == NULL)
687 base = ctxt->directory;
688
689 URI = xmlBuildURI(systemId, (const xmlChar *) base);
690 ent->URI = URI;
691 }
692 } else {
Daniel Veillarde020c3a2001-03-21 18:06:15 +0000693 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
694 ctxt->sax->error(ctxt,
695 "SAX.unparsedEntityDecl(%s) called while not in subset\n", name);
696 }
Owen Taylor3473f882001-02-23 17:55:21 +0000697}
698
699/**
700 * setDocumentLocator:
701 * @ctx: the user data (XML parser context)
702 * @loc: A SAX Locator
703 *
704 * Receive the document locator at startup, actually xmlDefaultSAXLocator
705 * Everything is available on the context, so this is useless in our case.
706 */
707void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000708setDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +0000709{
710 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
711#ifdef DEBUG_SAX
712 xmlGenericError(xmlGenericErrorContext,
713 "SAX.setDocumentLocator()\n");
714#endif
715}
716
717/**
718 * startDocument:
719 * @ctx: the user data (XML parser context)
720 *
721 * called when the document start being processed.
722 */
723void
724startDocument(void *ctx)
725{
726 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
727 xmlDocPtr doc;
728
729#ifdef DEBUG_SAX
730 xmlGenericError(xmlGenericErrorContext,
731 "SAX.startDocument()\n");
732#endif
733 if (ctxt->html) {
734 if (ctxt->myDoc == NULL)
735#ifdef LIBXML_HTML_ENABLED
736 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
737#else
738 xmlGenericError(xmlGenericErrorContext,
739 "libxml2 built without HTML support\n");
740#endif
741 } else {
742 doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
743 if (doc != NULL) {
744 if (ctxt->encoding != NULL)
745 doc->encoding = xmlStrdup(ctxt->encoding);
746 else
747 doc->encoding = NULL;
748 doc->standalone = ctxt->standalone;
749 }
750 }
751 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
752 (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000753 ctxt->myDoc->URL = xmlStrdup((const xmlChar *) ctxt->input->filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000754 }
755}
756
757/**
758 * endDocument:
759 * @ctx: the user data (XML parser context)
760 *
761 * called when the document end has been detected.
762 */
763void
764endDocument(void *ctx)
765{
766 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
767#ifdef DEBUG_SAX
768 xmlGenericError(xmlGenericErrorContext,
769 "SAX.endDocument()\n");
770#endif
771 if (ctxt->validate && ctxt->wellFormed &&
772 ctxt->myDoc && ctxt->myDoc->intSubset)
773 ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
774
775 /*
776 * Grab the encoding if it was added on-the-fly
777 */
778 if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) &&
779 (ctxt->myDoc->encoding == NULL)) {
780 ctxt->myDoc->encoding = ctxt->encoding;
781 ctxt->encoding = NULL;
782 }
783 if ((ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) &&
784 (ctxt->myDoc->encoding == NULL)) {
785 ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding);
786 }
787 if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) &&
788 (ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) {
789 ctxt->myDoc->charset = ctxt->charset;
790 }
791}
792
793/**
794 * attribute:
795 * @ctx: the user data (XML parser context)
796 * @fullname: The attribute name, including namespace prefix
797 * @value: The attribute value
798 *
799 * Handle an attribute that has been read by the parser.
800 * The default handling is to convert the attribute into an
801 * DOM subtree and past it in a new xmlAttr element added to
802 * the element.
803 */
804void
805attribute(void *ctx, const xmlChar *fullname, const xmlChar *value)
806{
807 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
808 xmlAttrPtr ret;
809 xmlChar *name;
810 xmlChar *ns;
811 xmlChar *nval;
812 xmlNsPtr namespace;
813
814/****************
815#ifdef DEBUG_SAX
816 xmlGenericError(xmlGenericErrorContext,
817 "SAX.attribute(%s, %s)\n", fullname, value);
818#endif
819 ****************/
820 /*
821 * Split the full name into a namespace prefix and the tag name
822 */
823 name = xmlSplitQName(ctxt, fullname, &ns);
824
825 /*
826 * Do the last stage of the attribute normalization
827 * Needed for HTML too:
828 * http://www.w3.org/TR/html4/types.html#h-6.2
829 */
830 nval = xmlValidNormalizeAttributeValue(ctxt->myDoc, ctxt->node,
831 fullname, value);
832 if (nval != NULL)
833 value = nval;
834
835 /*
836 * Check whether it's a namespace definition
837 */
838 if ((!ctxt->html) && (ns == NULL) &&
839 (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
840 (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
841 if (value[0] != 0) {
842 xmlURIPtr uri;
843
844 uri = xmlParseURI((const char *)value);
845 if (uri == NULL) {
846 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
847 ctxt->sax->warning(ctxt->userData,
848 "nmlns: %s not a valid URI\n", value);
849 } else {
850 if (uri->scheme == NULL) {
851 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
852 ctxt->sax->warning(ctxt->userData,
853 "nmlns: URI %s is not absolute\n", value);
854 }
855 xmlFreeURI(uri);
856 }
857 }
858
859 /* a default namespace definition */
860 xmlNewNs(ctxt->node, value, NULL);
861 if (name != NULL)
862 xmlFree(name);
863 if (nval != NULL)
864 xmlFree(nval);
865 return;
866 }
867 if ((!ctxt->html) &&
868 (ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
869 (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
870 /*
871 * Validate also for namespace decls, they are attributes from
872 * an XML-1.0 perspective
873 TODO ... doesn't map well with current API
874 if (ctxt->validate && ctxt->wellFormed &&
875 ctxt->myDoc && ctxt->myDoc->intSubset)
876 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
877 ctxt->node, ret, value);
878 */
879 /* a standard namespace definition */
880 xmlNewNs(ctxt->node, value, name);
881 xmlFree(ns);
882 if (name != NULL)
883 xmlFree(name);
884 if (nval != NULL)
885 xmlFree(nval);
886 return;
887 }
888
889 if (ns != NULL)
890 namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
891 else {
892 namespace = NULL;
893 }
894
895 /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */
896 ret = xmlNewNsProp(ctxt->node, namespace, name, NULL);
897
898 if (ret != NULL) {
899 if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
900 xmlNodePtr tmp;
901
902 ret->children = xmlStringGetNodeList(ctxt->myDoc, value);
903 tmp = ret->children;
904 while (tmp != NULL) {
905 tmp->parent = (xmlNodePtr) ret;
906 if (tmp->next == NULL)
907 ret->last = tmp;
908 tmp = tmp->next;
909 }
910 } else if (value != NULL) {
911 ret->children = xmlNewDocText(ctxt->myDoc, value);
912 ret->last = ret->children;
913 if (ret->children != NULL)
914 ret->children->parent = (xmlNodePtr) ret;
915 }
916 }
917
918 if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
919 ctxt->myDoc && ctxt->myDoc->intSubset) {
920
921 /*
922 * If we don't substitute entities, the validation should be
923 * done on a value with replaced entities anyway.
924 */
925 if (!ctxt->replaceEntities) {
926 xmlChar *val;
927
928 ctxt->depth++;
929 val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
930 0,0,0);
931 ctxt->depth--;
Daniel Veillardc7612992002-02-17 22:47:37 +0000932
Owen Taylor3473f882001-02-23 17:55:21 +0000933 if (val == NULL)
934 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
935 ctxt->myDoc, ctxt->node, ret, value);
936 else {
Daniel Veillardc7612992002-02-17 22:47:37 +0000937 xmlChar *nvalnorm;
938
939 /*
940 * Do the last stage of the attribute normalization
941 * It need to be done twice ... it's an extra burden related
942 * to the ability to keep references in attributes
943 */
944 nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc,
945 ctxt->node, fullname, val);
946 if (nvalnorm != NULL) {
947 xmlFree(val);
948 val = nvalnorm;
949 }
950
Owen Taylor3473f882001-02-23 17:55:21 +0000951 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
952 ctxt->myDoc, ctxt->node, ret, val);
953 xmlFree(val);
954 }
955 } else {
956 ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
957 ctxt->node, ret, value);
958 }
Daniel Veillard62f313b2001-07-04 19:49:14 +0000959 } else if (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
960 ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0))) {
Owen Taylor3473f882001-02-23 17:55:21 +0000961 /*
962 * when validating, the ID registration is done at the attribute
963 * validation level. Otherwise we have to do specific handling here.
964 */
965 if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
966 xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
967 else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
968 xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
969 }
970
971 if (nval != NULL)
972 xmlFree(nval);
973 if (name != NULL)
974 xmlFree(name);
975 if (ns != NULL)
976 xmlFree(ns);
977}
978
979/**
980 * startElement:
981 * @ctx: the user data (XML parser context)
982 * @fullname: The element name, including namespace prefix
983 * @atts: An array of name/value attributes pairs, NULL terminated
984 *
985 * called when an opening tag has been processed.
986 */
987void
988startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
989{
990 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
991 xmlNodePtr ret;
992 xmlNodePtr parent = ctxt->node;
993 xmlNsPtr ns;
994 xmlChar *name;
995 xmlChar *prefix;
996 const xmlChar *att;
997 const xmlChar *value;
998 int i;
999
1000#ifdef DEBUG_SAX
1001 xmlGenericError(xmlGenericErrorContext,
1002 "SAX.startElement(%s)\n", fullname);
1003#endif
1004
1005 /*
1006 * First check on validity:
1007 */
1008 if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
1009 ((ctxt->myDoc->intSubset == NULL) ||
1010 ((ctxt->myDoc->intSubset->notations == NULL) &&
1011 (ctxt->myDoc->intSubset->elements == NULL) &&
1012 (ctxt->myDoc->intSubset->attributes == NULL) &&
1013 (ctxt->myDoc->intSubset->entities == NULL)))) {
1014 if (ctxt->vctxt.error != NULL) {
1015 ctxt->vctxt.error(ctxt->vctxt.userData,
1016 "Validation failed: no DTD found !\n");
1017 }
1018 ctxt->validate = 0;
Daniel Veillard7a51d6d2001-09-10 14:40:43 +00001019 ctxt->valid = 0;
1020 ctxt->errNo = XML_ERR_NO_DTD;
Owen Taylor3473f882001-02-23 17:55:21 +00001021 }
1022
1023
1024 /*
1025 * Split the full name into a namespace prefix and the tag name
1026 */
1027 name = xmlSplitQName(ctxt, fullname, &prefix);
1028
1029
1030 /*
1031 * Note : the namespace resolution is deferred until the end of the
1032 * attributes parsing, since local namespace can be defined as
1033 * an attribute at this level.
1034 */
1035 ret = xmlNewDocNode(ctxt->myDoc, NULL, name, NULL);
1036 if (ret == NULL) return;
1037 if (ctxt->myDoc->children == NULL) {
1038#ifdef DEBUG_SAX_TREE
1039 xmlGenericError(xmlGenericErrorContext, "Setting %s as root\n", name);
1040#endif
1041 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1042 } else if (parent == NULL) {
1043 parent = ctxt->myDoc->children;
1044 }
1045 ctxt->nodemem = -1;
Daniel Veillardd9bad132001-07-23 19:39:43 +00001046 if (ctxt->linenumbers) {
1047 if (ctxt->input != NULL)
1048 ret->content = (void *) (long) ctxt->input->line;
1049 }
Owen Taylor3473f882001-02-23 17:55:21 +00001050
1051 /*
1052 * We are parsing a new node.
1053 */
1054#ifdef DEBUG_SAX_TREE
1055 xmlGenericError(xmlGenericErrorContext, "pushing(%s)\n", name);
1056#endif
1057 nodePush(ctxt, ret);
1058
1059 /*
1060 * Link the child element
1061 */
1062 if (parent != NULL) {
1063 if (parent->type == XML_ELEMENT_NODE) {
1064#ifdef DEBUG_SAX_TREE
1065 xmlGenericError(xmlGenericErrorContext,
1066 "adding child %s to %s\n", name, parent->name);
1067#endif
1068 xmlAddChild(parent, ret);
1069 } else {
1070#ifdef DEBUG_SAX_TREE
1071 xmlGenericError(xmlGenericErrorContext,
1072 "adding sibling %s to ", name);
1073 xmlDebugDumpOneNode(stderr, parent, 0);
1074#endif
1075 xmlAddSibling(parent, ret);
1076 }
1077 }
1078
1079 /*
Daniel Veillard48da9102001-08-07 01:10:10 +00001080 * Insert all the defaulted attributes from the DTD especially namespaces
1081 */
1082 if ((!ctxt->html) &&
1083 ((ctxt->myDoc->intSubset != NULL) ||
1084 (ctxt->myDoc->extSubset != NULL))) {
1085 xmlElementPtr elemDecl = NULL;
1086
1087 if (prefix != NULL) {
1088 if (ctxt->myDoc->intSubset != NULL)
1089 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset,
1090 name, prefix);
1091 if ((elemDecl == NULL) && (ctxt->myDoc->extSubset != NULL))
1092 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
1093 name, prefix);
1094 } else {
1095 if (ctxt->myDoc->intSubset != NULL)
1096 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset,
1097 name, prefix);
1098 if ((elemDecl == NULL) && (ctxt->myDoc->extSubset != NULL))
1099 elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
1100 name, prefix);
1101 }
1102 if (elemDecl != NULL) {
1103 xmlAttributePtr attr = elemDecl->attributes;
1104 while (attr != NULL) {
1105 if (attr->defaultValue != NULL) {
1106 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001107 * the element should be instantiated in the tree if:
Daniel Veillard48da9102001-08-07 01:10:10 +00001108 * - this is a namespace prefix
1109 * - the user required for completion in the tree
1110 * like XSLT
1111 */
1112 if (((attr->prefix != NULL) &&
1113 (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
1114 ((attr->prefix == NULL) &&
1115 (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
1116 (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
Daniel Veillard963d2ae2002-01-20 22:08:18 +00001117 xmlChar *fulln;
Daniel Veillard48da9102001-08-07 01:10:10 +00001118
1119 if (attr->prefix != NULL) {
Daniel Veillard963d2ae2002-01-20 22:08:18 +00001120 fulln = xmlStrdup(attr->prefix);
1121 fulln = xmlStrcat(fulln, BAD_CAST ":");
1122 fulln = xmlStrcat(fulln, attr->name);
1123 } else {
1124 fulln = xmlStrdup(attr->name);
Daniel Veillard48da9102001-08-07 01:10:10 +00001125 }
1126
1127 /*
1128 * Check that the attribute is not declared in the
1129 * serialization
1130 */
1131 att = NULL;
1132 if (atts != NULL) {
1133 i = 0;
1134 att = atts[i];
1135 while (att != NULL) {
1136 if (xmlStrEqual(att, fulln))
1137 break;
1138 i += 2;
1139 att = atts[i];
1140 }
1141 }
1142 if (att == NULL)
1143 attribute(ctxt, fulln, attr->defaultValue);
Daniel Veillard963d2ae2002-01-20 22:08:18 +00001144 xmlFree(fulln);
Daniel Veillard48da9102001-08-07 01:10:10 +00001145 }
1146 }
1147 attr = attr->nexth;
1148 }
1149 }
1150 }
1151
1152 /*
Owen Taylor3473f882001-02-23 17:55:21 +00001153 * process all the attributes whose name start with "xml"
1154 */
1155 if (atts != NULL) {
1156 i = 0;
1157 att = atts[i++];
1158 value = atts[i++];
1159 if (!ctxt->html) {
1160 while ((att != NULL) && (value != NULL)) {
1161 if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l'))
1162 attribute(ctxt, att, value);
1163
1164 att = atts[i++];
1165 value = atts[i++];
1166 }
1167 }
1168 }
1169
1170 /*
1171 * Search the namespace, note that since the attributes have been
1172 * processed, the local namespaces are available.
1173 */
1174 ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
1175 if ((ns == NULL) && (parent != NULL))
1176 ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
1177 if ((prefix != NULL) && (ns == NULL)) {
1178 ns = xmlNewNs(ret, NULL, prefix);
1179 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
1180 ctxt->sax->warning(ctxt->userData,
1181 "Namespace prefix %s is not defined\n", prefix);
1182 }
Daniel Veillard143b04f2001-09-10 18:14:14 +00001183
1184 /*
1185 * set the namespace node, making sure that if the default namspace
1186 * is unbound on a parent we simply kee it NULL
1187 */
Daniel Veillard651f9472001-10-04 14:51:06 +00001188 if ((ns != NULL) && (ns->href != NULL) && (ns->href[0] != 0))
Daniel Veillard143b04f2001-09-10 18:14:14 +00001189 xmlSetNs(ret, ns);
Owen Taylor3473f882001-02-23 17:55:21 +00001190
1191 /*
1192 * process all the other attributes
1193 */
1194 if (atts != NULL) {
1195 i = 0;
1196 att = atts[i++];
1197 value = atts[i++];
1198 if (ctxt->html) {
1199 while (att != NULL) {
1200 attribute(ctxt, att, value);
1201 att = atts[i++];
1202 value = atts[i++];
1203 }
1204 } else {
1205 while ((att != NULL) && (value != NULL)) {
1206 if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l'))
1207 attribute(ctxt, att, value);
1208
1209 /*
1210 * Next ones
1211 */
1212 att = atts[i++];
1213 value = atts[i++];
1214 }
1215 }
1216 }
1217
1218 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001219 * If it's the Document root, finish the DTD validation and
Owen Taylor3473f882001-02-23 17:55:21 +00001220 * check the document root element for validity
1221 */
1222 if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) {
1223 ctxt->valid &= xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
1224 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
1225 ctxt->vctxt.finishDtd = 1;
1226 }
1227
1228 if (prefix != NULL)
1229 xmlFree(prefix);
1230 if (name != NULL)
1231 xmlFree(name);
1232
1233}
1234
1235/**
1236 * endElement:
1237 * @ctx: the user data (XML parser context)
1238 * @name: The element name
1239 *
1240 * called when the end of an element has been detected.
1241 */
1242void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +00001243endElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +00001244{
1245 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1246 xmlParserNodeInfo node_info;
1247 xmlNodePtr cur = ctxt->node;
1248
1249#ifdef DEBUG_SAX
1250 if (name == NULL)
1251 xmlGenericError(xmlGenericErrorContext, "SAX.endElement(NULL)\n");
1252 else
1253 xmlGenericError(xmlGenericErrorContext, "SAX.endElement(%s)\n", name);
1254#endif
1255
1256 /* Capture end position and add node */
1257 if (cur != NULL && ctxt->record_info) {
1258 node_info.end_pos = ctxt->input->cur - ctxt->input->base;
1259 node_info.end_line = ctxt->input->line;
1260 node_info.node = cur;
1261 xmlParserAddNodeInfo(ctxt, &node_info);
1262 }
1263 ctxt->nodemem = -1;
1264
1265 if (ctxt->validate && ctxt->wellFormed &&
1266 ctxt->myDoc && ctxt->myDoc->intSubset)
1267 ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
1268 cur);
1269
1270
1271 /*
1272 * end of parsing of this node.
1273 */
1274#ifdef DEBUG_SAX_TREE
1275 xmlGenericError(xmlGenericErrorContext, "popping(%s)\n", cur->name);
1276#endif
1277 nodePop(ctxt);
1278}
1279
1280/**
1281 * reference:
1282 * @ctx: the user data (XML parser context)
1283 * @name: The entity name
1284 *
1285 * called when an entity reference is detected.
1286 */
1287void
1288reference(void *ctx, const xmlChar *name)
1289{
1290 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1291 xmlNodePtr ret;
1292
1293#ifdef DEBUG_SAX
1294 xmlGenericError(xmlGenericErrorContext,
1295 "SAX.reference(%s)\n", name);
1296#endif
1297 if (name[0] == '#')
1298 ret = xmlNewCharRef(ctxt->myDoc, name);
1299 else
1300 ret = xmlNewReference(ctxt->myDoc, name);
1301#ifdef DEBUG_SAX_TREE
1302 xmlGenericError(xmlGenericErrorContext,
1303 "add reference %s to %s \n", name, ctxt->node->name);
1304#endif
1305 xmlAddChild(ctxt->node, ret);
1306}
1307
1308/**
1309 * characters:
1310 * @ctx: the user data (XML parser context)
1311 * @ch: a xmlChar string
1312 * @len: the number of xmlChar
1313 *
1314 * receiving some chars from the parser.
Owen Taylor3473f882001-02-23 17:55:21 +00001315 */
1316void
1317characters(void *ctx, const xmlChar *ch, int len)
1318{
1319 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1320 xmlNodePtr lastChild;
1321
1322#ifdef DEBUG_SAX
1323 xmlGenericError(xmlGenericErrorContext,
1324 "SAX.characters(%.30s, %d)\n", ch, len);
1325#endif
1326 /*
1327 * Handle the data if any. If there is no child
1328 * add it as content, otherwise if the last child is text,
1329 * concatenate it, else create a new node of type text.
1330 */
1331
1332 if (ctxt->node == NULL) {
1333#ifdef DEBUG_SAX_TREE
1334 xmlGenericError(xmlGenericErrorContext,
1335 "add chars: ctxt->node == NULL !\n");
1336#endif
1337 return;
1338 }
1339 lastChild = xmlGetLastChild(ctxt->node);
1340#ifdef DEBUG_SAX_TREE
1341 xmlGenericError(xmlGenericErrorContext,
1342 "add chars to %s \n", ctxt->node->name);
1343#endif
1344
1345 /*
1346 * Here we needed an accelerator mechanism in case of very large
1347 * elements. Use an attribute in the structure !!!
1348 */
1349 if (lastChild == NULL) {
1350 /* first node, first time */
1351 xmlNodeAddContentLen(ctxt->node, ch, len);
1352#ifndef XML_USE_BUFFER_CONTENT
1353 if (ctxt->node->children != NULL) {
1354 ctxt->nodelen = len;
1355 ctxt->nodemem = len + 1;
1356 }
1357#endif
1358 } else {
Daniel Veillardf300b7e2001-08-13 10:43:15 +00001359 int coalesceText = (lastChild != NULL) &&
1360 (lastChild->type == XML_TEXT_NODE) &&
1361 (lastChild->name == xmlStringText);
1362 if ((coalesceText) && (ctxt->nodemem != 0)) {
Owen Taylor3473f882001-02-23 17:55:21 +00001363#ifndef XML_USE_BUFFER_CONTENT
1364 /*
1365 * The whole point of maintaining nodelen and nodemem,
Daniel Veillard60087f32001-10-10 09:45:09 +00001366 * xmlTextConcat is too costly, i.e. compute length,
Owen Taylor3473f882001-02-23 17:55:21 +00001367 * reallocate a new buffer, move data, append ch. Here
1368 * We try to minimaze realloc() uses and avoid copying
Daniel Veillard60087f32001-10-10 09:45:09 +00001369 * and recomputing length over and over.
Owen Taylor3473f882001-02-23 17:55:21 +00001370 */
1371 if (ctxt->nodelen + len >= ctxt->nodemem) {
1372 xmlChar *newbuf;
1373 int size;
1374
1375 size = ctxt->nodemem + len;
1376 size *= 2;
1377 newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
1378 if (newbuf == NULL) {
1379 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1380 ctxt->sax->error(ctxt->userData,
1381 "SAX.characters(): out of memory\n");
1382 return;
1383 }
1384 ctxt->nodemem = size;
1385 lastChild->content = newbuf;
1386 }
1387 memcpy(&lastChild->content[ctxt->nodelen], ch, len);
1388 ctxt->nodelen += len;
1389 lastChild->content[ctxt->nodelen] = 0;
1390#else
1391 xmlTextConcat(lastChild, ch, len);
1392#endif
Daniel Veillardf300b7e2001-08-13 10:43:15 +00001393 } else if (coalesceText) {
Daniel Veillard80f32572001-03-07 19:45:40 +00001394 xmlTextConcat(lastChild, ch, len);
1395 if (ctxt->node->children != NULL) {
1396 ctxt->nodelen = xmlStrlen(lastChild->content);
1397 ctxt->nodemem = ctxt->nodelen + 1;
1398 }
Owen Taylor3473f882001-02-23 17:55:21 +00001399 } else {
1400 /* Mixed content, first time */
1401 lastChild = xmlNewTextLen(ch, len);
1402 xmlAddChild(ctxt->node, lastChild);
1403#ifndef XML_USE_BUFFER_CONTENT
1404 if (ctxt->node->children != NULL) {
1405 ctxt->nodelen = len;
1406 ctxt->nodemem = len + 1;
1407 }
1408#endif
1409 }
1410 }
1411}
1412
1413/**
1414 * ignorableWhitespace:
1415 * @ctx: the user data (XML parser context)
1416 * @ch: a xmlChar string
1417 * @len: the number of xmlChar
1418 *
1419 * receiving some ignorable whitespaces from the parser.
Daniel Veillard05c13a22001-09-09 08:38:09 +00001420 * UNUSED: by default the DOM building will use characters
Owen Taylor3473f882001-02-23 17:55:21 +00001421 */
1422void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +00001423ignorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
Owen Taylor3473f882001-02-23 17:55:21 +00001424{
1425 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
1426#ifdef DEBUG_SAX
1427 xmlGenericError(xmlGenericErrorContext,
1428 "SAX.ignorableWhitespace(%.30s, %d)\n", ch, len);
1429#endif
1430}
1431
1432/**
1433 * processingInstruction:
1434 * @ctx: the user data (XML parser context)
1435 * @target: the target name
1436 * @data: the PI data's
1437 *
1438 * A processing instruction has been parsed.
1439 */
1440void
1441processingInstruction(void *ctx, const xmlChar *target,
1442 const xmlChar *data)
1443{
1444 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1445 xmlNodePtr ret;
1446 xmlNodePtr parent = ctxt->node;
1447
1448#ifdef DEBUG_SAX
1449 xmlGenericError(xmlGenericErrorContext,
1450 "SAX.processingInstruction(%s, %s)\n", target, data);
1451#endif
1452
1453 ret = xmlNewPI(target, data);
1454 if (ret == NULL) return;
1455 parent = ctxt->node;
1456
1457 if (ctxt->inSubset == 1) {
1458 xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
1459 return;
1460 } else if (ctxt->inSubset == 2) {
1461 xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
1462 return;
1463 }
1464 if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
1465#ifdef DEBUG_SAX_TREE
1466 xmlGenericError(xmlGenericErrorContext,
1467 "Setting PI %s as root\n", target);
1468#endif
1469 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1470 return;
1471 }
1472 if (parent->type == XML_ELEMENT_NODE) {
1473#ifdef DEBUG_SAX_TREE
1474 xmlGenericError(xmlGenericErrorContext,
1475 "adding PI %s child to %s\n", target, parent->name);
1476#endif
1477 xmlAddChild(parent, ret);
1478 } else {
1479#ifdef DEBUG_SAX_TREE
1480 xmlGenericError(xmlGenericErrorContext,
1481 "adding PI %s sibling to ", target);
1482 xmlDebugDumpOneNode(stderr, parent, 0);
1483#endif
1484 xmlAddSibling(parent, ret);
1485 }
1486}
1487
1488/**
1489 * globalNamespace:
1490 * @ctx: the user data (XML parser context)
1491 * @href: the namespace associated URN
1492 * @prefix: the namespace prefix
1493 *
1494 * An old global namespace has been parsed.
1495 */
1496void
1497globalNamespace(void *ctx, const xmlChar *href, const xmlChar *prefix)
1498{
1499 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1500#ifdef DEBUG_SAX
1501 xmlGenericError(xmlGenericErrorContext,
1502 "SAX.globalNamespace(%s, %s)\n", href, prefix);
1503#endif
1504 xmlNewGlobalNs(ctxt->myDoc, href, prefix);
1505}
1506
1507/**
1508 * setNamespace:
1509 * @ctx: the user data (XML parser context)
1510 * @name: the namespace prefix
1511 *
1512 * Set the current element namespace.
1513 */
1514
1515void
1516setNamespace(void *ctx, const xmlChar *name)
1517{
1518 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1519 xmlNsPtr ns;
1520 xmlNodePtr parent;
1521
1522#ifdef DEBUG_SAX
1523 xmlGenericError(xmlGenericErrorContext, "SAX.setNamespace(%s)\n", name);
1524#endif
1525 ns = xmlSearchNs(ctxt->myDoc, ctxt->node, name);
1526 if (ns == NULL) { /* ctxt->node may not have a parent yet ! */
1527 if (ctxt->nodeNr >= 2) {
1528 parent = ctxt->nodeTab[ctxt->nodeNr - 2];
1529 if (parent != NULL)
1530 ns = xmlSearchNs(ctxt->myDoc, parent, name);
1531 }
1532 }
1533 xmlSetNs(ctxt->node, ns);
1534}
1535
1536/**
1537 * getNamespace:
1538 * @ctx: the user data (XML parser context)
1539 *
1540 * Get the current element namespace.
1541 *
1542 * Returns the xmlNsPtr or NULL if none
1543 */
1544
1545xmlNsPtr
1546getNamespace(void *ctx)
1547{
1548 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1549 xmlNsPtr ret;
1550
1551#ifdef DEBUG_SAX
1552 xmlGenericError(xmlGenericErrorContext, "SAX.getNamespace()\n");
1553#endif
1554 ret = ctxt->node->ns;
1555 return(ret);
1556}
1557
1558/**
1559 * checkNamespace:
1560 * @ctx: the user data (XML parser context)
1561 * @namespace: the namespace to check against
1562 *
1563 * Check that the current element namespace is the same as the
1564 * one read upon parsing.
1565 *
1566 * Returns 1 if true 0 otherwise
1567 */
1568
1569int
1570checkNamespace(void *ctx, xmlChar *namespace)
1571{
1572 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1573 xmlNodePtr cur = ctxt->node;
1574
1575#ifdef DEBUG_SAX
1576 xmlGenericError(xmlGenericErrorContext,
1577 "SAX.checkNamespace(%s)\n", namespace);
1578#endif
1579
1580 /*
1581 * Check that the Name in the ETag is the same as in the STag.
1582 */
1583 if (namespace == NULL) {
1584 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
1585 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1586 ctxt->sax->error(ctxt,
1587 "End tags for %s don't hold the namespace %s\n",
1588 cur->name, cur->ns->prefix);
1589 ctxt->wellFormed = 0;
1590 }
1591 } else {
1592 if ((cur->ns == NULL) || (cur->ns->prefix == NULL)) {
1593 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1594 ctxt->sax->error(ctxt,
1595 "End tags %s holds a prefix %s not used by the open tag\n",
1596 cur->name, namespace);
1597 ctxt->wellFormed = 0;
1598 } else if (!xmlStrEqual(namespace, cur->ns->prefix)) {
1599 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
1600 ctxt->sax->error(ctxt,
1601 "Start and End tags for %s don't use the same namespaces: %s and %s\n",
1602 cur->name, cur->ns->prefix, namespace);
1603 ctxt->wellFormed = 0;
1604 } else
1605 return(1);
1606 }
1607 return(0);
1608}
1609
1610/**
1611 * namespaceDecl:
1612 * @ctx: the user data (XML parser context)
1613 * @href: the namespace associated URN
1614 * @prefix: the namespace prefix
1615 *
1616 * A namespace has been parsed.
1617 */
1618void
1619namespaceDecl(void *ctx, const xmlChar *href, const xmlChar *prefix)
1620{
1621 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1622#ifdef DEBUG_SAX
1623 if (prefix == NULL)
1624 xmlGenericError(xmlGenericErrorContext,
1625 "SAX.namespaceDecl(%s, NULL)\n", href);
1626 else
1627 xmlGenericError(xmlGenericErrorContext,
1628 "SAX.namespaceDecl(%s, %s)\n", href, prefix);
1629#endif
1630 xmlNewNs(ctxt->node, href, prefix);
1631}
1632
1633/**
1634 * comment:
1635 * @ctx: the user data (XML parser context)
1636 * @value: the comment content
1637 *
1638 * A comment has been parsed.
1639 */
1640void
1641comment(void *ctx, const xmlChar *value)
1642{
1643 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1644 xmlNodePtr ret;
1645 xmlNodePtr parent = ctxt->node;
1646
1647#ifdef DEBUG_SAX
1648 xmlGenericError(xmlGenericErrorContext, "SAX.comment(%s)\n", value);
1649#endif
1650 ret = xmlNewDocComment(ctxt->myDoc, value);
1651 if (ret == NULL) return;
1652
1653 if (ctxt->inSubset == 1) {
1654 xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
1655 return;
1656 } else if (ctxt->inSubset == 2) {
1657 xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
1658 return;
1659 }
1660 if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
1661#ifdef DEBUG_SAX_TREE
1662 xmlGenericError(xmlGenericErrorContext,
1663 "Setting comment as root\n");
1664#endif
1665 xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
1666 return;
1667 }
1668 if (parent->type == XML_ELEMENT_NODE) {
1669#ifdef DEBUG_SAX_TREE
1670 xmlGenericError(xmlGenericErrorContext,
1671 "adding comment child to %s\n", parent->name);
1672#endif
1673 xmlAddChild(parent, ret);
1674 } else {
1675#ifdef DEBUG_SAX_TREE
1676 xmlGenericError(xmlGenericErrorContext,
1677 "adding comment sibling to ");
1678 xmlDebugDumpOneNode(stderr, parent, 0);
1679#endif
1680 xmlAddSibling(parent, ret);
1681 }
1682}
1683
1684/**
1685 * cdataBlock:
1686 * @ctx: the user data (XML parser context)
1687 * @value: The pcdata content
1688 * @len: the block length
1689 *
1690 * called when a pcdata block has been parsed
1691 */
1692void
1693cdataBlock(void *ctx, const xmlChar *value, int len)
1694{
1695 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1696 xmlNodePtr ret, lastChild;
1697
1698#ifdef DEBUG_SAX
1699 xmlGenericError(xmlGenericErrorContext,
1700 "SAX.pcdata(%.10s, %d)\n", value, len);
1701#endif
1702 lastChild = xmlGetLastChild(ctxt->node);
1703#ifdef DEBUG_SAX_TREE
1704 xmlGenericError(xmlGenericErrorContext,
1705 "add chars to %s \n", ctxt->node->name);
1706#endif
1707 if ((lastChild != NULL) &&
1708 (lastChild->type == XML_CDATA_SECTION_NODE)) {
1709 xmlTextConcat(lastChild, value, len);
1710 } else {
1711 ret = xmlNewCDataBlock(ctxt->myDoc, value, len);
1712 xmlAddChild(ctxt->node, ret);
1713 }
1714}
1715
Daniel Veillardd0463562001-10-13 09:15:48 +00001716/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001717 * initxmlDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001718 * @hdlr: the SAX handler
1719 * @warning: flag if non-zero sets the handler warning procedure
Daniel Veillardd0463562001-10-13 09:15:48 +00001720 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001721 * Initialize the default XML SAX handler
Owen Taylor3473f882001-02-23 17:55:21 +00001722 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001723void
1724initxmlDefaultSAXHandler(xmlSAXHandler *hdlr, int warning)
1725{
1726 if(hdlr->initialized == 1)
1727 return;
1728
1729 hdlr->internalSubset = internalSubset;
1730 hdlr->externalSubset = externalSubset;
1731 hdlr->isStandalone = isStandalone;
1732 hdlr->hasInternalSubset = hasInternalSubset;
1733 hdlr->hasExternalSubset = hasExternalSubset;
1734 hdlr->resolveEntity = resolveEntity;
1735 hdlr->getEntity = getEntity;
1736 hdlr->getParameterEntity = getParameterEntity;
1737 hdlr->entityDecl = entityDecl;
1738 hdlr->attributeDecl = attributeDecl;
1739 hdlr->elementDecl = elementDecl;
1740 hdlr->notationDecl = notationDecl;
1741 hdlr->unparsedEntityDecl = unparsedEntityDecl;
1742 hdlr->setDocumentLocator = setDocumentLocator;
1743 hdlr->startDocument = startDocument;
1744 hdlr->endDocument = endDocument;
1745 hdlr->startElement = startElement;
1746 hdlr->endElement = endElement;
1747 hdlr->reference = reference;
1748 hdlr->characters = characters;
1749 hdlr->cdataBlock = cdataBlock;
1750 hdlr->ignorableWhitespace = characters;
1751 hdlr->processingInstruction = processingInstruction;
1752 hdlr->comment = comment;
1753 /* if (xmlGetWarningsDefaultValue == 0) */
1754 if (warning == 0)
1755 hdlr->warning = NULL;
1756 else
1757 hdlr->warning = xmlParserWarning;
1758 hdlr->error = xmlParserError;
1759 hdlr->fatalError = xmlParserError;
1760
1761 hdlr->initialized = 1;
1762}
Owen Taylor3473f882001-02-23 17:55:21 +00001763
1764/**
1765 * xmlDefaultSAXHandlerInit:
1766 *
1767 * Initialize the default SAX handler
1768 */
1769void
1770xmlDefaultSAXHandlerInit(void)
1771{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +00001772 initxmlDefaultSAXHandler(&xmlDefaultSAXHandler, xmlGetWarningsDefaultValue);
Owen Taylor3473f882001-02-23 17:55:21 +00001773}
1774
Daniel Veillardeae522a2001-04-23 13:41:34 +00001775#ifdef LIBXML_HTML_ENABLED
Daniel Veillardd0463562001-10-13 09:15:48 +00001776
1777/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001778 * inithtmlDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001779 * @hdlr: the SAX handler
Daniel Veillardd0463562001-10-13 09:15:48 +00001780 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001781 * Initialize the default HTML SAX handler
Owen Taylor3473f882001-02-23 17:55:21 +00001782 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001783void
1784inithtmlDefaultSAXHandler(xmlSAXHandler *hdlr)
1785{
1786 if(hdlr->initialized == 1)
1787 return;
1788
1789 hdlr->internalSubset = internalSubset;
1790 hdlr->externalSubset = NULL;
1791 hdlr->isStandalone = NULL;
1792 hdlr->hasInternalSubset = NULL;
1793 hdlr->hasExternalSubset = NULL;
1794 hdlr->resolveEntity = NULL;
1795 hdlr->getEntity = getEntity;
1796 hdlr->getParameterEntity = NULL;
1797 hdlr->entityDecl = NULL;
1798 hdlr->attributeDecl = NULL;
1799 hdlr->elementDecl = NULL;
1800 hdlr->notationDecl = NULL;
1801 hdlr->unparsedEntityDecl = NULL;
1802 hdlr->setDocumentLocator = setDocumentLocator;
1803 hdlr->startDocument = startDocument;
1804 hdlr->endDocument = endDocument;
1805 hdlr->startElement = startElement;
1806 hdlr->endElement = endElement;
1807 hdlr->reference = NULL;
1808 hdlr->characters = characters;
1809 hdlr->cdataBlock = cdataBlock;
1810 hdlr->ignorableWhitespace = ignorableWhitespace;
1811 hdlr->processingInstruction = NULL;
1812 hdlr->comment = comment;
1813 hdlr->warning = xmlParserWarning;
1814 hdlr->error = xmlParserError;
1815 hdlr->fatalError = xmlParserError;
1816
1817 hdlr->initialized = 1;
1818}
Owen Taylor3473f882001-02-23 17:55:21 +00001819
1820/**
1821 * htmlDefaultSAXHandlerInit:
1822 *
1823 * Initialize the default SAX handler
1824 */
1825void
1826htmlDefaultSAXHandlerInit(void)
1827{
Daniel Veillardd0463562001-10-13 09:15:48 +00001828 inithtmlDefaultSAXHandler(&htmlDefaultSAXHandler);
Owen Taylor3473f882001-02-23 17:55:21 +00001829}
Daniel Veillardd0463562001-10-13 09:15:48 +00001830
Daniel Veillardeae522a2001-04-23 13:41:34 +00001831#endif /* LIBXML_HTML_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +00001832
Daniel Veillardeae522a2001-04-23 13:41:34 +00001833#ifdef LIBXML_DOCB_ENABLED
Daniel Veillardd0463562001-10-13 09:15:48 +00001834
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001835/**
Daniel Veillard9d06d302002-01-22 18:15:52 +00001836 * initdocbDefaultSAXHandler:
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001837 * @hdlr: the SAX handler
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001838 *
1839 * Initialize the default DocBook SAX handler
1840 */
Daniel Veillardd0463562001-10-13 09:15:48 +00001841void
1842initdocbDefaultSAXHandler(xmlSAXHandler *hdlr)
1843{
1844 if(hdlr->initialized == 1)
1845 return;
1846
1847 hdlr->internalSubset = internalSubset;
1848 hdlr->externalSubset = NULL;
1849 hdlr->isStandalone = isStandalone;
1850 hdlr->hasInternalSubset = hasInternalSubset;
1851 hdlr->hasExternalSubset = hasExternalSubset;
1852 hdlr->resolveEntity = resolveEntity;
1853 hdlr->getEntity = getEntity;
1854 hdlr->getParameterEntity = NULL;
1855 hdlr->entityDecl = entityDecl;
1856 hdlr->attributeDecl = NULL;
1857 hdlr->elementDecl = NULL;
1858 hdlr->notationDecl = NULL;
1859 hdlr->unparsedEntityDecl = NULL;
1860 hdlr->setDocumentLocator = setDocumentLocator;
1861 hdlr->startDocument = startDocument;
1862 hdlr->endDocument = endDocument;
1863 hdlr->startElement = startElement;
1864 hdlr->endElement = endElement;
1865 hdlr->reference = reference;
1866 hdlr->characters = characters;
1867 hdlr->cdataBlock = NULL;
1868 hdlr->ignorableWhitespace = ignorableWhitespace;
1869 hdlr->processingInstruction = NULL;
1870 hdlr->comment = comment;
1871 hdlr->warning = xmlParserWarning;
1872 hdlr->error = xmlParserError;
1873 hdlr->fatalError = xmlParserError;
1874
1875 hdlr->initialized = 1;
1876}
Owen Taylor3473f882001-02-23 17:55:21 +00001877
1878/**
Daniel Veillardeae522a2001-04-23 13:41:34 +00001879 * docbDefaultSAXHandlerInit:
Owen Taylor3473f882001-02-23 17:55:21 +00001880 *
1881 * Initialize the default SAX handler
1882 */
1883void
Daniel Veillardeae522a2001-04-23 13:41:34 +00001884docbDefaultSAXHandlerInit(void)
Owen Taylor3473f882001-02-23 17:55:21 +00001885{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +00001886 initdocbDefaultSAXHandler(&docbDefaultSAXHandler);
Owen Taylor3473f882001-02-23 17:55:21 +00001887}
Daniel Veillardeae522a2001-04-23 13:41:34 +00001888
1889#endif /* LIBXML_DOCB_ENABLED */