diff --git a/ChangeLog b/ChangeLog index 65145b34..199ccd8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed May 30 20:30:47 CEST 2001 Daniel Veillard + + * HTMLtree.c: applied patch from Jaroslaw Kolakowski to close bug + #55380 + * tree.c: patch to xmlNodeGetContent() to get CDATA section content + Mon May 28 12:56:29 CEST 2001 Daniel Veillard * TODO: updated diff --git a/HTMLtree.c b/HTMLtree.c index 626a8212..e61ce2b9 100644 --- a/HTMLtree.c +++ b/HTMLtree.c @@ -662,34 +662,77 @@ htmlDocContentDump(xmlBufferPtr buf, xmlDocPtr cur) { * htmlDocDumpMemory: * @cur: the document * @mem: OUT: the memory pointer - * @size: OUT: the memory lenght + * @size: OUT: the memory length * * Dump an HTML document in memory and return the xmlChar * and it's size. * It's up to the caller to free the memory. */ void htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { - xmlBufferPtr buf; + xmlOutputBufferPtr buf; + xmlCharEncodingHandlerPtr handler = NULL; + const char *encoding; if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, - "htmlxmlDocDumpMemory : document == NULL\n"); + "htmlDocDumpMemory : document == NULL\n"); #endif *mem = NULL; *size = 0; return; } - buf = xmlBufferCreate(); + + encoding = (const char *) htmlGetMetaEncoding(cur); + + if (encoding != NULL) { + xmlCharEncoding enc; + + enc = xmlParseCharEncoding(encoding); + if (enc != cur->charset) { + if (cur->charset != XML_CHAR_ENCODING_UTF8) { + /* + * Not supported yet + */ + *mem = NULL; + *size = 0; + return; + } + + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + *mem = NULL; + *size = 0; + return; + } + } + } + + /* + * Fallback to HTML or ASCII when the encoding is unspecified + */ + if (handler == NULL) + handler = xmlFindCharEncodingHandler("HTML"); + if (handler == NULL) + handler = xmlFindCharEncodingHandler("ascii"); + + buf = xmlAllocOutputBuffer(handler); if (buf == NULL) { *mem = NULL; *size = 0; return; } - htmlDocContentDump(buf, cur); - *mem = buf->content; - *size = buf->use; - xmlFree(buf); + + htmlDocContentDumpOutput(buf, cur, NULL); + xmlOutputBufferFlush(buf); + if (buf->conv != NULL) { + *size = buf->conv->use; + *mem = xmlStrndup(buf->conv->content, *size); + } else { + *size = buf->buffer->use; + *mem = xmlStrndup(buf->buffer->content, *size); + } + (void)xmlOutputBufferClose(buf); } diff --git a/tree.c b/tree.c index 4b32f924..99afb61f 100644 --- a/tree.c +++ b/tree.c @@ -3308,6 +3308,7 @@ xmlNodeGetContent(xmlNodePtr cur) { while (tmp != NULL) { switch (tmp->type) { case XML_ELEMENT_NODE: + case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: if (tmp->content != NULL) #ifndef XML_USE_BUFFER_CONTENT