mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
html: Move DTD creation to endDocument SAX callback
This commit is contained in:
27
HTMLparser.c
27
HTMLparser.c
@@ -4331,8 +4331,6 @@ htmlCtxtParseContentInternal(htmlParserCtxtPtr ctxt, xmlParserInputPtr input) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
htmlParseDocument(htmlParserCtxtPtr ctxt) {
|
htmlParseDocument(htmlParserCtxtPtr ctxt) {
|
||||||
xmlDtdPtr dtd;
|
|
||||||
|
|
||||||
if ((ctxt == NULL) || (ctxt->input == NULL))
|
if ((ctxt == NULL) || (ctxt->input == NULL))
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
@@ -4429,17 +4427,6 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
|
|||||||
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
||||||
ctxt->sax->endDocument(ctxt->userData);
|
ctxt->sax->endDocument(ctxt->userData);
|
||||||
|
|
||||||
if ((!(ctxt->options & HTML_PARSE_NODEFDTD)) && (ctxt->myDoc != NULL)) {
|
|
||||||
dtd = xmlGetIntSubset(ctxt->myDoc);
|
|
||||||
if (dtd == NULL) {
|
|
||||||
ctxt->myDoc->intSubset =
|
|
||||||
xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html",
|
|
||||||
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
|
|
||||||
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
|
|
||||||
if (ctxt->myDoc->intSubset == NULL)
|
|
||||||
htmlErrMemory(ctxt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! ctxt->wellFormed) return(-1);
|
if (! ctxt->wellFormed) return(-1);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
@@ -5158,20 +5145,6 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
|
|||||||
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
||||||
ctxt->sax->endDocument(ctxt->userData);
|
ctxt->sax->endDocument(ctxt->userData);
|
||||||
|
|
||||||
if ((!(ctxt->options & HTML_PARSE_NODEFDTD)) &&
|
|
||||||
(ctxt->myDoc != NULL)) {
|
|
||||||
xmlDtdPtr dtd;
|
|
||||||
dtd = xmlGetIntSubset(ctxt->myDoc);
|
|
||||||
if (dtd == NULL) {
|
|
||||||
ctxt->myDoc->intSubset =
|
|
||||||
xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html",
|
|
||||||
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
|
|
||||||
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
|
|
||||||
if (ctxt->myDoc->intSubset == NULL)
|
|
||||||
htmlErrMemory(ctxt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctxt->instate = XML_PARSER_EOF;
|
ctxt->instate = XML_PARSER_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
SAX2.c
17
SAX2.c
@@ -837,7 +837,10 @@ xmlSAX2EndDocument(void *ctx)
|
|||||||
#endif /* LIBXML_VALID_ENABLED */
|
#endif /* LIBXML_VALID_ENABLED */
|
||||||
|
|
||||||
doc = ctxt->myDoc;
|
doc = ctxt->myDoc;
|
||||||
if ((doc != NULL) && (doc->encoding == NULL)) {
|
if (doc == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (doc->encoding == NULL) {
|
||||||
const xmlChar *encoding = xmlGetActualEncoding(ctxt);
|
const xmlChar *encoding = xmlGetActualEncoding(ctxt);
|
||||||
|
|
||||||
if (encoding != NULL) {
|
if (encoding != NULL) {
|
||||||
@@ -846,6 +849,18 @@ xmlSAX2EndDocument(void *ctx)
|
|||||||
xmlSAX2ErrMemory(ctxt);
|
xmlSAX2ErrMemory(ctxt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LIBXML_HTML_ENABLED
|
||||||
|
if ((ctxt->html) &&
|
||||||
|
((ctxt->options & HTML_PARSE_NODEFDTD) == 0) &&
|
||||||
|
(doc->intSubset == NULL)) {
|
||||||
|
doc->intSubset = xmlCreateIntSubset(doc, BAD_CAST "html",
|
||||||
|
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
|
||||||
|
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
|
||||||
|
if (doc->intSubset == NULL)
|
||||||
|
xmlSAX2ErrMemory(ctxt);
|
||||||
|
}
|
||||||
|
#endif /* LIBXML_HTML_ENABLED */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user