2 * SAX2.c : Default SAX2 handler to build a tree.
4 * See Copyright for the status of this software.
6 * Daniel Veillard <daniel@veillard.com>
16 #include <libxml/xmlmemory.h>
17 #include <libxml/tree.h>
18 #include <libxml/parser.h>
19 #include <libxml/parserInternals.h>
20 #include <libxml/valid.h>
21 #include <libxml/entities.h>
22 #include <libxml/xmlerror.h>
23 #include <libxml/debugXML.h>
24 #include <libxml/xmlIO.h>
25 #include <libxml/SAX.h>
26 #include <libxml/uri.h>
27 #include <libxml/valid.h>
28 #include <libxml/HTMLtree.h>
29 #include <libxml/globals.h>
31 /* Define SIZE_T_MAX unless defined through <limits.h>. */
33 # define SIZE_T_MAX ((size_t)-1)
34 #endif /* !SIZE_T_MAX */
36 /* #define DEBUG_SAX2 */
37 /* #define DEBUG_SAX2_TREE */
42 * macro to flag unimplemented blocks
43 * XML_CATALOG_PREFER user env to select between system/public preferred
44 * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk>
45 *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with
46 *> values "system" and "public". I have made the default be "system" to
50 xmlGenericError(xmlGenericErrorContext, \
51 "Unimplemented block at %s:%d\n", \
56 * @ctxt: an XML validation parser context
57 * @msg: a string to accompany the error message
59 static void LIBXML_ATTR_FORMAT(2,0)
60 xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt
, const char *msg
) {
61 xmlStructuredErrorFunc schannel
= NULL
;
62 const char *str1
= "out of memory\n";
65 ctxt
->errNo
= XML_ERR_NO_MEMORY
;
66 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->initialized
== XML_SAX2_MAGIC
))
67 schannel
= ctxt
->sax
->serror
;
68 __xmlRaiseError(schannel
,
69 ctxt
->vctxt
.error
, ctxt
->vctxt
.userData
,
70 ctxt
, NULL
, XML_FROM_PARSER
, XML_ERR_NO_MEMORY
,
71 XML_ERR_ERROR
, NULL
, 0, (const char *) str1
,
73 msg
, (const char *) str1
, NULL
);
74 ctxt
->errNo
= XML_ERR_NO_MEMORY
;
75 ctxt
->instate
= XML_PARSER_EOF
;
78 __xmlRaiseError(schannel
,
80 ctxt
, NULL
, XML_FROM_PARSER
, XML_ERR_NO_MEMORY
,
81 XML_ERR_ERROR
, NULL
, 0, (const char *) str1
,
83 msg
, (const char *) str1
, NULL
);
89 * @ctxt: an XML validation parser context
90 * @error: the error number
91 * @msg: the error message
95 * Handle a validation error
97 static void LIBXML_ATTR_FORMAT(3,0)
98 xmlErrValid(xmlParserCtxtPtr ctxt
, xmlParserErrors error
,
99 const char *msg
, const char *str1
, const char *str2
)
101 xmlStructuredErrorFunc schannel
= NULL
;
103 if ((ctxt
!= NULL
) && (ctxt
->disableSAX
!= 0) &&
104 (ctxt
->instate
== XML_PARSER_EOF
))
108 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->initialized
== XML_SAX2_MAGIC
))
109 schannel
= ctxt
->sax
->serror
;
110 __xmlRaiseError(schannel
,
111 ctxt
->vctxt
.error
, ctxt
->vctxt
.userData
,
112 ctxt
, NULL
, XML_FROM_DTD
, error
,
113 XML_ERR_ERROR
, NULL
, 0, (const char *) str1
,
114 (const char *) str2
, NULL
, 0, 0,
115 msg
, (const char *) str1
, (const char *) str2
);
118 __xmlRaiseError(schannel
,
120 ctxt
, NULL
, XML_FROM_DTD
, error
,
121 XML_ERR_ERROR
, NULL
, 0, (const char *) str1
,
122 (const char *) str2
, NULL
, 0, 0,
123 msg
, (const char *) str1
, (const char *) str2
);
129 * @ctxt: an XML parser context
130 * @error: the error number
131 * @msg: the error message
132 * @str1: an error string
133 * @str2: an error string
135 * Handle a fatal parser error, i.e. violating Well-Formedness constraints
137 static void LIBXML_ATTR_FORMAT(3,0)
138 xmlFatalErrMsg(xmlParserCtxtPtr ctxt
, xmlParserErrors error
,
139 const char *msg
, const xmlChar
*str1
, const xmlChar
*str2
)
141 if ((ctxt
!= NULL
) && (ctxt
->disableSAX
!= 0) &&
142 (ctxt
->instate
== XML_PARSER_EOF
))
146 __xmlRaiseError(NULL
, NULL
, NULL
, ctxt
, NULL
, XML_FROM_PARSER
, error
,
147 XML_ERR_FATAL
, NULL
, 0,
148 (const char *) str1
, (const char *) str2
,
149 NULL
, 0, 0, msg
, str1
, str2
);
151 ctxt
->wellFormed
= 0;
153 if (ctxt
->recovery
== 0)
154 ctxt
->disableSAX
= 1;
160 * @ctxt: an XML parser context
161 * @error: the error number
162 * @msg: the error message
163 * @str1: an error string
164 * @str2: an error string
166 * Handle a parser warning
168 static void LIBXML_ATTR_FORMAT(3,0)
169 xmlWarnMsg(xmlParserCtxtPtr ctxt
, xmlParserErrors error
,
170 const char *msg
, const xmlChar
*str1
)
172 if ((ctxt
!= NULL
) && (ctxt
->disableSAX
!= 0) &&
173 (ctxt
->instate
== XML_PARSER_EOF
))
177 __xmlRaiseError(NULL
, NULL
, NULL
, ctxt
, NULL
, XML_FROM_PARSER
, error
,
178 XML_ERR_WARNING
, NULL
, 0,
179 (const char *) str1
, NULL
,
180 NULL
, 0, 0, msg
, str1
);
185 * @ctxt: an XML parser context
186 * @error: the error number
187 * @msg: the error message
188 * @str1: an error string
189 * @str2: an error string
191 * Handle a namespace error
193 static void LIBXML_ATTR_FORMAT(3,0)
194 xmlNsErrMsg(xmlParserCtxtPtr ctxt
, xmlParserErrors error
,
195 const char *msg
, const xmlChar
*str1
, const xmlChar
*str2
)
197 if ((ctxt
!= NULL
) && (ctxt
->disableSAX
!= 0) &&
198 (ctxt
->instate
== XML_PARSER_EOF
))
202 __xmlRaiseError(NULL
, NULL
, NULL
, ctxt
, NULL
, XML_FROM_NAMESPACE
, error
,
203 XML_ERR_ERROR
, NULL
, 0,
204 (const char *) str1
, (const char *) str2
,
205 NULL
, 0, 0, msg
, str1
, str2
);
210 * @ctxt: an XML parser context
211 * @error: the error number
212 * @msg: the error message
213 * @str1: an error string
215 * Handle a namespace warning
217 static void LIBXML_ATTR_FORMAT(3,0)
218 xmlNsWarnMsg(xmlParserCtxtPtr ctxt
, xmlParserErrors error
,
219 const char *msg
, const xmlChar
*str1
, const xmlChar
*str2
)
221 if ((ctxt
!= NULL
) && (ctxt
->disableSAX
!= 0) &&
222 (ctxt
->instate
== XML_PARSER_EOF
))
226 __xmlRaiseError(NULL
, NULL
, NULL
, ctxt
, NULL
, XML_FROM_NAMESPACE
, error
,
227 XML_ERR_WARNING
, NULL
, 0,
228 (const char *) str1
, (const char *) str2
,
229 NULL
, 0, 0, msg
, str1
, str2
);
233 * xmlSAX2GetPublicId:
234 * @ctx: the user data (XML parser context)
236 * Provides the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN"
238 * Returns a xmlChar *
241 xmlSAX2GetPublicId(void *ctx ATTRIBUTE_UNUSED
)
243 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
248 * xmlSAX2GetSystemId:
249 * @ctx: the user data (XML parser context)
251 * Provides the system ID, basically URL or filename e.g.
252 * http://www.sgmlsource.com/dtds/memo.dtd
254 * Returns a xmlChar *
257 xmlSAX2GetSystemId(void *ctx
)
259 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
260 if ((ctx
== NULL
) || (ctxt
->input
== NULL
)) return(NULL
);
261 return((const xmlChar
*) ctxt
->input
->filename
);
265 * xmlSAX2GetLineNumber:
266 * @ctx: the user data (XML parser context)
268 * Provide the line number of the current parsing point.
273 xmlSAX2GetLineNumber(void *ctx
)
275 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
276 if ((ctx
== NULL
) || (ctxt
->input
== NULL
)) return(0);
277 return(ctxt
->input
->line
);
281 * xmlSAX2GetColumnNumber:
282 * @ctx: the user data (XML parser context)
284 * Provide the column number of the current parsing point.
289 xmlSAX2GetColumnNumber(void *ctx
)
291 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
292 if ((ctx
== NULL
) || (ctxt
->input
== NULL
)) return(0);
293 return(ctxt
->input
->col
);
297 * xmlSAX2IsStandalone:
298 * @ctx: the user data (XML parser context)
300 * Is this document tagged standalone ?
305 xmlSAX2IsStandalone(void *ctx
)
307 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
308 if ((ctx
== NULL
) || (ctxt
->myDoc
== NULL
)) return(0);
309 return(ctxt
->myDoc
->standalone
== 1);
313 * xmlSAX2HasInternalSubset:
314 * @ctx: the user data (XML parser context)
316 * Does this document has an internal subset
321 xmlSAX2HasInternalSubset(void *ctx
)
323 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
324 if ((ctxt
== NULL
) || (ctxt
->myDoc
== NULL
)) return(0);
325 return(ctxt
->myDoc
->intSubset
!= NULL
);
329 * xmlSAX2HasExternalSubset:
330 * @ctx: the user data (XML parser context)
332 * Does this document has an external subset
337 xmlSAX2HasExternalSubset(void *ctx
)
339 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
340 if ((ctxt
== NULL
) || (ctxt
->myDoc
== NULL
)) return(0);
341 return(ctxt
->myDoc
->extSubset
!= NULL
);
345 * xmlSAX2InternalSubset:
346 * @ctx: the user data (XML parser context)
347 * @name: the root element name
348 * @ExternalID: the external ID
349 * @SystemID: the SYSTEM ID (e.g. filename or URL)
351 * Callback on internal subset declaration.
354 xmlSAX2InternalSubset(void *ctx
, const xmlChar
*name
,
355 const xmlChar
*ExternalID
, const xmlChar
*SystemID
)
357 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
359 if (ctx
== NULL
) return;
361 xmlGenericError(xmlGenericErrorContext
,
362 "SAX.xmlSAX2InternalSubset(%s, %s, %s)\n",
363 name
, ExternalID
, SystemID
);
366 if (ctxt
->myDoc
== NULL
)
368 dtd
= xmlGetIntSubset(ctxt
->myDoc
);
372 xmlUnlinkNode((xmlNodePtr
) dtd
);
374 ctxt
->myDoc
->intSubset
= NULL
;
376 ctxt
->myDoc
->intSubset
=
377 xmlCreateIntSubset(ctxt
->myDoc
, name
, ExternalID
, SystemID
);
378 if (ctxt
->myDoc
->intSubset
== NULL
)
379 xmlSAX2ErrMemory(ctxt
, "xmlSAX2InternalSubset");
383 * xmlSAX2ExternalSubset:
384 * @ctx: the user data (XML parser context)
385 * @name: the root element name
386 * @ExternalID: the external ID
387 * @SystemID: the SYSTEM ID (e.g. filename or URL)
389 * Callback on external subset declaration.
392 xmlSAX2ExternalSubset(void *ctx
, const xmlChar
*name
,
393 const xmlChar
*ExternalID
, const xmlChar
*SystemID
)
395 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
396 if (ctx
== NULL
) return;
398 xmlGenericError(xmlGenericErrorContext
,
399 "SAX.xmlSAX2ExternalSubset(%s, %s, %s)\n",
400 name
, ExternalID
, SystemID
);
402 if (((ExternalID
!= NULL
) || (SystemID
!= NULL
)) &&
403 (((ctxt
->validate
) || (ctxt
->loadsubset
!= 0)) &&
404 (ctxt
->wellFormed
&& ctxt
->myDoc
))) {
406 * Try to fetch and parse the external subset.
408 xmlParserInputPtr oldinput
;
411 xmlParserInputPtr
*oldinputTab
;
412 xmlParserInputPtr input
= NULL
;
415 const xmlChar
*oldencoding
;
418 * Ask the Entity resolver to load the damn thing
420 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->resolveEntity
!= NULL
))
421 input
= ctxt
->sax
->resolveEntity(ctxt
->userData
, ExternalID
,
427 xmlNewDtd(ctxt
->myDoc
, name
, ExternalID
, SystemID
);
430 * make sure we won't destroy the main document context
432 oldinput
= ctxt
->input
;
433 oldinputNr
= ctxt
->inputNr
;
434 oldinputMax
= ctxt
->inputMax
;
435 oldinputTab
= ctxt
->inputTab
;
436 oldcharset
= ctxt
->charset
;
437 oldencoding
= ctxt
->encoding
;
438 ctxt
->encoding
= NULL
;
440 ctxt
->inputTab
= (xmlParserInputPtr
*)
441 xmlMalloc(5 * sizeof(xmlParserInputPtr
));
442 if (ctxt
->inputTab
== NULL
) {
443 xmlSAX2ErrMemory(ctxt
, "xmlSAX2ExternalSubset");
444 ctxt
->input
= oldinput
;
445 ctxt
->inputNr
= oldinputNr
;
446 ctxt
->inputMax
= oldinputMax
;
447 ctxt
->inputTab
= oldinputTab
;
448 ctxt
->charset
= oldcharset
;
449 ctxt
->encoding
= oldencoding
;
455 xmlPushInput(ctxt
, input
);
458 * On the fly encoding conversion if needed
460 if (ctxt
->input
->length
>= 4) {
461 enc
= xmlDetectCharEncoding(ctxt
->input
->cur
, 4);
462 xmlSwitchEncoding(ctxt
, enc
);
465 if (input
->filename
== NULL
)
466 input
->filename
= (char *) xmlCanonicPath(SystemID
);
469 input
->base
= ctxt
->input
->cur
;
470 input
->cur
= ctxt
->input
->cur
;
474 * let's parse that entity knowing it's an external subset.
476 xmlParseExternalSubset(ctxt
, ExternalID
, SystemID
);
479 * Free up the external entities
482 while (ctxt
->inputNr
> 1)
484 xmlFreeInputStream(ctxt
->input
);
485 xmlFree(ctxt
->inputTab
);
488 * Restore the parsing context of the main entity
490 ctxt
->input
= oldinput
;
491 ctxt
->inputNr
= oldinputNr
;
492 ctxt
->inputMax
= oldinputMax
;
493 ctxt
->inputTab
= oldinputTab
;
494 ctxt
->charset
= oldcharset
;
495 if ((ctxt
->encoding
!= NULL
) &&
496 ((ctxt
->dict
== NULL
) ||
497 (!xmlDictOwns(ctxt
->dict
, ctxt
->encoding
))))
498 xmlFree((xmlChar
*) ctxt
->encoding
);
499 ctxt
->encoding
= oldencoding
;
500 /* ctxt->wellFormed = oldwellFormed; */
505 * xmlSAX2ResolveEntity:
506 * @ctx: the user data (XML parser context)
507 * @publicId: The public ID of the entity
508 * @systemId: The system ID of the entity
510 * The entity loader, to control the loading of external entities,
511 * the application can either:
512 * - override this xmlSAX2ResolveEntity() callback in the SAX block
513 * - or better use the xmlSetExternalEntityLoader() function to
514 * set up it's own entity resolution routine
516 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
519 xmlSAX2ResolveEntity(void *ctx
, const xmlChar
*publicId
, const xmlChar
*systemId
)
521 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
522 xmlParserInputPtr ret
;
524 const char *base
= NULL
;
526 if (ctx
== NULL
) return(NULL
);
527 if (ctxt
->input
!= NULL
)
528 base
= ctxt
->input
->filename
;
530 base
= ctxt
->directory
;
532 URI
= xmlBuildURI(systemId
, (const xmlChar
*) base
);
535 xmlGenericError(xmlGenericErrorContext
,
536 "SAX.xmlSAX2ResolveEntity(%s, %s)\n", publicId
, systemId
);
539 ret
= xmlLoadExternalEntity((const char *) URI
,
540 (const char *) publicId
, ctxt
);
548 * @ctx: the user data (XML parser context)
549 * @name: The entity name
551 * Get an entity by name
553 * Returns the xmlEntityPtr if found.
556 xmlSAX2GetEntity(void *ctx
, const xmlChar
*name
)
558 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
559 xmlEntityPtr ret
= NULL
;
561 if (ctx
== NULL
) return(NULL
);
563 xmlGenericError(xmlGenericErrorContext
,
564 "SAX.xmlSAX2GetEntity(%s)\n", name
);
567 if (ctxt
->inSubset
== 0) {
568 ret
= xmlGetPredefinedEntity(name
);
572 if ((ctxt
->myDoc
!= NULL
) && (ctxt
->myDoc
->standalone
== 1)) {
573 if (ctxt
->inSubset
== 2) {
574 ctxt
->myDoc
->standalone
= 0;
575 ret
= xmlGetDocEntity(ctxt
->myDoc
, name
);
576 ctxt
->myDoc
->standalone
= 1;
578 ret
= xmlGetDocEntity(ctxt
->myDoc
, name
);
580 ctxt
->myDoc
->standalone
= 0;
581 ret
= xmlGetDocEntity(ctxt
->myDoc
, name
);
583 xmlFatalErrMsg(ctxt
, XML_ERR_NOT_STANDALONE
,
584 "Entity(%s) document marked standalone but requires external subset\n",
587 ctxt
->myDoc
->standalone
= 1;
591 ret
= xmlGetDocEntity(ctxt
->myDoc
, name
);
597 * xmlSAX2GetParameterEntity:
598 * @ctx: the user data (XML parser context)
599 * @name: The entity name
601 * Get a parameter entity by name
603 * Returns the xmlEntityPtr if found.
606 xmlSAX2GetParameterEntity(void *ctx
, const xmlChar
*name
)
608 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
611 if (ctx
== NULL
) return(NULL
);
613 xmlGenericError(xmlGenericErrorContext
,
614 "SAX.xmlSAX2GetParameterEntity(%s)\n", name
);
617 ret
= xmlGetParameterEntity(ctxt
->myDoc
, name
);
624 * @ctx: the user data (XML parser context)
625 * @name: the entity name
626 * @type: the entity type
627 * @publicId: The public ID of the entity
628 * @systemId: The system ID of the entity
629 * @content: the entity value (without processing).
631 * An entity definition has been parsed
634 xmlSAX2EntityDecl(void *ctx
, const xmlChar
*name
, int type
,
635 const xmlChar
*publicId
, const xmlChar
*systemId
, xmlChar
*content
)
638 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
640 if (ctx
== NULL
) return;
642 xmlGenericError(xmlGenericErrorContext
,
643 "SAX.xmlSAX2EntityDecl(%s, %d, %s, %s, %s)\n",
644 name
, type
, publicId
, systemId
, content
);
646 if (ctxt
->inSubset
== 1) {
647 ent
= xmlAddDocEntity(ctxt
->myDoc
, name
, type
, publicId
,
649 if ((ent
== NULL
) && (ctxt
->pedantic
))
650 xmlWarnMsg(ctxt
, XML_WAR_ENTITY_REDEFINED
,
651 "Entity(%s) already defined in the internal subset\n",
653 if ((ent
!= NULL
) && (ent
->URI
== NULL
) && (systemId
!= NULL
)) {
655 const char *base
= NULL
;
657 if (ctxt
->input
!= NULL
)
658 base
= ctxt
->input
->filename
;
660 base
= ctxt
->directory
;
662 URI
= xmlBuildURI(systemId
, (const xmlChar
*) base
);
665 } else if (ctxt
->inSubset
== 2) {
666 ent
= xmlAddDtdEntity(ctxt
->myDoc
, name
, type
, publicId
,
668 if ((ent
== NULL
) && (ctxt
->pedantic
) &&
669 (ctxt
->sax
!= NULL
) && (ctxt
->sax
->warning
!= NULL
))
670 ctxt
->sax
->warning(ctxt
->userData
,
671 "Entity(%s) already defined in the external subset\n", name
);
672 if ((ent
!= NULL
) && (ent
->URI
== NULL
) && (systemId
!= NULL
)) {
674 const char *base
= NULL
;
676 if (ctxt
->input
!= NULL
)
677 base
= ctxt
->input
->filename
;
679 base
= ctxt
->directory
;
681 URI
= xmlBuildURI(systemId
, (const xmlChar
*) base
);
685 xmlFatalErrMsg(ctxt
, XML_ERR_ENTITY_PROCESSING
,
686 "SAX.xmlSAX2EntityDecl(%s) called while not in subset\n",
692 * xmlSAX2AttributeDecl:
693 * @ctx: the user data (XML parser context)
694 * @elem: the name of the element
695 * @fullname: the attribute name
696 * @type: the attribute type
697 * @def: the type of default value
698 * @defaultValue: the attribute default value
699 * @tree: the tree of enumerated value set
701 * An attribute definition has been parsed
704 xmlSAX2AttributeDecl(void *ctx
, const xmlChar
*elem
, const xmlChar
*fullname
,
705 int type
, int def
, const xmlChar
*defaultValue
,
706 xmlEnumerationPtr tree
)
708 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
709 xmlAttributePtr attr
;
710 xmlChar
*name
= NULL
, *prefix
= NULL
;
712 if ((ctxt
== NULL
) || (ctxt
->myDoc
== NULL
))
716 xmlGenericError(xmlGenericErrorContext
,
717 "SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n",
718 elem
, fullname
, type
, def
, defaultValue
);
720 if ((xmlStrEqual(fullname
, BAD_CAST
"xml:id")) &&
721 (type
!= XML_ATTRIBUTE_ID
)) {
723 * Raise the error but keep the validity flag
725 int tmp
= ctxt
->valid
;
726 xmlErrValid(ctxt
, XML_DTD_XMLID_TYPE
,
727 "xml:id : attribute type should be ID\n", NULL
, NULL
);
730 /* TODO: optimize name/prefix allocation */
731 name
= xmlSplitQName(ctxt
, fullname
, &prefix
);
732 ctxt
->vctxt
.valid
= 1;
733 if (ctxt
->inSubset
== 1)
734 attr
= xmlAddAttributeDecl(&ctxt
->vctxt
, ctxt
->myDoc
->intSubset
, elem
,
735 name
, prefix
, (xmlAttributeType
) type
,
736 (xmlAttributeDefault
) def
, defaultValue
, tree
);
737 else if (ctxt
->inSubset
== 2)
738 attr
= xmlAddAttributeDecl(&ctxt
->vctxt
, ctxt
->myDoc
->extSubset
, elem
,
739 name
, prefix
, (xmlAttributeType
) type
,
740 (xmlAttributeDefault
) def
, defaultValue
, tree
);
742 xmlFatalErrMsg(ctxt
, XML_ERR_INTERNAL_ERROR
,
743 "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n",
746 xmlFreeEnumeration(tree
);
749 #ifdef LIBXML_VALID_ENABLED
750 if (ctxt
->vctxt
.valid
== 0)
752 if ((attr
!= NULL
) && (ctxt
->validate
) && (ctxt
->wellFormed
) &&
753 (ctxt
->myDoc
->intSubset
!= NULL
))
754 ctxt
->valid
&= xmlValidateAttributeDecl(&ctxt
->vctxt
, ctxt
->myDoc
,
756 #endif /* LIBXML_VALID_ENABLED */
764 * xmlSAX2ElementDecl:
765 * @ctx: the user data (XML parser context)
766 * @name: the element name
767 * @type: the element type
768 * @content: the element value tree
770 * An element definition has been parsed
773 xmlSAX2ElementDecl(void *ctx
, const xmlChar
* name
, int type
,
774 xmlElementContentPtr content
)
776 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
777 xmlElementPtr elem
= NULL
;
779 if ((ctxt
== NULL
) || (ctxt
->myDoc
== NULL
))
783 xmlGenericError(xmlGenericErrorContext
,
784 "SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name
, type
);
787 if (ctxt
->inSubset
== 1)
788 elem
= xmlAddElementDecl(&ctxt
->vctxt
, ctxt
->myDoc
->intSubset
,
789 name
, (xmlElementTypeVal
) type
, content
);
790 else if (ctxt
->inSubset
== 2)
791 elem
= xmlAddElementDecl(&ctxt
->vctxt
, ctxt
->myDoc
->extSubset
,
792 name
, (xmlElementTypeVal
) type
, content
);
794 xmlFatalErrMsg(ctxt
, XML_ERR_INTERNAL_ERROR
,
795 "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",
799 #ifdef LIBXML_VALID_ENABLED
802 if (ctxt
->validate
&& ctxt
->wellFormed
&&
803 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
)
805 xmlValidateElementDecl(&ctxt
->vctxt
, ctxt
->myDoc
, elem
);
806 #endif /* LIBXML_VALID_ENABLED */
810 * xmlSAX2NotationDecl:
811 * @ctx: the user data (XML parser context)
812 * @name: The name of the notation
813 * @publicId: The public ID of the entity
814 * @systemId: The system ID of the entity
816 * What to do when a notation declaration has been parsed.
819 xmlSAX2NotationDecl(void *ctx
, const xmlChar
*name
,
820 const xmlChar
*publicId
, const xmlChar
*systemId
)
822 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
823 xmlNotationPtr nota
= NULL
;
825 if ((ctxt
== NULL
) || (ctxt
->myDoc
== NULL
))
829 xmlGenericError(xmlGenericErrorContext
,
830 "SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name
, publicId
, systemId
);
833 if ((publicId
== NULL
) && (systemId
== NULL
)) {
834 xmlFatalErrMsg(ctxt
, XML_ERR_NOTATION_PROCESSING
,
835 "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n",
838 } else if (ctxt
->inSubset
== 1)
839 nota
= xmlAddNotationDecl(&ctxt
->vctxt
, ctxt
->myDoc
->intSubset
, name
,
841 else if (ctxt
->inSubset
== 2)
842 nota
= xmlAddNotationDecl(&ctxt
->vctxt
, ctxt
->myDoc
->extSubset
, name
,
845 xmlFatalErrMsg(ctxt
, XML_ERR_NOTATION_PROCESSING
,
846 "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n",
850 #ifdef LIBXML_VALID_ENABLED
851 if (nota
== NULL
) ctxt
->valid
= 0;
852 if ((ctxt
->validate
) && (ctxt
->wellFormed
) &&
853 (ctxt
->myDoc
->intSubset
!= NULL
))
854 ctxt
->valid
&= xmlValidateNotationDecl(&ctxt
->vctxt
, ctxt
->myDoc
,
856 #endif /* LIBXML_VALID_ENABLED */
860 * xmlSAX2UnparsedEntityDecl:
861 * @ctx: the user data (XML parser context)
862 * @name: The name of the entity
863 * @publicId: The public ID of the entity
864 * @systemId: The system ID of the entity
865 * @notationName: the name of the notation
867 * What to do when an unparsed entity declaration is parsed
870 xmlSAX2UnparsedEntityDecl(void *ctx
, const xmlChar
*name
,
871 const xmlChar
*publicId
, const xmlChar
*systemId
,
872 const xmlChar
*notationName
)
875 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
876 if (ctx
== NULL
) return;
878 xmlGenericError(xmlGenericErrorContext
,
879 "SAX.xmlSAX2UnparsedEntityDecl(%s, %s, %s, %s)\n",
880 name
, publicId
, systemId
, notationName
);
882 if (ctxt
->inSubset
== 1) {
883 ent
= xmlAddDocEntity(ctxt
->myDoc
, name
,
884 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
,
885 publicId
, systemId
, notationName
);
886 if ((ent
== NULL
) && (ctxt
->pedantic
) &&
887 (ctxt
->sax
!= NULL
) && (ctxt
->sax
->warning
!= NULL
))
888 ctxt
->sax
->warning(ctxt
->userData
,
889 "Entity(%s) already defined in the internal subset\n", name
);
890 if ((ent
!= NULL
) && (ent
->URI
== NULL
) && (systemId
!= NULL
)) {
892 const char *base
= NULL
;
894 if (ctxt
->input
!= NULL
)
895 base
= ctxt
->input
->filename
;
897 base
= ctxt
->directory
;
899 URI
= xmlBuildURI(systemId
, (const xmlChar
*) base
);
902 } else if (ctxt
->inSubset
== 2) {
903 ent
= xmlAddDtdEntity(ctxt
->myDoc
, name
,
904 XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
,
905 publicId
, systemId
, notationName
);
906 if ((ent
== NULL
) && (ctxt
->pedantic
) &&
907 (ctxt
->sax
!= NULL
) && (ctxt
->sax
->warning
!= NULL
))
908 ctxt
->sax
->warning(ctxt
->userData
,
909 "Entity(%s) already defined in the external subset\n", name
);
910 if ((ent
!= NULL
) && (ent
->URI
== NULL
) && (systemId
!= NULL
)) {
912 const char *base
= NULL
;
914 if (ctxt
->input
!= NULL
)
915 base
= ctxt
->input
->filename
;
917 base
= ctxt
->directory
;
919 URI
= xmlBuildURI(systemId
, (const xmlChar
*) base
);
923 xmlFatalErrMsg(ctxt
, XML_ERR_INTERNAL_ERROR
,
924 "SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n",
930 * xmlSAX2SetDocumentLocator:
931 * @ctx: the user data (XML parser context)
932 * @loc: A SAX Locator
934 * Receive the document locator at startup, actually xmlDefaultSAXLocator
935 * Everything is available on the context, so this is useless in our case.
938 xmlSAX2SetDocumentLocator(void *ctx ATTRIBUTE_UNUSED
, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED
)
940 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
942 xmlGenericError(xmlGenericErrorContext
,
943 "SAX.xmlSAX2SetDocumentLocator()\n");
948 * xmlSAX2StartDocument:
949 * @ctx: the user data (XML parser context)
951 * called when the document start being processed.
954 xmlSAX2StartDocument(void *ctx
)
956 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
959 if (ctx
== NULL
) return;
962 xmlGenericError(xmlGenericErrorContext
,
963 "SAX.xmlSAX2StartDocument()\n");
966 #ifdef LIBXML_HTML_ENABLED
967 if (ctxt
->myDoc
== NULL
)
968 ctxt
->myDoc
= htmlNewDocNoDtD(NULL
, NULL
);
969 if (ctxt
->myDoc
== NULL
) {
970 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartDocument");
973 ctxt
->myDoc
->properties
= XML_DOC_HTML
;
974 ctxt
->myDoc
->parseFlags
= ctxt
->options
;
976 xmlGenericError(xmlGenericErrorContext
,
977 "libxml2 built without HTML support\n");
978 ctxt
->errNo
= XML_ERR_INTERNAL_ERROR
;
979 ctxt
->instate
= XML_PARSER_EOF
;
980 ctxt
->disableSAX
= 1;
984 doc
= ctxt
->myDoc
= xmlNewDoc(ctxt
->version
);
987 if (ctxt
->options
& XML_PARSE_OLD10
)
988 doc
->properties
|= XML_DOC_OLD10
;
989 doc
->parseFlags
= ctxt
->options
;
990 if (ctxt
->encoding
!= NULL
)
991 doc
->encoding
= xmlStrdup(ctxt
->encoding
);
993 doc
->encoding
= NULL
;
994 doc
->standalone
= ctxt
->standalone
;
996 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartDocument");
999 if ((ctxt
->dictNames
) && (doc
!= NULL
)) {
1000 doc
->dict
= ctxt
->dict
;
1001 xmlDictReference(doc
->dict
);
1004 if ((ctxt
->myDoc
!= NULL
) && (ctxt
->myDoc
->URL
== NULL
) &&
1005 (ctxt
->input
!= NULL
) && (ctxt
->input
->filename
!= NULL
)) {
1006 ctxt
->myDoc
->URL
= xmlPathToURI((const xmlChar
*)ctxt
->input
->filename
);
1007 if (ctxt
->myDoc
->URL
== NULL
)
1008 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartDocument");
1013 * xmlSAX2EndDocument:
1014 * @ctx: the user data (XML parser context)
1016 * called when the document end has been detected.
1019 xmlSAX2EndDocument(void *ctx
)
1021 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
1023 xmlGenericError(xmlGenericErrorContext
,
1024 "SAX.xmlSAX2EndDocument()\n");
1026 if (ctx
== NULL
) return;
1027 #ifdef LIBXML_VALID_ENABLED
1028 if (ctxt
->validate
&& ctxt
->wellFormed
&&
1029 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
)
1030 ctxt
->valid
&= xmlValidateDocumentFinal(&ctxt
->vctxt
, ctxt
->myDoc
);
1031 #endif /* LIBXML_VALID_ENABLED */
1034 * Grab the encoding if it was added on-the-fly
1036 if ((ctxt
->encoding
!= NULL
) && (ctxt
->myDoc
!= NULL
) &&
1037 (ctxt
->myDoc
->encoding
== NULL
)) {
1038 ctxt
->myDoc
->encoding
= ctxt
->encoding
;
1039 ctxt
->encoding
= NULL
;
1041 if ((ctxt
->inputTab
!= NULL
) &&
1042 (ctxt
->inputNr
> 0) && (ctxt
->inputTab
[0] != NULL
) &&
1043 (ctxt
->inputTab
[0]->encoding
!= NULL
) && (ctxt
->myDoc
!= NULL
) &&
1044 (ctxt
->myDoc
->encoding
== NULL
)) {
1045 ctxt
->myDoc
->encoding
= xmlStrdup(ctxt
->inputTab
[0]->encoding
);
1047 if ((ctxt
->charset
!= XML_CHAR_ENCODING_NONE
) && (ctxt
->myDoc
!= NULL
) &&
1048 (ctxt
->myDoc
->charset
== XML_CHAR_ENCODING_NONE
)) {
1049 ctxt
->myDoc
->charset
= ctxt
->charset
;
1053 #if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || defined(LIBXML_LEGACY_ENABLED)
1055 * xmlSAX2AttributeInternal:
1056 * @ctx: the user data (XML parser context)
1057 * @fullname: The attribute name, including namespace prefix
1058 * @value: The attribute value
1059 * @prefix: the prefix on the element node
1061 * Handle an attribute that has been read by the parser.
1062 * The default handling is to convert the attribute into an
1063 * DOM subtree and past it in a new xmlAttr element added to
1067 xmlSAX2AttributeInternal(void *ctx
, const xmlChar
*fullname
,
1068 const xmlChar
*value
, const xmlChar
*prefix ATTRIBUTE_UNUSED
)
1070 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
1078 name
= xmlStrdup(fullname
);
1083 * Split the full name into a namespace prefix and the tag name
1085 name
= xmlSplitQName(ctxt
, fullname
, &ns
);
1086 if ((name
!= NULL
) && (name
[0] == 0)) {
1087 if (xmlStrEqual(ns
, BAD_CAST
"xmlns")) {
1088 xmlNsErrMsg(ctxt
, XML_ERR_NS_DECL_ERROR
,
1089 "invalid namespace declaration '%s'\n",
1092 xmlNsWarnMsg(ctxt
, XML_WAR_NS_COLUMN
,
1093 "Avoid attribute ending with ':' like '%s'\n",
1100 name
= xmlStrdup(fullname
);
1104 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElement");
1110 #ifdef LIBXML_HTML_ENABLED
1112 (value
== NULL
) && (htmlIsBooleanAttr(fullname
))) {
1113 nval
= xmlStrdup(fullname
);
1114 value
= (const xmlChar
*) nval
;
1118 #ifdef LIBXML_VALID_ENABLED
1120 * Do the last stage of the attribute normalization
1121 * Needed for HTML too:
1122 * http://www.w3.org/TR/html4/types.html#h-6.2
1124 ctxt
->vctxt
.valid
= 1;
1125 nval
= xmlValidCtxtNormalizeAttributeValue(&ctxt
->vctxt
,
1126 ctxt
->myDoc
, ctxt
->node
,
1128 if (ctxt
->vctxt
.valid
!= 1) {
1135 #endif /* LIBXML_VALID_ENABLED */
1139 * Check whether it's a namespace definition
1141 if ((!ctxt
->html
) && (ns
== NULL
) &&
1142 (name
[0] == 'x') && (name
[1] == 'm') && (name
[2] == 'l') &&
1143 (name
[3] == 'n') && (name
[4] == 's') && (name
[5] == 0)) {
1147 if (!ctxt
->replaceEntities
) {
1149 val
= xmlStringDecodeEntities(ctxt
, value
, XML_SUBSTITUTE_REF
,
1153 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElement");
1161 val
= (xmlChar
*) value
;
1167 uri
= xmlParseURI((const char *)val
);
1169 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->warning
!= NULL
))
1170 ctxt
->sax
->warning(ctxt
->userData
,
1171 "xmlns: %s not a valid URI\n", val
);
1173 if (uri
->scheme
== NULL
) {
1174 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->warning
!= NULL
))
1175 ctxt
->sax
->warning(ctxt
->userData
,
1176 "xmlns: URI %s is not absolute\n", val
);
1182 /* a default namespace definition */
1183 nsret
= xmlNewNs(ctxt
->node
, val
, NULL
);
1185 #ifdef LIBXML_VALID_ENABLED
1187 * Validate also for namespace decls, they are attributes from
1188 * an XML-1.0 perspective
1190 if (nsret
!= NULL
&& ctxt
->validate
&& ctxt
->wellFormed
&&
1191 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
)
1192 ctxt
->valid
&= xmlValidateOneNamespace(&ctxt
->vctxt
, ctxt
->myDoc
,
1193 ctxt
->node
, prefix
, nsret
, val
);
1194 #endif /* LIBXML_VALID_ENABLED */
1203 if ((!ctxt
->html
) &&
1204 (ns
!= NULL
) && (ns
[0] == 'x') && (ns
[1] == 'm') && (ns
[2] == 'l') &&
1205 (ns
[3] == 'n') && (ns
[4] == 's') && (ns
[5] == 0)) {
1209 if (!ctxt
->replaceEntities
) {
1211 val
= xmlStringDecodeEntities(ctxt
, value
, XML_SUBSTITUTE_REF
,
1215 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElement");
1224 val
= (xmlChar
*) value
;
1228 xmlNsErrMsg(ctxt
, XML_NS_ERR_EMPTY
,
1229 "Empty namespace name for prefix %s\n", name
, NULL
);
1231 if ((ctxt
->pedantic
!= 0) && (val
[0] != 0)) {
1234 uri
= xmlParseURI((const char *)val
);
1236 xmlNsWarnMsg(ctxt
, XML_WAR_NS_URI
,
1237 "xmlns:%s: %s not a valid URI\n", name
, value
);
1239 if (uri
->scheme
== NULL
) {
1240 xmlNsWarnMsg(ctxt
, XML_WAR_NS_URI_RELATIVE
,
1241 "xmlns:%s: URI %s is not absolute\n", name
, value
);
1247 /* a standard namespace definition */
1248 nsret
= xmlNewNs(ctxt
->node
, val
, name
);
1250 #ifdef LIBXML_VALID_ENABLED
1252 * Validate also for namespace decls, they are attributes from
1253 * an XML-1.0 perspective
1255 if (nsret
!= NULL
&& ctxt
->validate
&& ctxt
->wellFormed
&&
1256 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
)
1257 ctxt
->valid
&= xmlValidateOneNamespace(&ctxt
->vctxt
, ctxt
->myDoc
,
1258 ctxt
->node
, prefix
, nsret
, value
);
1259 #endif /* LIBXML_VALID_ENABLED */
1270 namespace = xmlSearchNs(ctxt
->myDoc
, ctxt
->node
, ns
);
1272 if (namespace == NULL
) {
1273 xmlNsErrMsg(ctxt
, XML_NS_ERR_UNDEFINED_NAMESPACE
,
1274 "Namespace prefix %s of attribute %s is not defined\n",
1279 prop
= ctxt
->node
->properties
;
1280 while (prop
!= NULL
) {
1281 if (prop
->ns
!= NULL
) {
1282 if ((xmlStrEqual(name
, prop
->name
)) &&
1283 ((namespace == prop
->ns
) ||
1284 (xmlStrEqual(namespace->href
, prop
->ns
->href
)))) {
1285 xmlNsErrMsg(ctxt
, XML_ERR_ATTRIBUTE_REDEFINED
,
1286 "Attribute %s in %s redefined\n",
1287 name
, namespace->href
);
1288 ctxt
->wellFormed
= 0;
1289 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
1302 /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */
1303 ret
= xmlNewNsPropEatName(ctxt
->node
, namespace, name
, NULL
);
1306 if ((ctxt
->replaceEntities
== 0) && (!ctxt
->html
)) {
1309 ret
->children
= xmlStringGetNodeList(ctxt
->myDoc
, value
);
1310 tmp
= ret
->children
;
1311 while (tmp
!= NULL
) {
1312 tmp
->parent
= (xmlNodePtr
) ret
;
1313 if (tmp
->next
== NULL
)
1317 } else if (value
!= NULL
) {
1318 ret
->children
= xmlNewDocText(ctxt
->myDoc
, value
);
1319 ret
->last
= ret
->children
;
1320 if (ret
->children
!= NULL
)
1321 ret
->children
->parent
= (xmlNodePtr
) ret
;
1325 #ifdef LIBXML_VALID_ENABLED
1326 if ((!ctxt
->html
) && ctxt
->validate
&& ctxt
->wellFormed
&&
1327 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
) {
1330 * If we don't substitute entities, the validation should be
1331 * done on a value with replaced entities anyway.
1333 if (!ctxt
->replaceEntities
) {
1337 val
= xmlStringDecodeEntities(ctxt
, value
, XML_SUBSTITUTE_REF
,
1342 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
,
1343 ctxt
->myDoc
, ctxt
->node
, ret
, value
);
1348 * Do the last stage of the attribute normalization
1349 * It need to be done twice ... it's an extra burden related
1350 * to the ability to keep xmlSAX2References in attributes
1352 nvalnorm
= xmlValidNormalizeAttributeValue(ctxt
->myDoc
,
1353 ctxt
->node
, fullname
, val
);
1354 if (nvalnorm
!= NULL
) {
1359 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
,
1360 ctxt
->myDoc
, ctxt
->node
, ret
, val
);
1364 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
, ctxt
->myDoc
,
1365 ctxt
->node
, ret
, value
);
1368 #endif /* LIBXML_VALID_ENABLED */
1369 if (((ctxt
->loadsubset
& XML_SKIP_IDS
) == 0) &&
1370 (((ctxt
->replaceEntities
== 0) && (ctxt
->external
!= 2)) ||
1371 ((ctxt
->replaceEntities
!= 0) && (ctxt
->inSubset
== 0)))) {
1373 * when validating, the ID registration is done at the attribute
1374 * validation level. Otherwise we have to do specific handling here.
1376 if (xmlStrEqual(fullname
, BAD_CAST
"xml:id")) {
1378 * Add the xml:id value
1380 * Open issue: normalization of the value.
1382 if (xmlValidateNCName(value
, 1) != 0) {
1383 xmlErrValid(ctxt
, XML_DTD_XMLID_VALUE
,
1384 "xml:id : attribute value %s is not an NCName\n",
1385 (const char *) value
, NULL
);
1387 xmlAddID(&ctxt
->vctxt
, ctxt
->myDoc
, value
, ret
);
1388 } else if (xmlIsID(ctxt
->myDoc
, ctxt
->node
, ret
))
1389 xmlAddID(&ctxt
->vctxt
, ctxt
->myDoc
, value
, ret
);
1390 else if (xmlIsRef(ctxt
->myDoc
, ctxt
->node
, ret
))
1391 xmlAddRef(&ctxt
->vctxt
, ctxt
->myDoc
, value
, ret
);
1402 * xmlCheckDefaultedAttributes:
1404 * Check defaulted attributes from the DTD
1407 xmlCheckDefaultedAttributes(xmlParserCtxtPtr ctxt
, const xmlChar
*name
,
1408 const xmlChar
*prefix
, const xmlChar
**atts
) {
1409 xmlElementPtr elemDecl
;
1414 elemDecl
= xmlGetDtdQElementDesc(ctxt
->myDoc
->intSubset
, name
, prefix
);
1415 if (elemDecl
== NULL
) {
1416 elemDecl
= xmlGetDtdQElementDesc(ctxt
->myDoc
->extSubset
, name
, prefix
);
1420 process_external_subset
:
1422 if (elemDecl
!= NULL
) {
1423 xmlAttributePtr attr
= elemDecl
->attributes
;
1425 * Check against defaulted attributes from the external subset
1426 * if the document is stamped as standalone
1428 if ((ctxt
->myDoc
->standalone
== 1) &&
1429 (ctxt
->myDoc
->extSubset
!= NULL
) &&
1431 while (attr
!= NULL
) {
1432 if ((attr
->defaultValue
!= NULL
) &&
1433 (xmlGetDtdQAttrDesc(ctxt
->myDoc
->extSubset
,
1434 attr
->elem
, attr
->name
,
1435 attr
->prefix
) == attr
) &&
1436 (xmlGetDtdQAttrDesc(ctxt
->myDoc
->intSubset
,
1437 attr
->elem
, attr
->name
,
1438 attr
->prefix
) == NULL
)) {
1441 if (attr
->prefix
!= NULL
) {
1442 fulln
= xmlStrdup(attr
->prefix
);
1443 fulln
= xmlStrcat(fulln
, BAD_CAST
":");
1444 fulln
= xmlStrcat(fulln
, attr
->name
);
1446 fulln
= xmlStrdup(attr
->name
);
1448 if (fulln
== NULL
) {
1449 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElement");
1454 * Check that the attribute is not declared in the
1461 while (att
!= NULL
) {
1462 if (xmlStrEqual(att
, fulln
))
1469 xmlErrValid(ctxt
, XML_DTD_STANDALONE_DEFAULTED
,
1470 "standalone: attribute %s on %s defaulted from external subset\n",
1471 (const char *)fulln
,
1472 (const char *)attr
->elem
);
1481 * Actually insert defaulted values when needed
1483 attr
= elemDecl
->attributes
;
1484 while (attr
!= NULL
) {
1486 * Make sure that attributes redefinition occurring in the
1487 * internal subset are not overridden by definitions in the
1490 if (attr
->defaultValue
!= NULL
) {
1492 * the element should be instantiated in the tree if:
1493 * - this is a namespace prefix
1494 * - the user required for completion in the tree
1496 * - there isn't already an attribute definition
1497 * in the internal subset overriding it.
1499 if (((attr
->prefix
!= NULL
) &&
1500 (xmlStrEqual(attr
->prefix
, BAD_CAST
"xmlns"))) ||
1501 ((attr
->prefix
== NULL
) &&
1502 (xmlStrEqual(attr
->name
, BAD_CAST
"xmlns"))) ||
1503 (ctxt
->loadsubset
& XML_COMPLETE_ATTRS
)) {
1504 xmlAttributePtr tst
;
1506 tst
= xmlGetDtdQAttrDesc(ctxt
->myDoc
->intSubset
,
1507 attr
->elem
, attr
->name
,
1509 if ((tst
== attr
) || (tst
== NULL
)) {
1513 fulln
= xmlBuildQName(attr
->name
, attr
->prefix
, fn
, 50);
1514 if (fulln
== NULL
) {
1515 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElement");
1520 * Check that the attribute is not declared in the
1527 while (att
!= NULL
) {
1528 if (xmlStrEqual(att
, fulln
))
1535 xmlSAX2AttributeInternal(ctxt
, fulln
,
1536 attr
->defaultValue
, prefix
);
1538 if ((fulln
!= fn
) && (fulln
!= attr
->name
))
1545 if (internal
== 1) {
1546 elemDecl
= xmlGetDtdQElementDesc(ctxt
->myDoc
->extSubset
,
1549 goto process_external_subset
;
1555 * xmlSAX2StartElement:
1556 * @ctx: the user data (XML parser context)
1557 * @fullname: The element name, including namespace prefix
1558 * @atts: An array of name/value attributes pairs, NULL terminated
1560 * called when an opening tag has been processed.
1563 xmlSAX2StartElement(void *ctx
, const xmlChar
*fullname
, const xmlChar
**atts
)
1565 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
1572 const xmlChar
*value
;
1575 if ((ctx
== NULL
) || (fullname
== NULL
) || (ctxt
->myDoc
== NULL
)) return;
1576 parent
= ctxt
->node
;
1578 xmlGenericError(xmlGenericErrorContext
,
1579 "SAX.xmlSAX2StartElement(%s)\n", fullname
);
1583 * First check on validity:
1585 if (ctxt
->validate
&& (ctxt
->myDoc
->extSubset
== NULL
) &&
1586 ((ctxt
->myDoc
->intSubset
== NULL
) ||
1587 ((ctxt
->myDoc
->intSubset
->notations
== NULL
) &&
1588 (ctxt
->myDoc
->intSubset
->elements
== NULL
) &&
1589 (ctxt
->myDoc
->intSubset
->attributes
== NULL
) &&
1590 (ctxt
->myDoc
->intSubset
->entities
== NULL
)))) {
1591 xmlErrValid(ctxt
, XML_ERR_NO_DTD
,
1592 "Validation failed: no DTD found !", NULL
, NULL
);
1598 * Split the full name into a namespace prefix and the tag name
1600 name
= xmlSplitQName(ctxt
, fullname
, &prefix
);
1604 * Note : the namespace resolution is deferred until the end of the
1605 * attributes parsing, since local namespace can be defined as
1606 * an attribute at this level.
1608 ret
= xmlNewDocNodeEatName(ctxt
->myDoc
, NULL
, name
, NULL
);
1612 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElement");
1615 if (ctxt
->myDoc
->children
== NULL
) {
1616 #ifdef DEBUG_SAX_TREE
1617 xmlGenericError(xmlGenericErrorContext
, "Setting %s as root\n", name
);
1619 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
, (xmlNodePtr
) ret
);
1620 } else if (parent
== NULL
) {
1621 parent
= ctxt
->myDoc
->children
;
1624 if (ctxt
->linenumbers
) {
1625 if (ctxt
->input
!= NULL
) {
1626 if (ctxt
->input
->line
< USHRT_MAX
)
1627 ret
->line
= (unsigned short) ctxt
->input
->line
;
1629 ret
->line
= USHRT_MAX
;
1634 * We are parsing a new node.
1636 #ifdef DEBUG_SAX_TREE
1637 xmlGenericError(xmlGenericErrorContext
, "pushing(%s)\n", name
);
1639 if (nodePush(ctxt
, ret
) < 0) {
1648 * Link the child element
1650 if (parent
!= NULL
) {
1651 if (parent
->type
== XML_ELEMENT_NODE
) {
1652 #ifdef DEBUG_SAX_TREE
1653 xmlGenericError(xmlGenericErrorContext
,
1654 "adding child %s to %s\n", name
, parent
->name
);
1656 xmlAddChild(parent
, ret
);
1658 #ifdef DEBUG_SAX_TREE
1659 xmlGenericError(xmlGenericErrorContext
,
1660 "adding sibling %s to ", name
);
1661 xmlDebugDumpOneNode(stderr
, parent
, 0);
1663 xmlAddSibling(parent
, ret
);
1669 * Insert all the defaulted attributes from the DTD especially
1672 if ((ctxt
->myDoc
->intSubset
!= NULL
) ||
1673 (ctxt
->myDoc
->extSubset
!= NULL
)) {
1674 xmlCheckDefaultedAttributes(ctxt
, name
, prefix
, atts
);
1678 * process all the attributes whose name start with "xmlns"
1684 while ((att
!= NULL
) && (value
!= NULL
)) {
1685 if ((att
[0] == 'x') && (att
[1] == 'm') && (att
[2] == 'l') &&
1686 (att
[3] == 'n') && (att
[4] == 's'))
1687 xmlSAX2AttributeInternal(ctxt
, att
, value
, prefix
);
1695 * Search the namespace, note that since the attributes have been
1696 * processed, the local namespaces are available.
1698 ns
= xmlSearchNs(ctxt
->myDoc
, ret
, prefix
);
1699 if ((ns
== NULL
) && (parent
!= NULL
))
1700 ns
= xmlSearchNs(ctxt
->myDoc
, parent
, prefix
);
1701 if ((prefix
!= NULL
) && (ns
== NULL
)) {
1702 ns
= xmlNewNs(ret
, NULL
, prefix
);
1703 xmlNsWarnMsg(ctxt
, XML_NS_ERR_UNDEFINED_NAMESPACE
,
1704 "Namespace prefix %s is not defined\n",
1709 * set the namespace node, making sure that if the default namespace
1710 * is unbound on a parent we simply keep it NULL
1712 if ((ns
!= NULL
) && (ns
->href
!= NULL
) &&
1713 ((ns
->href
[0] != 0) || (ns
->prefix
!= NULL
)))
1718 * process all the other attributes
1725 while (att
!= NULL
) {
1726 xmlSAX2AttributeInternal(ctxt
, att
, value
, NULL
);
1731 while ((att
!= NULL
) && (value
!= NULL
)) {
1732 if ((att
[0] != 'x') || (att
[1] != 'm') || (att
[2] != 'l') ||
1733 (att
[3] != 'n') || (att
[4] != 's'))
1734 xmlSAX2AttributeInternal(ctxt
, att
, value
, NULL
);
1745 #ifdef LIBXML_VALID_ENABLED
1747 * If it's the Document root, finish the DTD validation and
1748 * check the document root element for validity
1750 if ((ctxt
->validate
) && (ctxt
->vctxt
.finishDtd
== XML_CTXT_FINISH_DTD_0
)) {
1753 chk
= xmlValidateDtdFinal(&ctxt
->vctxt
, ctxt
->myDoc
);
1757 ctxt
->wellFormed
= 0;
1758 ctxt
->valid
&= xmlValidateRoot(&ctxt
->vctxt
, ctxt
->myDoc
);
1759 ctxt
->vctxt
.finishDtd
= XML_CTXT_FINISH_DTD_1
;
1761 #endif /* LIBXML_VALID_ENABLED */
1769 * xmlSAX2EndElement:
1770 * @ctx: the user data (XML parser context)
1771 * @name: The element name
1773 * called when the end of an element has been detected.
1776 xmlSAX2EndElement(void *ctx
, const xmlChar
*name ATTRIBUTE_UNUSED
)
1778 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
1781 if (ctx
== NULL
) return;
1785 xmlGenericError(xmlGenericErrorContext
, "SAX.xmlSAX2EndElement(NULL)\n");
1787 xmlGenericError(xmlGenericErrorContext
, "SAX.xmlSAX2EndElement(%s)\n", name
);
1790 /* Capture end position and add node */
1791 if (cur
!= NULL
&& ctxt
->record_info
) {
1792 ctxt
->nodeInfo
->end_pos
= ctxt
->input
->cur
- ctxt
->input
->base
;
1793 ctxt
->nodeInfo
->end_line
= ctxt
->input
->line
;
1794 ctxt
->nodeInfo
->node
= cur
;
1795 xmlParserAddNodeInfo(ctxt
, ctxt
->nodeInfo
);
1799 #ifdef LIBXML_VALID_ENABLED
1800 if (ctxt
->validate
&& ctxt
->wellFormed
&&
1801 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
)
1802 ctxt
->valid
&= xmlValidateOneElement(&ctxt
->vctxt
, ctxt
->myDoc
,
1804 #endif /* LIBXML_VALID_ENABLED */
1808 * end of parsing of this node.
1810 #ifdef DEBUG_SAX_TREE
1811 xmlGenericError(xmlGenericErrorContext
, "popping(%s)\n", cur
->name
);
1815 #endif /* LIBXML_SAX1_ENABLED || LIBXML_HTML_ENABLED || LIBXML_LEGACY_ENABLED */
1819 * @ctxt: the parser context
1820 * @str: the input string
1821 * @len: the string length
1823 * Callback for a text node
1825 * Returns the newly allocated string or NULL if not needed or error
1828 xmlSAX2TextNode(xmlParserCtxtPtr ctxt
, const xmlChar
*str
, int len
) {
1830 const xmlChar
*intern
= NULL
;
1835 if (ctxt
->freeElems
!= NULL
) {
1836 ret
= ctxt
->freeElems
;
1837 ctxt
->freeElems
= ret
->next
;
1838 ctxt
->freeElemsNr
--;
1840 ret
= (xmlNodePtr
) xmlMalloc(sizeof(xmlNode
));
1843 xmlErrMemory(ctxt
, "xmlSAX2Characters");
1846 memset(ret
, 0, sizeof(xmlNode
));
1848 * intern the formatting blanks found between tags, or the
1849 * very short strings
1851 if (ctxt
->dictNames
) {
1852 xmlChar cur
= str
[len
];
1854 if ((len
< (int) (2 * sizeof(void *))) &&
1855 (ctxt
->options
& XML_PARSE_COMPACT
)) {
1856 /* store the string in the node overriding properties and nsDef */
1857 xmlChar
*tmp
= (xmlChar
*) &(ret
->properties
);
1858 memcpy(tmp
, str
, len
);
1861 } else if ((len
<= 3) && ((cur
== '"') || (cur
== '\'') ||
1862 ((cur
== '<') && (str
[len
+ 1] != '!')))) {
1863 intern
= xmlDictLookup(ctxt
->dict
, str
, len
);
1864 } else if (IS_BLANK_CH(*str
) && (len
< 60) && (cur
== '<') &&
1865 (str
[len
+ 1] != '!')) {
1868 for (i
= 1;i
< len
;i
++) {
1869 if (!IS_BLANK_CH(str
[i
])) goto skip
;
1871 intern
= xmlDictLookup(ctxt
->dict
, str
, len
);
1875 ret
->type
= XML_TEXT_NODE
;
1877 ret
->name
= xmlStringText
;
1878 if (intern
== NULL
) {
1879 ret
->content
= xmlStrndup(str
, len
);
1880 if (ret
->content
== NULL
) {
1881 xmlSAX2ErrMemory(ctxt
, "xmlSAX2TextNode");
1886 ret
->content
= (xmlChar
*) intern
;
1888 if (ctxt
->linenumbers
) {
1889 if (ctxt
->input
!= NULL
) {
1890 if (ctxt
->input
->line
< USHRT_MAX
)
1891 ret
->line
= (unsigned short) ctxt
->input
->line
;
1893 ret
->line
= USHRT_MAX
;
1894 if (ctxt
->options
& XML_PARSE_BIG_LINES
)
1895 ret
->psvi
= (void *) (ptrdiff_t) ctxt
->input
->line
;
1900 if ((__xmlRegisterCallbacks
) && (xmlRegisterNodeDefaultValue
))
1901 xmlRegisterNodeDefaultValue(ret
);
1905 #ifdef LIBXML_VALID_ENABLED
1907 * xmlSAX2DecodeAttrEntities:
1908 * @ctxt: the parser context
1909 * @str: the input string
1910 * @len: the string length
1912 * Remove the entities from an attribute value
1914 * Returns the newly allocated string or NULL if not needed or error
1917 xmlSAX2DecodeAttrEntities(xmlParserCtxtPtr ctxt
, const xmlChar
*str
,
1918 const xmlChar
*end
) {
1929 ret
= xmlStringLenDecodeEntities(ctxt
, str
, end
- str
,
1930 XML_SUBSTITUTE_REF
, 0,0,0);
1934 #endif /* LIBXML_VALID_ENABLED */
1937 * xmlSAX2AttributeNs:
1938 * @ctx: the user data (XML parser context)
1939 * @localname: the local name of the attribute
1940 * @prefix: the attribute namespace prefix if available
1941 * @URI: the attribute namespace name if available
1942 * @value: Start of the attribute value
1943 * @valueend: end of the attribute value
1945 * Handle an attribute that has been read by the parser.
1946 * The default handling is to convert the attribute into an
1947 * DOM subtree and past it in a new xmlAttr element added to
1951 xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt
,
1952 const xmlChar
* localname
,
1953 const xmlChar
* prefix
,
1954 const xmlChar
* value
,
1955 const xmlChar
* valueend
)
1958 xmlNsPtr
namespace = NULL
;
1959 xmlChar
*dup
= NULL
;
1962 * Note: if prefix == NULL, the attribute is not in the default namespace
1965 namespace = xmlSearchNs(ctxt
->myDoc
, ctxt
->node
, prefix
);
1970 if (ctxt
->freeAttrs
!= NULL
) {
1971 ret
= ctxt
->freeAttrs
;
1972 ctxt
->freeAttrs
= ret
->next
;
1973 ctxt
->freeAttrsNr
--;
1974 memset(ret
, 0, sizeof(xmlAttr
));
1975 ret
->type
= XML_ATTRIBUTE_NODE
;
1977 ret
->parent
= ctxt
->node
;
1978 ret
->doc
= ctxt
->myDoc
;
1979 ret
->ns
= namespace;
1981 if (ctxt
->dictNames
)
1982 ret
->name
= localname
;
1984 ret
->name
= xmlStrdup(localname
);
1986 /* link at the end to preserve order, TODO speed up with a last */
1987 if (ctxt
->node
->properties
== NULL
) {
1988 ctxt
->node
->properties
= ret
;
1990 xmlAttrPtr prev
= ctxt
->node
->properties
;
1992 while (prev
->next
!= NULL
) prev
= prev
->next
;
1997 if ((__xmlRegisterCallbacks
) && (xmlRegisterNodeDefaultValue
))
1998 xmlRegisterNodeDefaultValue((xmlNodePtr
)ret
);
2000 if (ctxt
->dictNames
)
2001 ret
= xmlNewNsPropEatName(ctxt
->node
, namespace,
2002 (xmlChar
*) localname
, NULL
);
2004 ret
= xmlNewNsProp(ctxt
->node
, namespace, localname
, NULL
);
2006 xmlErrMemory(ctxt
, "xmlSAX2AttributeNs");
2011 if ((ctxt
->replaceEntities
== 0) && (!ctxt
->html
)) {
2015 * We know that if there is an entity reference, then
2016 * the string has been dup'ed and terminates with 0
2017 * otherwise with ' or "
2019 if (*valueend
!= 0) {
2020 tmp
= xmlSAX2TextNode(ctxt
, value
, valueend
- value
);
2021 ret
->children
= tmp
;
2024 tmp
->doc
= ret
->doc
;
2025 tmp
->parent
= (xmlNodePtr
) ret
;
2028 ret
->children
= xmlStringLenGetNodeList(ctxt
->myDoc
, value
,
2030 tmp
= ret
->children
;
2031 while (tmp
!= NULL
) {
2032 tmp
->doc
= ret
->doc
;
2033 tmp
->parent
= (xmlNodePtr
) ret
;
2034 if (tmp
->next
== NULL
)
2039 } else if (value
!= NULL
) {
2042 tmp
= xmlSAX2TextNode(ctxt
, value
, valueend
- value
);
2043 ret
->children
= tmp
;
2046 tmp
->doc
= ret
->doc
;
2047 tmp
->parent
= (xmlNodePtr
) ret
;
2051 #ifdef LIBXML_VALID_ENABLED
2052 if ((!ctxt
->html
) && ctxt
->validate
&& ctxt
->wellFormed
&&
2053 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
) {
2055 * If we don't substitute entities, the validation should be
2056 * done on a value with replaced entities anyway.
2058 if (!ctxt
->replaceEntities
) {
2059 dup
= xmlSAX2DecodeAttrEntities(ctxt
, value
, valueend
);
2061 if (*valueend
== 0) {
2062 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
,
2063 ctxt
->myDoc
, ctxt
->node
, ret
, value
);
2066 * That should already be normalized.
2067 * cheaper to finally allocate here than duplicate
2068 * entry points in the full validation code
2070 dup
= xmlStrndup(value
, valueend
- value
);
2072 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
,
2073 ctxt
->myDoc
, ctxt
->node
, ret
, dup
);
2077 * dup now contains a string of the flattened attribute
2078 * content with entities substituted. Check if we need to
2079 * apply an extra layer of normalization.
2080 * It need to be done twice ... it's an extra burden related
2081 * to the ability to keep references in attributes
2083 if (ctxt
->attsSpecial
!= NULL
) {
2088 fullname
= xmlBuildQName(localname
, prefix
, fn
, 50);
2089 if (fullname
!= NULL
) {
2090 ctxt
->vctxt
.valid
= 1;
2091 nvalnorm
= xmlValidCtxtNormalizeAttributeValue(
2092 &ctxt
->vctxt
, ctxt
->myDoc
,
2093 ctxt
->node
, fullname
, dup
);
2094 if (ctxt
->vctxt
.valid
!= 1)
2097 if ((fullname
!= fn
) && (fullname
!= localname
))
2099 if (nvalnorm
!= NULL
) {
2106 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
,
2107 ctxt
->myDoc
, ctxt
->node
, ret
, dup
);
2111 * if entities already have been substituted, then
2112 * the attribute as passed is already normalized
2114 dup
= xmlStrndup(value
, valueend
- value
);
2116 ctxt
->valid
&= xmlValidateOneAttribute(&ctxt
->vctxt
,
2117 ctxt
->myDoc
, ctxt
->node
, ret
, dup
);
2120 #endif /* LIBXML_VALID_ENABLED */
2121 if (((ctxt
->loadsubset
& XML_SKIP_IDS
) == 0) &&
2122 (((ctxt
->replaceEntities
== 0) && (ctxt
->external
!= 2)) ||
2123 ((ctxt
->replaceEntities
!= 0) && (ctxt
->inSubset
== 0)))) {
2125 * when validating, the ID registration is done at the attribute
2126 * validation level. Otherwise we have to do specific handling here.
2128 if ((prefix
== ctxt
->str_xml
) &&
2129 (localname
[0] == 'i') && (localname
[1] == 'd') &&
2130 (localname
[2] == 0)) {
2132 * Add the xml:id value
2134 * Open issue: normalization of the value.
2137 dup
= xmlStrndup(value
, valueend
- value
);
2138 #if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || defined(LIBXML_LEGACY_ENABLED)
2139 #ifdef LIBXML_VALID_ENABLED
2140 if (xmlValidateNCName(dup
, 1) != 0) {
2141 xmlErrValid(ctxt
, XML_DTD_XMLID_VALUE
,
2142 "xml:id : attribute value %s is not an NCName\n",
2143 (const char *) dup
, NULL
);
2147 xmlAddID(&ctxt
->vctxt
, ctxt
->myDoc
, dup
, ret
);
2148 } else if (xmlIsID(ctxt
->myDoc
, ctxt
->node
, ret
)) {
2149 /* might be worth duplicate entry points and not copy */
2151 dup
= xmlStrndup(value
, valueend
- value
);
2152 xmlAddID(&ctxt
->vctxt
, ctxt
->myDoc
, dup
, ret
);
2153 } else if (xmlIsRef(ctxt
->myDoc
, ctxt
->node
, ret
)) {
2155 dup
= xmlStrndup(value
, valueend
- value
);
2156 xmlAddRef(&ctxt
->vctxt
, ctxt
->myDoc
, dup
, ret
);
2164 * xmlSAX2StartElementNs:
2165 * @ctx: the user data (XML parser context)
2166 * @localname: the local name of the element
2167 * @prefix: the element namespace prefix if available
2168 * @URI: the element namespace name if available
2169 * @nb_namespaces: number of namespace definitions on that node
2170 * @namespaces: pointer to the array of prefix/URI pairs namespace definitions
2171 * @nb_attributes: the number of attributes on that node
2172 * @nb_defaulted: the number of defaulted attributes.
2173 * @attributes: pointer to the array of (localname/prefix/URI/value/end)
2176 * SAX2 callback when an element start has been detected by the parser.
2177 * It provides the namespace information for the element, as well as
2178 * the new namespace declarations on the element.
2181 xmlSAX2StartElementNs(void *ctx
,
2182 const xmlChar
*localname
,
2183 const xmlChar
*prefix
,
2186 const xmlChar
**namespaces
,
2189 const xmlChar
**attributes
)
2191 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
2194 xmlNsPtr last
= NULL
, ns
;
2195 const xmlChar
*uri
, *pref
;
2196 xmlChar
*lname
= NULL
;
2199 if (ctx
== NULL
) return;
2200 parent
= ctxt
->node
;
2202 * First check on validity:
2204 if (ctxt
->validate
&& (ctxt
->myDoc
->extSubset
== NULL
) &&
2205 ((ctxt
->myDoc
->intSubset
== NULL
) ||
2206 ((ctxt
->myDoc
->intSubset
->notations
== NULL
) &&
2207 (ctxt
->myDoc
->intSubset
->elements
== NULL
) &&
2208 (ctxt
->myDoc
->intSubset
->attributes
== NULL
) &&
2209 (ctxt
->myDoc
->intSubset
->entities
== NULL
)))) {
2210 xmlErrValid(ctxt
, XML_DTD_NO_DTD
,
2211 "Validation failed: no DTD found !", NULL
, NULL
);
2216 * Take care of the rare case of an undefined namespace prefix
2218 if ((prefix
!= NULL
) && (URI
== NULL
)) {
2219 if (ctxt
->dictNames
) {
2220 const xmlChar
*fullname
;
2222 fullname
= xmlDictQLookup(ctxt
->dict
, prefix
, localname
);
2223 if (fullname
!= NULL
)
2224 localname
= fullname
;
2226 lname
= xmlBuildQName(localname
, prefix
, NULL
, 0);
2232 if (ctxt
->freeElems
!= NULL
) {
2233 ret
= ctxt
->freeElems
;
2234 ctxt
->freeElems
= ret
->next
;
2235 ctxt
->freeElemsNr
--;
2236 memset(ret
, 0, sizeof(xmlNode
));
2237 ret
->doc
= ctxt
->myDoc
;
2238 ret
->type
= XML_ELEMENT_NODE
;
2240 if (ctxt
->dictNames
)
2241 ret
->name
= localname
;
2244 ret
->name
= xmlStrdup(localname
);
2247 if (ret
->name
== NULL
) {
2248 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElementNs");
2252 if ((__xmlRegisterCallbacks
) && (xmlRegisterNodeDefaultValue
))
2253 xmlRegisterNodeDefaultValue(ret
);
2255 if (ctxt
->dictNames
)
2256 ret
= xmlNewDocNodeEatName(ctxt
->myDoc
, NULL
,
2257 (xmlChar
*) localname
, NULL
);
2258 else if (lname
== NULL
)
2259 ret
= xmlNewDocNode(ctxt
->myDoc
, NULL
, localname
, NULL
);
2261 ret
= xmlNewDocNodeEatName(ctxt
->myDoc
, NULL
,
2262 (xmlChar
*) lname
, NULL
);
2264 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElementNs");
2268 if (ctxt
->linenumbers
) {
2269 if (ctxt
->input
!= NULL
) {
2270 if (ctxt
->input
->line
< USHRT_MAX
)
2271 ret
->line
= (unsigned short) ctxt
->input
->line
;
2273 ret
->line
= USHRT_MAX
;
2277 if (parent
== NULL
) {
2278 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
, (xmlNodePtr
) ret
);
2281 * Build the namespace list
2283 for (i
= 0,j
= 0;j
< nb_namespaces
;j
++) {
2284 pref
= namespaces
[i
++];
2285 uri
= namespaces
[i
++];
2286 ns
= xmlNewNs(NULL
, uri
, pref
);
2289 ret
->nsDef
= last
= ns
;
2294 if ((URI
!= NULL
) && (prefix
== pref
))
2298 * any out of memory error would already have been raised
2299 * but we can't be guaranteed it's the actual error due to the
2300 * API, best is to skip in this case
2304 #ifdef LIBXML_VALID_ENABLED
2305 if ((!ctxt
->html
) && ctxt
->validate
&& ctxt
->wellFormed
&&
2306 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
) {
2307 ctxt
->valid
&= xmlValidateOneNamespace(&ctxt
->vctxt
, ctxt
->myDoc
,
2308 ret
, prefix
, ns
, uri
);
2310 #endif /* LIBXML_VALID_ENABLED */
2315 * We are parsing a new node.
2317 if (nodePush(ctxt
, ret
) < 0) {
2324 * Link the child element
2326 if (parent
!= NULL
) {
2327 if (parent
->type
== XML_ELEMENT_NODE
) {
2328 xmlAddChild(parent
, ret
);
2330 xmlAddSibling(parent
, ret
);
2335 * Insert the defaulted attributes from the DTD only if requested:
2337 if ((nb_defaulted
!= 0) &&
2338 ((ctxt
->loadsubset
& XML_COMPLETE_ATTRS
) == 0))
2339 nb_attributes
-= nb_defaulted
;
2342 * Search the namespace if it wasn't already found
2343 * Note that, if prefix is NULL, this searches for the default Ns
2345 if ((URI
!= NULL
) && (ret
->ns
== NULL
)) {
2346 ret
->ns
= xmlSearchNs(ctxt
->myDoc
, parent
, prefix
);
2347 if ((ret
->ns
== NULL
) && (xmlStrEqual(prefix
, BAD_CAST
"xml"))) {
2348 ret
->ns
= xmlSearchNs(ctxt
->myDoc
, ret
, prefix
);
2350 if (ret
->ns
== NULL
) {
2351 ns
= xmlNewNs(ret
, NULL
, prefix
);
2354 xmlSAX2ErrMemory(ctxt
, "xmlSAX2StartElementNs");
2358 xmlNsWarnMsg(ctxt
, XML_NS_ERR_UNDEFINED_NAMESPACE
,
2359 "Namespace prefix %s was not found\n",
2362 xmlNsWarnMsg(ctxt
, XML_NS_ERR_UNDEFINED_NAMESPACE
,
2363 "Namespace default prefix was not found\n",
2369 * process all the other attributes
2371 if (nb_attributes
> 0) {
2372 for (j
= 0,i
= 0;i
< nb_attributes
;i
++,j
+=5) {
2374 * Handle the rare case of an undefined attribute prefix
2376 if ((attributes
[j
+1] != NULL
) && (attributes
[j
+2] == NULL
)) {
2377 if (ctxt
->dictNames
) {
2378 const xmlChar
*fullname
;
2380 fullname
= xmlDictQLookup(ctxt
->dict
, attributes
[j
+1],
2382 if (fullname
!= NULL
) {
2383 xmlSAX2AttributeNs(ctxt
, fullname
, NULL
,
2384 attributes
[j
+3], attributes
[j
+4]);
2388 lname
= xmlBuildQName(attributes
[j
], attributes
[j
+1],
2390 if (lname
!= NULL
) {
2391 xmlSAX2AttributeNs(ctxt
, lname
, NULL
,
2392 attributes
[j
+3], attributes
[j
+4]);
2398 xmlSAX2AttributeNs(ctxt
, attributes
[j
], attributes
[j
+1],
2399 attributes
[j
+3], attributes
[j
+4]);
2403 #ifdef LIBXML_VALID_ENABLED
2405 * If it's the Document root, finish the DTD validation and
2406 * check the document root element for validity
2408 if ((ctxt
->validate
) && (ctxt
->vctxt
.finishDtd
== XML_CTXT_FINISH_DTD_0
)) {
2411 chk
= xmlValidateDtdFinal(&ctxt
->vctxt
, ctxt
->myDoc
);
2415 ctxt
->wellFormed
= 0;
2416 ctxt
->valid
&= xmlValidateRoot(&ctxt
->vctxt
, ctxt
->myDoc
);
2417 ctxt
->vctxt
.finishDtd
= XML_CTXT_FINISH_DTD_1
;
2419 #endif /* LIBXML_VALID_ENABLED */
2423 * xmlSAX2EndElementNs:
2424 * @ctx: the user data (XML parser context)
2425 * @localname: the local name of the element
2426 * @prefix: the element namespace prefix if available
2427 * @URI: the element namespace name if available
2429 * SAX2 callback when an element end has been detected by the parser.
2430 * It provides the namespace information for the element.
2433 xmlSAX2EndElementNs(void *ctx
,
2434 const xmlChar
* localname ATTRIBUTE_UNUSED
,
2435 const xmlChar
* prefix ATTRIBUTE_UNUSED
,
2436 const xmlChar
* URI ATTRIBUTE_UNUSED
)
2438 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
2439 xmlParserNodeInfo node_info
;
2442 if (ctx
== NULL
) return;
2444 /* Capture end position and add node */
2445 if ((ctxt
->record_info
) && (cur
!= NULL
)) {
2446 node_info
.end_pos
= ctxt
->input
->cur
- ctxt
->input
->base
;
2447 node_info
.end_line
= ctxt
->input
->line
;
2448 node_info
.node
= cur
;
2449 xmlParserAddNodeInfo(ctxt
, &node_info
);
2453 #ifdef LIBXML_VALID_ENABLED
2454 if (ctxt
->validate
&& ctxt
->wellFormed
&&
2455 ctxt
->myDoc
&& ctxt
->myDoc
->intSubset
)
2456 ctxt
->valid
&= xmlValidateOneElement(&ctxt
->vctxt
, ctxt
->myDoc
, cur
);
2457 #endif /* LIBXML_VALID_ENABLED */
2460 * end of parsing of this node.
2467 * @ctx: the user data (XML parser context)
2468 * @name: The entity name
2470 * called when an entity xmlSAX2Reference is detected.
2473 xmlSAX2Reference(void *ctx
, const xmlChar
*name
)
2475 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
2478 if (ctx
== NULL
) return;
2480 xmlGenericError(xmlGenericErrorContext
,
2481 "SAX.xmlSAX2Reference(%s)\n", name
);
2484 ret
= xmlNewCharRef(ctxt
->myDoc
, name
);
2486 ret
= xmlNewReference(ctxt
->myDoc
, name
);
2487 #ifdef DEBUG_SAX_TREE
2488 xmlGenericError(xmlGenericErrorContext
,
2489 "add xmlSAX2Reference %s to %s \n", name
, ctxt
->node
->name
);
2491 if (xmlAddChild(ctxt
->node
, ret
) == NULL
) {
2498 * @ctx: the user data (XML parser context)
2499 * @ch: a xmlChar string
2500 * @len: the number of xmlChar
2501 * @type: text or cdata
2503 * Append characters.
2506 xmlSAX2Text(xmlParserCtxtPtr ctxt
, const xmlChar
*ch
, int len
,
2507 xmlElementType type
)
2509 xmlNodePtr lastChild
;
2511 if (ctxt
== NULL
) return;
2513 xmlGenericError(xmlGenericErrorContext
,
2514 "SAX.xmlSAX2Characters(%.30s, %d)\n", ch
, len
);
2517 * Handle the data if any. If there is no child
2518 * add it as content, otherwise if the last child is text,
2519 * concatenate it, else create a new node of type text.
2522 if (ctxt
->node
== NULL
) {
2523 #ifdef DEBUG_SAX_TREE
2524 xmlGenericError(xmlGenericErrorContext
,
2525 "add chars: ctxt->node == NULL !\n");
2529 lastChild
= ctxt
->node
->last
;
2530 #ifdef DEBUG_SAX_TREE
2531 xmlGenericError(xmlGenericErrorContext
,
2532 "add chars to %s \n", ctxt
->node
->name
);
2536 * Here we needed an accelerator mechanism in case of very large
2537 * elements. Use an attribute in the structure !!!
2539 if (lastChild
== NULL
) {
2540 if (type
== XML_TEXT_NODE
)
2541 lastChild
= xmlSAX2TextNode(ctxt
, ch
, len
);
2543 lastChild
= xmlNewCDataBlock(ctxt
->myDoc
, ch
, len
);
2544 if (lastChild
!= NULL
) {
2545 ctxt
->node
->children
= lastChild
;
2546 ctxt
->node
->last
= lastChild
;
2547 lastChild
->parent
= ctxt
->node
;
2548 lastChild
->doc
= ctxt
->node
->doc
;
2549 ctxt
->nodelen
= len
;
2550 ctxt
->nodemem
= len
+ 1;
2552 xmlSAX2ErrMemory(ctxt
, "xmlSAX2Characters");
2556 int coalesceText
= (lastChild
!= NULL
) &&
2557 (lastChild
->type
== type
) &&
2558 ((type
!= XML_TEXT_NODE
) ||
2559 (lastChild
->name
== xmlStringText
));
2560 if ((coalesceText
) && (ctxt
->nodemem
!= 0)) {
2562 * The whole point of maintaining nodelen and nodemem,
2563 * xmlTextConcat is too costly, i.e. compute length,
2564 * reallocate a new buffer, move data, append ch. Here
2565 * We try to minimize realloc() uses and avoid copying
2566 * and recomputing length over and over.
2568 if (lastChild
->content
== (xmlChar
*)&(lastChild
->properties
)) {
2569 lastChild
->content
= xmlStrdup(lastChild
->content
);
2570 lastChild
->properties
= NULL
;
2571 } else if ((ctxt
->nodemem
== ctxt
->nodelen
+ 1) &&
2572 (xmlDictOwns(ctxt
->dict
, lastChild
->content
))) {
2573 lastChild
->content
= xmlStrdup(lastChild
->content
);
2575 if (lastChild
->content
== NULL
) {
2576 xmlSAX2ErrMemory(ctxt
, "xmlSAX2Characters: xmlStrdup returned NULL");
2579 if (((size_t)ctxt
->nodelen
+ (size_t)len
> XML_MAX_TEXT_LENGTH
) &&
2580 ((ctxt
->options
& XML_PARSE_HUGE
) == 0)) {
2581 xmlSAX2ErrMemory(ctxt
, "xmlSAX2Characters: huge text node");
2584 if ((size_t)ctxt
->nodelen
> SIZE_T_MAX
- (size_t)len
||
2585 (size_t)ctxt
->nodemem
+ (size_t)len
> SIZE_T_MAX
/ 2) {
2586 xmlSAX2ErrMemory(ctxt
, "xmlSAX2Characters overflow prevented");
2589 if (ctxt
->nodelen
+ len
>= ctxt
->nodemem
) {
2593 size
= ctxt
->nodemem
+ len
;
2595 newbuf
= (xmlChar
*) xmlRealloc(lastChild
->content
,size
);
2596 if (newbuf
== NULL
) {
2597 xmlSAX2ErrMemory(ctxt
, "xmlSAX2Characters");
2600 ctxt
->nodemem
= size
;
2601 lastChild
->content
= newbuf
;
2603 memcpy(&lastChild
->content
[ctxt
->nodelen
], ch
, len
);
2604 ctxt
->nodelen
+= len
;
2605 lastChild
->content
[ctxt
->nodelen
] = 0;
2606 } else if (coalesceText
) {
2607 if (xmlTextConcat(lastChild
, ch
, len
)) {
2608 xmlSAX2ErrMemory(ctxt
, "xmlSAX2Characters");
2610 if (ctxt
->node
->children
!= NULL
) {
2611 ctxt
->nodelen
= xmlStrlen(lastChild
->content
);
2612 ctxt
->nodemem
= ctxt
->nodelen
+ 1;
2615 /* Mixed content, first time */
2616 if (type
== XML_TEXT_NODE
)
2617 lastChild
= xmlSAX2TextNode(ctxt
, ch
, len
);
2619 lastChild
= xmlNewCDataBlock(ctxt
->myDoc
, ch
, len
);
2620 if (lastChild
!= NULL
) {
2621 xmlAddChild(ctxt
->node
, lastChild
);
2622 if (ctxt
->node
->children
!= NULL
) {
2623 ctxt
->nodelen
= len
;
2624 ctxt
->nodemem
= len
+ 1;
2632 * xmlSAX2Characters:
2633 * @ctx: the user data (XML parser context)
2634 * @ch: a xmlChar string
2635 * @len: the number of xmlChar
2637 * receiving some chars from the parser.
2640 xmlSAX2Characters(void *ctx
, const xmlChar
*ch
, int len
)
2642 xmlSAX2Text((xmlParserCtxtPtr
) ctx
, ch
, len
, XML_TEXT_NODE
);
2646 * xmlSAX2IgnorableWhitespace:
2647 * @ctx: the user data (XML parser context)
2648 * @ch: a xmlChar string
2649 * @len: the number of xmlChar
2651 * receiving some ignorable whitespaces from the parser.
2652 * UNUSED: by default the DOM building will use xmlSAX2Characters
2655 xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED
, const xmlChar
*ch ATTRIBUTE_UNUSED
, int len ATTRIBUTE_UNUSED
)
2657 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
2659 xmlGenericError(xmlGenericErrorContext
,
2660 "SAX.xmlSAX2IgnorableWhitespace(%.30s, %d)\n", ch
, len
);
2665 * xmlSAX2ProcessingInstruction:
2666 * @ctx: the user data (XML parser context)
2667 * @target: the target name
2668 * @data: the PI data's
2670 * A processing instruction has been parsed.
2673 xmlSAX2ProcessingInstruction(void *ctx
, const xmlChar
*target
,
2674 const xmlChar
*data
)
2676 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
2680 if (ctx
== NULL
) return;
2681 parent
= ctxt
->node
;
2683 xmlGenericError(xmlGenericErrorContext
,
2684 "SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target
, data
);
2687 ret
= xmlNewDocPI(ctxt
->myDoc
, target
, data
);
2688 if (ret
== NULL
) return;
2690 if (ctxt
->linenumbers
) {
2691 if (ctxt
->input
!= NULL
) {
2692 if (ctxt
->input
->line
< USHRT_MAX
)
2693 ret
->line
= (unsigned short) ctxt
->input
->line
;
2695 ret
->line
= USHRT_MAX
;
2698 if (ctxt
->inSubset
== 1) {
2699 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
->intSubset
, ret
);
2701 } else if (ctxt
->inSubset
== 2) {
2702 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
->extSubset
, ret
);
2705 if (parent
== NULL
) {
2706 #ifdef DEBUG_SAX_TREE
2707 xmlGenericError(xmlGenericErrorContext
,
2708 "Setting PI %s as root\n", target
);
2710 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
, (xmlNodePtr
) ret
);
2713 if (parent
->type
== XML_ELEMENT_NODE
) {
2714 #ifdef DEBUG_SAX_TREE
2715 xmlGenericError(xmlGenericErrorContext
,
2716 "adding PI %s child to %s\n", target
, parent
->name
);
2718 xmlAddChild(parent
, ret
);
2720 #ifdef DEBUG_SAX_TREE
2721 xmlGenericError(xmlGenericErrorContext
,
2722 "adding PI %s sibling to ", target
);
2723 xmlDebugDumpOneNode(stderr
, parent
, 0);
2725 xmlAddSibling(parent
, ret
);
2731 * @ctx: the user data (XML parser context)
2732 * @value: the xmlSAX2Comment content
2734 * A xmlSAX2Comment has been parsed.
2737 xmlSAX2Comment(void *ctx
, const xmlChar
*value
)
2739 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
2743 if (ctx
== NULL
) return;
2744 parent
= ctxt
->node
;
2746 xmlGenericError(xmlGenericErrorContext
, "SAX.xmlSAX2Comment(%s)\n", value
);
2748 ret
= xmlNewDocComment(ctxt
->myDoc
, value
);
2749 if (ret
== NULL
) return;
2750 if (ctxt
->linenumbers
) {
2751 if (ctxt
->input
!= NULL
) {
2752 if (ctxt
->input
->line
< USHRT_MAX
)
2753 ret
->line
= (unsigned short) ctxt
->input
->line
;
2755 ret
->line
= USHRT_MAX
;
2759 if (ctxt
->inSubset
== 1) {
2760 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
->intSubset
, ret
);
2762 } else if (ctxt
->inSubset
== 2) {
2763 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
->extSubset
, ret
);
2766 if (parent
== NULL
) {
2767 #ifdef DEBUG_SAX_TREE
2768 xmlGenericError(xmlGenericErrorContext
,
2769 "Setting xmlSAX2Comment as root\n");
2771 xmlAddChild((xmlNodePtr
) ctxt
->myDoc
, (xmlNodePtr
) ret
);
2774 if (parent
->type
== XML_ELEMENT_NODE
) {
2775 #ifdef DEBUG_SAX_TREE
2776 xmlGenericError(xmlGenericErrorContext
,
2777 "adding xmlSAX2Comment child to %s\n", parent
->name
);
2779 xmlAddChild(parent
, ret
);
2781 #ifdef DEBUG_SAX_TREE
2782 xmlGenericError(xmlGenericErrorContext
,
2783 "adding xmlSAX2Comment sibling to ");
2784 xmlDebugDumpOneNode(stderr
, parent
, 0);
2786 xmlAddSibling(parent
, ret
);
2791 * xmlSAX2CDataBlock:
2792 * @ctx: the user data (XML parser context)
2793 * @value: The pcdata content
2794 * @len: the block length
2796 * called when a pcdata block has been parsed
2799 xmlSAX2CDataBlock(void *ctx
, const xmlChar
*value
, int len
)
2801 xmlSAX2Text((xmlParserCtxtPtr
) ctx
, value
, len
, XML_CDATA_SECTION_NODE
);
2804 static int xmlSAX2DefaultVersionValue
= 2;
2806 #ifdef LIBXML_SAX1_ENABLED
2808 * xmlSAXDefaultVersion:
2809 * @version: the version, 1 or 2
2811 * Set the default version of SAX used globally by the library.
2812 * By default, during initialization the default is set to 2.
2813 * Note that it is generally a better coding style to use
2814 * xmlSAXVersion() to set up the version explicitly for a given
2817 * Returns the previous value in case of success and -1 in case of error.
2820 xmlSAXDefaultVersion(int version
)
2822 int ret
= xmlSAX2DefaultVersionValue
;
2824 if ((version
!= 1) && (version
!= 2))
2826 xmlSAX2DefaultVersionValue
= version
;
2829 #endif /* LIBXML_SAX1_ENABLED */
2833 * @hdlr: the SAX handler
2834 * @version: the version, 1 or 2
2836 * Initialize the default XML SAX handler according to the version
2838 * Returns 0 in case of success and -1 in case of error.
2841 xmlSAXVersion(xmlSAXHandler
*hdlr
, int version
)
2843 if (hdlr
== NULL
) return(-1);
2845 hdlr
->startElement
= NULL
;
2846 hdlr
->endElement
= NULL
;
2847 hdlr
->startElementNs
= xmlSAX2StartElementNs
;
2848 hdlr
->endElementNs
= xmlSAX2EndElementNs
;
2849 hdlr
->serror
= NULL
;
2850 hdlr
->initialized
= XML_SAX2_MAGIC
;
2851 #ifdef LIBXML_SAX1_ENABLED
2852 } else if (version
== 1) {
2853 hdlr
->startElement
= xmlSAX2StartElement
;
2854 hdlr
->endElement
= xmlSAX2EndElement
;
2855 hdlr
->initialized
= 1;
2856 #endif /* LIBXML_SAX1_ENABLED */
2859 hdlr
->internalSubset
= xmlSAX2InternalSubset
;
2860 hdlr
->externalSubset
= xmlSAX2ExternalSubset
;
2861 hdlr
->isStandalone
= xmlSAX2IsStandalone
;
2862 hdlr
->hasInternalSubset
= xmlSAX2HasInternalSubset
;
2863 hdlr
->hasExternalSubset
= xmlSAX2HasExternalSubset
;
2864 hdlr
->resolveEntity
= xmlSAX2ResolveEntity
;
2865 hdlr
->getEntity
= xmlSAX2GetEntity
;
2866 hdlr
->getParameterEntity
= xmlSAX2GetParameterEntity
;
2867 hdlr
->entityDecl
= xmlSAX2EntityDecl
;
2868 hdlr
->attributeDecl
= xmlSAX2AttributeDecl
;
2869 hdlr
->elementDecl
= xmlSAX2ElementDecl
;
2870 hdlr
->notationDecl
= xmlSAX2NotationDecl
;
2871 hdlr
->unparsedEntityDecl
= xmlSAX2UnparsedEntityDecl
;
2872 hdlr
->setDocumentLocator
= xmlSAX2SetDocumentLocator
;
2873 hdlr
->startDocument
= xmlSAX2StartDocument
;
2874 hdlr
->endDocument
= xmlSAX2EndDocument
;
2875 hdlr
->reference
= xmlSAX2Reference
;
2876 hdlr
->characters
= xmlSAX2Characters
;
2877 hdlr
->cdataBlock
= xmlSAX2CDataBlock
;
2878 hdlr
->ignorableWhitespace
= xmlSAX2Characters
;
2879 hdlr
->processingInstruction
= xmlSAX2ProcessingInstruction
;
2880 hdlr
->comment
= xmlSAX2Comment
;
2881 hdlr
->warning
= xmlParserWarning
;
2882 hdlr
->error
= xmlParserError
;
2883 hdlr
->fatalError
= xmlParserError
;
2889 * xmlSAX2InitDefaultSAXHandler:
2890 * @hdlr: the SAX handler
2891 * @warning: flag if non-zero sets the handler warning procedure
2893 * Initialize the default XML SAX2 handler
2896 xmlSAX2InitDefaultSAXHandler(xmlSAXHandler
*hdlr
, int warning
)
2898 if ((hdlr
== NULL
) || (hdlr
->initialized
!= 0))
2901 xmlSAXVersion(hdlr
, xmlSAX2DefaultVersionValue
);
2903 hdlr
->warning
= NULL
;
2905 hdlr
->warning
= xmlParserWarning
;
2909 * xmlDefaultSAXHandlerInit:
2911 * Initialize the default SAX2 handler
2914 xmlDefaultSAXHandlerInit(void)
2916 #ifdef LIBXML_SAX1_ENABLED
2917 xmlSAXVersion((xmlSAXHandlerPtr
) &xmlDefaultSAXHandler
, 1);
2918 #endif /* LIBXML_SAX1_ENABLED */
2921 #ifdef LIBXML_HTML_ENABLED
2924 * xmlSAX2InitHtmlDefaultSAXHandler:
2925 * @hdlr: the SAX handler
2927 * Initialize the default HTML SAX2 handler
2930 xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler
*hdlr
)
2932 if ((hdlr
== NULL
) || (hdlr
->initialized
!= 0))
2935 hdlr
->internalSubset
= xmlSAX2InternalSubset
;
2936 hdlr
->externalSubset
= NULL
;
2937 hdlr
->isStandalone
= NULL
;
2938 hdlr
->hasInternalSubset
= NULL
;
2939 hdlr
->hasExternalSubset
= NULL
;
2940 hdlr
->resolveEntity
= NULL
;
2941 hdlr
->getEntity
= xmlSAX2GetEntity
;
2942 hdlr
->getParameterEntity
= NULL
;
2943 hdlr
->entityDecl
= NULL
;
2944 hdlr
->attributeDecl
= NULL
;
2945 hdlr
->elementDecl
= NULL
;
2946 hdlr
->notationDecl
= NULL
;
2947 hdlr
->unparsedEntityDecl
= NULL
;
2948 hdlr
->setDocumentLocator
= xmlSAX2SetDocumentLocator
;
2949 hdlr
->startDocument
= xmlSAX2StartDocument
;
2950 hdlr
->endDocument
= xmlSAX2EndDocument
;
2951 hdlr
->startElement
= xmlSAX2StartElement
;
2952 hdlr
->endElement
= xmlSAX2EndElement
;
2953 hdlr
->reference
= NULL
;
2954 hdlr
->characters
= xmlSAX2Characters
;
2955 hdlr
->cdataBlock
= xmlSAX2CDataBlock
;
2956 hdlr
->ignorableWhitespace
= xmlSAX2IgnorableWhitespace
;
2957 hdlr
->processingInstruction
= xmlSAX2ProcessingInstruction
;
2958 hdlr
->comment
= xmlSAX2Comment
;
2959 hdlr
->warning
= xmlParserWarning
;
2960 hdlr
->error
= xmlParserError
;
2961 hdlr
->fatalError
= xmlParserError
;
2963 hdlr
->initialized
= 1;
2967 * htmlDefaultSAXHandlerInit:
2969 * Initialize the default SAX handler
2972 htmlDefaultSAXHandlerInit(void)
2974 xmlSAX2InitHtmlDefaultSAXHandler((xmlSAXHandlerPtr
) &htmlDefaultSAXHandler
);
2977 #endif /* LIBXML_HTML_ENABLED */
2979 #ifdef LIBXML_DOCB_ENABLED
2982 * xmlSAX2InitDocbDefaultSAXHandler:
2983 * @hdlr: the SAX handler
2985 * Initialize the default DocBook SAX2 handler
2988 xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler
*hdlr
)
2990 if ((hdlr
== NULL
) || (hdlr
->initialized
!= 0))
2993 hdlr
->internalSubset
= xmlSAX2InternalSubset
;
2994 hdlr
->externalSubset
= NULL
;
2995 hdlr
->isStandalone
= xmlSAX2IsStandalone
;
2996 hdlr
->hasInternalSubset
= xmlSAX2HasInternalSubset
;
2997 hdlr
->hasExternalSubset
= xmlSAX2HasExternalSubset
;
2998 hdlr
->resolveEntity
= xmlSAX2ResolveEntity
;
2999 hdlr
->getEntity
= xmlSAX2GetEntity
;
3000 hdlr
->getParameterEntity
= NULL
;
3001 hdlr
->entityDecl
= xmlSAX2EntityDecl
;
3002 hdlr
->attributeDecl
= NULL
;
3003 hdlr
->elementDecl
= NULL
;
3004 hdlr
->notationDecl
= NULL
;
3005 hdlr
->unparsedEntityDecl
= NULL
;
3006 hdlr
->setDocumentLocator
= xmlSAX2SetDocumentLocator
;
3007 hdlr
->startDocument
= xmlSAX2StartDocument
;
3008 hdlr
->endDocument
= xmlSAX2EndDocument
;
3009 hdlr
->startElement
= xmlSAX2StartElement
;
3010 hdlr
->endElement
= xmlSAX2EndElement
;
3011 hdlr
->reference
= xmlSAX2Reference
;
3012 hdlr
->characters
= xmlSAX2Characters
;
3013 hdlr
->cdataBlock
= NULL
;
3014 hdlr
->ignorableWhitespace
= xmlSAX2IgnorableWhitespace
;
3015 hdlr
->processingInstruction
= NULL
;
3016 hdlr
->comment
= xmlSAX2Comment
;
3017 hdlr
->warning
= xmlParserWarning
;
3018 hdlr
->error
= xmlParserError
;
3019 hdlr
->fatalError
= xmlParserError
;
3021 hdlr
->initialized
= 1;
3025 * docbDefaultSAXHandlerInit:
3027 * Initialize the default SAX handler
3030 docbDefaultSAXHandlerInit(void)
3032 xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr
) &docbDefaultSAXHandler
);
3035 #endif /* LIBXML_DOCB_ENABLED */
3037 #include "elfgcchack.h"