Commit a6d8eb62 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

Finally had a bit of time to resynch both trees:

- HTMLparser.[ch]: added a way to avoid adding automatically
  omitted tags. htmlHandleOmittedElem() allows to change the
  default handling.
- tree.[ch] xmllint.c: added xmlDocDumpFormatMemory() and
  xmlDocDumpFormatMemoryEnc(), uses memory functions for output
  of xmllint too when using --memory flag, added a memory test
  suite at the Makefile level.
- xpathInternals.h xpath.[ch] xpointer.c: fixed problems
  with namespace use when encountering QNames in XPath evalation,
  added xmlns() scheme in XPointer.
- nanoftp.c : incorporated a fix
- parser.c xmlIO.c: fixed problems raised with encoding when using
  the memory I/O
- parserInternals.c: closed bug 25934 reported by
  torsten.landschoff@innominate.de
- TODO: updated
Daniel
parent a1fe9104
Wed Dec 27 12:35:49 CET 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* HTMLparser.[ch]: added a way to avoid adding automatically
omitted tags. htmlHandleOmittedElem() allows to change the
default handling.
* tree.[ch] xmllint.c: added xmlDocDumpFormatMemory() and
xmlDocDumpFormatMemoryEnc(), uses memory functions for output
of xmllint too when using --memory flag, added a memory test
suite at the Makefile level.
* xpathInternals.h xpath.[ch] xpointer.c: fixed problems
with namespace use when encountering QNames in XPath evalation,
added xmlns() scheme in XPointer.
* nanoftp.c : incorporated a fix
* parser.c xmlIO.c: fixed problems raised with encoding when using
the memory I/O
* parserInternals.c: closed bug 25934 reported by
torsten.landschoff@innominate.de
* TODO: updated
Sat Nov 25 11:46:27 CET 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* configure.in doc/html/* doc/xml.html: made a 2.2.9 release
......
......@@ -53,6 +53,8 @@
/* #define DEBUG */
/* #define DEBUG_PUSH */
int htmlOmittedDefaultValue = 1;
/************************************************************************
* *
* Parser stacks related functions and macros *
......@@ -837,12 +839,14 @@ htmlIsAutoClosed(htmlDocPtr doc, htmlNodePtr elem) {
* @ctxt: an HTML parser context
* @newtag: The new tag name
*
* The HTmL DtD allows a tag to exists only implicitely
* The HTML DtD allows a tag to exists only implicitely
* called when a new tag has been detected and generates the
* appropriates implicit tags if missing
*/
void
htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) {
if (!htmlOmittedDefaultValue)
return;
if (xmlStrEqual(newtag, BAD_CAST"html"))
return;
if (ctxt->nameNr <= 0) {
......@@ -2787,6 +2791,10 @@ htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) {
if ((ctxt == NULL) || (attvalue == NULL))
return;
/* do not change encoding */
if (ctxt->input->encoding != NULL)
return;
encoding = xmlStrcasestr(attvalue, BAD_CAST"charset=");
if (encoding != NULL) {
encoding += 8;
......@@ -4822,6 +4830,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
htmlParserInputPtr inputStream;
xmlParserInputBufferPtr buf;
/* htmlCharEncoding enc; */
xmlChar *content, *content_line = (xmlChar *) "charset=";
buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
if (buf == NULL) return(NULL);
......@@ -4852,6 +4861,18 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
inputStream->free = NULL;
inputPush(ctxt, inputStream);
/* set encoding */
if (encoding) {
content = xmlMalloc (xmlStrlen(content_line) + strlen(encoding) + 1);
if (content) {
strcpy ((char *)content, (char *)content_line);
strcat ((char *)content, (char *)encoding);
htmlCheckEncoding (ctxt, content);
xmlFree (content);
}
}
return(ctxt);
}
......@@ -4913,4 +4934,21 @@ htmlParseFile(const char *filename, const char *encoding) {
return(htmlSAXParseFile(filename, encoding, NULL, NULL));
}
/**
* htmlHandleOmittedElem:
* @val: int 0 or 1
*
* Set and return the previous value for handling HTML omitted tags.
*
* Returns the last value for 0 for no handling, 1 for auto insertion.
*/
int
htmlHandleOmittedElem(int val) {
int old = htmlOmittedDefaultValue;
htmlOmittedDefaultValue = val;
return(old);
}
#endif /* LIBXML_HTML_ENABLED */
......@@ -91,6 +91,7 @@ int htmlEncodeEntities(unsigned char* out,
const unsigned char* in,
int *inlen, int quoteChar);
int htmlIsScriptAttribute(const xmlChar *name);
int htmlHandleOmittedElem(int val);
/**
* Interfaces for the Push mode
......
......@@ -179,6 +179,24 @@ XMLtests : xmllint
diff result.$$name result2.$$name ; \
rm result.$$name result2.$$name ; \
fi ; fi ; done)
@echo "##"
@echo "## XML regression tests on memory"
@echo "##"
@(for i in $(srcdir)/test/* ; do \
name=`basename $$i`; \
if [ ! -d $$i ] ; then \
if [ ! -f $(srcdir)/result/$$name ] ; then \
echo New test file $$name ; \
$(top_builddir)/xmllint --memory $$i > $(srcdir)/result/$$name ; \
else \
echo Testing $$name ; \
$(top_builddir)/xmllint --memory $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/$$name result.$$name ; \
$(top_builddir)/xmllint --memory result.$$name > result2.$$name ; \
diff result.$$name result2.$$name ; \
rm result.$$name result2.$$name ; \
fi ; fi ; done)
XMLenttests : xmllint
@echo "##"
......
......@@ -32,6 +32,9 @@ TODO:
- jamesh suggestion: SAX like functions to save a document ie. call a
function to open a new element with given attributes, write character
data, close last element, etc
- htmlParseDoc has parameter encoding which is not used.
Function htmlCreateDocParserCtxt ignore it.
TODO:
=====
......
......@@ -620,31 +620,35 @@ esac
])
# AC_LIBLTDL_CONVENIENCE[(dir)] - sets LIBLTDL to the link flags for
# the libltdl convenience library, adds --enable-ltdl-convenience to
# the configure arguments. Note that LIBLTDL is not AC_SUBSTed, nor
# is AC_CONFIG_SUBDIRS called. If DIR is not provided, it is assumed
# to be `${top_builddir}/libltdl'. Make sure you start DIR with
# '${top_builddir}/' (note the single quotes!) if your package is not
# flat, and, if you're not using automake, define top_builddir as
# appropriate in the Makefiles.
# the libltdl convenience library and INCLTDL to the include flags for
# the libltdl header and adds --enable-ltdl-convenience to the
# configure arguments. Note that LIBLTDL and INCLTDL are not
# AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If DIR is not
# provided, it is assumed to be `libltdl'. LIBLTDL will be prefixed
# with '${top_builddir}/' and INCLTDL will be prefixed with
# '${top_srcdir}/' (note the single quotes!). If your package is not
# flat and you're not using automake, define top_builddir and
# top_srcdir appropriately in the Makefiles.
AC_DEFUN(AC_LIBLTDL_CONVENIENCE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
case "$enable_ltdl_convenience" in
no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
"") enable_ltdl_convenience=yes
ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
esac
LIBLTDL=ifelse($#,1,$1,['${top_builddir}/libltdl'])/libltdlc.la
INCLTDL=ifelse($#,1,-I$1,['-I${top_builddir}/libltdl'])
LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
])
# AC_LIBLTDL_INSTALLABLE[(dir)] - sets LIBLTDL to the link flags for
# the libltdl installable library, and adds --enable-ltdl-install to
# the configure arguments. Note that LIBLTDL is not AC_SUBSTed, nor
# is AC_CONFIG_SUBDIRS called. If DIR is not provided, it is assumed
# to be `${top_builddir}/libltdl'. Make sure you start DIR with
# '${top_builddir}/' (note the single quotes!) if your package is not
# flat, and, if you're not using automake, define top_builddir as
# appropriate in the Makefiles.
# the libltdl installable library and INCLTDL to the include flags for
# the libltdl header and adds --enable-ltdl-install to the configure
# arguments. Note that LIBLTDL and INCLTDL are not AC_SUBSTed, nor is
# AC_CONFIG_SUBDIRS called. If DIR is not provided and an installed
# libltdl is not found, it is assumed to be `libltdl'. LIBLTDL will
# be prefixed with '${top_builddir}/' and INCLTDL will be prefixed
# with '${top_srcdir}/' (note the single quotes!). If your package is
# not flat and you're not using automake, define top_builddir and
# top_srcdir appropriately in the Makefiles.
# In the future, this macro may have to be called after AC_PROG_LIBTOOL.
AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
AC_CHECK_LIB(ltdl, main,
......@@ -657,8 +661,8 @@ AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
])
if test x"$enable_ltdl_install" = x"yes"; then
ac_configure_args="$ac_configure_args --enable-ltdl-install"
LIBLTDL=ifelse($#,1,$1,['${top_builddir}/libltdl'])/libltdl.la
INCLTDL=ifelse($#,1,-I$1,['-I${top_builddir}/libltdl'])
LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
else
ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
LIBLTDL="-lltdl"
......
......@@ -91,6 +91,7 @@ int htmlEncodeEntities(unsigned char* out,
const unsigned char* in,
int *inlen, int quoteChar);
int htmlIsScriptAttribute(const xmlChar *name);
int htmlHandleOmittedElem(int val);
/**
* Interfaces for the Push mode
......
......@@ -634,6 +634,10 @@ int xmlReconciliateNs (xmlDocPtr doc,
/*
* Saving
*/
void xmlDocDumpFormatMemory (xmlDocPtr cur,
xmlChar**mem,
int *size,
int format);
void xmlDocDumpMemory (xmlDocPtr cur,
xmlChar**mem,
int *size);
......@@ -641,6 +645,11 @@ void xmlDocDumpMemoryEnc (xmlDocPtr out_doc,
xmlChar **doc_txt_ptr,
int * doc_txt_len,
const char *txt_encoding);
void xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc,
xmlChar **doc_txt_ptr,
int * doc_txt_len,
const char *txt_encoding,
int format);
int xmlDocDump (FILE *f,
xmlDocPtr cur);
void xmlElemDump (FILE *f,
......
......@@ -47,7 +47,8 @@ typedef enum {
XPATH_MEMORY_ERROR,
XPTR_SYNTAX_ERROR,
XPTR_RESOURCE_ERROR,
XPTR_SUB_RESOURCE_ERROR
XPTR_SUB_RESOURCE_ERROR,
XPATH_UNDEF_PREFIX_ERROR
} xmlXPathError;
/*
......@@ -171,6 +172,8 @@ struct _xmlXPathAxis {
* - a set of variable bindings
* - a function library
* - the set of namespace declarations in scope for the expression
* Following the switch to hash tables, this need to be trimmed up at
* the next binary incompatible release.
*/
struct _xmlXPathContext {
......@@ -193,10 +196,10 @@ struct _xmlXPathContext {
int max_axis; /* max number of axis */
xmlXPathAxisPtr axis; /* Array of defined axis */
/* Namespace traversal should be implemented with user */
xmlNsPtr *namespaces; /* The namespaces lookup */
int nsNr; /* the current Namespace index */
void *user; /* user defined extra info */
/* the namespace nodes of the context node */
xmlNsPtr *namespaces; /* Array of namespaces */
int nsNr; /* number of namespace in scope */
void *user; /* function to free */
/* extra variables */
int contextSize; /* the context size */
......@@ -206,6 +209,9 @@ struct _xmlXPathContext {
int xptr; /* it this an XPointer context */
xmlNodePtr here; /* for here() */
xmlNodePtr origin; /* for origin() */
/* the set of namespace declarations in scope for the expression */
xmlHashTablePtr nsHash; /* The namespaces hash table */
};
/*
......
......@@ -68,6 +68,13 @@ void xmlXPathDebugDumpObject (FILE *output,
/**
* Extending a context
*/
int xmlXPathRegisterNs (xmlXPathContextPtr ctxt,
const xmlChar *prefix,
const xmlChar *ns_uri);
const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt,
const xmlChar *ns_uri);
void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt);
int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
const xmlChar *name,
xmlXPathFunction f);
......@@ -121,6 +128,7 @@ void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
/*
* Debug
......
......@@ -650,6 +650,9 @@ get_more:
* and analyzed.
*/
len = xmlNanoFTPGetMore(ctx);
if (len < 0) {
return(-1);
}
if ((ctxt->controlBufUsed == 0) && (len == 0)) {
return(-1);
}
......
......@@ -8189,17 +8189,23 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
if ((terminate) || (ctxt->input->buf->buffer->use > 80))
xmlParseTryOrFinish(ctxt, terminate);
} else if (ctxt->instate != XML_PARSER_EOF)
if ((ctxt->input != NULL) && ctxt->input->buf != NULL) {
xmlParserInputBufferPtr in = ctxt->input->buf;
int nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw);
if (nbchars < 0) {
xmlGenericError(xmlGenericErrorContext,
"xmlParseChunk: encoder error\n");
return(XML_ERR_INVALID_ENCODING);
}
}
xmlParseTryOrFinish(ctxt, terminate);
} else if (ctxt->instate != XML_PARSER_EOF) {
if ((ctxt->input != NULL) && ctxt->input->buf != NULL) {
xmlParserInputBufferPtr in = ctxt->input->buf;
if ((in->encoder != NULL) && (in->buffer != NULL) &&
(in->raw != NULL)) {
int nbchars;
nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw);
if (nbchars < 0) {
xmlGenericError(xmlGenericErrorContext,
"xmlParseChunk: encoder error\n");
return(XML_ERR_INVALID_ENCODING);
}
}
}
}
xmlParseTryOrFinish(ctxt, terminate);
if (terminate) {
/*
* Check for termination
......@@ -9234,6 +9240,7 @@ xmlCreateEntityParserCtxt(const xmlChar *URL, const xmlChar *ID,
} else {
inputStream = xmlLoadExternalEntity((char *)uri, (char *)ID, ctxt);
if (inputStream == NULL) {
xmlFree(uri);
xmlFreeParserCtxt(ctxt);
return(NULL);
}
......
......@@ -481,7 +481,7 @@ xmlIsBaseChar(int c) {
(((c) >= 0x06D0) && ((c) <= 0x06D3)) ||
((c) == 0x06D5) ||
(((c) >= 0x06E5) && ((c) <= 0x06E6)) ||
(((c) > 0x905) && ( /* accelerator */
(((c) >= 0x905) && ( /* accelerator */
(((c) >= 0x0905) && ((c) <= 0x0939)) ||
((c) == 0x093D) ||
(((c) >= 0x0958) && ((c) <= 0x0961)) ||
......@@ -572,7 +572,7 @@ xmlIsBaseChar(int c) {
(((c) >= 0x0EC0) && ((c) <= 0x0EC4)) ||
(((c) >= 0x0F40) && ((c) <= 0x0F47)) ||
(((c) >= 0x0F49) && ((c) <= 0x0F69)) ||
(((c) > 0x10A0) && ( /* accelerator */
(((c) >= 0x10A0) && ( /* accelerator */
(((c) >= 0x10A0) && ((c) <= 0x10C5)) ||
(((c) >= 0x10D0) && ((c) <= 0x10F6)) ||
((c) == 0x1100) ||
......@@ -697,7 +697,7 @@ xmlIsCombining(int c) {
(((c) >= 0x06E0) && ((c) <= 0x06E4)) ||
(((c) >= 0x06E7) && ((c) <= 0x06E8)) ||
(((c) >= 0x06EA) && ((c) <= 0x06ED)) ||
(((c) > 0x0901) && ( /* accelerator */
(((c) >= 0x0901) && ( /* accelerator */
(((c) >= 0x0901) && ((c) <= 0x0903)) ||
((c) == 0x093C) ||
(((c) >= 0x093E) && ((c) <= 0x094C)) ||
......@@ -713,7 +713,7 @@ xmlIsCombining(int c) {
(((c) >= 0x09CB) && ((c) <= 0x09CD)) ||
((c) == 0x09D7) ||
(((c) >= 0x09E2) && ((c) <= 0x09E3)) ||
(((c) > 0x0A02) && ( /* accelerator */
(((c) >= 0x0A02) && ( /* accelerator */
((c) == 0x0A02) ||
((c) == 0x0A3C) ||
((c) == 0x0A3E) ||
......@@ -753,7 +753,7 @@ xmlIsCombining(int c) {
(((c) >= 0x0D46) && ((c) <= 0x0D48)) ||
(((c) >= 0x0D4A) && ((c) <= 0x0D4D)) ||
((c) == 0x0D57) ||
(((c) > 0x0E31) && ( /* accelerator */
(((c) >= 0x0E31) && ( /* accelerator */
((c) == 0x0E31) ||
(((c) >= 0x0E34) && ((c) <= 0x0E3A)) ||
(((c) >= 0x0E47) && ((c) <= 0x0E4E)) ||
......
......@@ -5098,44 +5098,6 @@ xmlElemDump(FILE *f, xmlDocPtr doc, xmlNodePtr cur) {
xmlBufferFree(buf);
}
/**
* xmlDocContentDump:
* @buf: the XML buffer output
* @cur: the document
*
* Dump an XML document.
*/
static void
xmlDocContentDump(xmlBufferPtr buf, xmlDocPtr cur) {
xmlBufferWriteChar(buf, "<?xml version=");
if (cur->version != NULL)
xmlBufferWriteQuotedString(buf, cur->version);
else
xmlBufferWriteChar(buf, "\"1.0\"");
if (cur->encoding != NULL) {
xmlBufferWriteChar(buf, " encoding=");
xmlBufferWriteQuotedString(buf, cur->encoding);
}
switch (cur->standalone) {
case 0:
xmlBufferWriteChar(buf, " standalone=\"no\"");
break;
case 1:
xmlBufferWriteChar(buf, " standalone=\"yes\"");
break;
}
xmlBufferWriteChar(buf, "?>\n");
if (cur->children != NULL) {
xmlNodePtr child = cur->children;
while (child != NULL) {
xmlNodeDump(buf, cur, child, 0, 0);
xmlBufferWriteChar(buf, "\n");
child = child->next;
}
}
}
/************************************************************************
* *
* Dumping XML tree content to an I/O output buffer *
......@@ -5522,12 +5484,13 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
* @buf: the XML buffer output
* @cur: the document
* @encoding: an optional encoding string
* @format: should formatting spaces been added
*
* Dump an XML document.
*/
static void
xmlDocContentDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr cur,
const char *encoding) {
const char *encoding, int format) {
xmlOutputBufferWriteString(buf, "<?xml version=");
if (cur->version != NULL)
xmlBufferWriteQuotedString(buf->buffer, cur->version);
......@@ -5556,7 +5519,7 @@ xmlDocContentDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr cur,
xmlNodePtr child = cur->children;
while (child != NULL) {
xmlNodeDumpOutput(buf, cur, child, 0, 1, encoding);
xmlNodeDumpOutput(buf, cur, child, 0, format, encoding);
xmlOutputBufferWriteString(buf, "\n");
child = child->next;
}
......@@ -5569,46 +5532,13 @@ xmlDocContentDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr cur,
* *
************************************************************************/
/**
* xmlDocDumpMemory:
* @cur: the document
* @mem: OUT: the memory pointer
* @size: OUT: the memory lenght
*
* Dump an XML document in memory and return the xmlChar * and it's size.
* It's up to the caller to free the memory.
*/
void
xmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) {
xmlBufferPtr buf;
if (cur == NULL) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlDocDumpMemory : document == NULL\n");
#endif
*mem = NULL;
*size = 0;
return;
}
buf = xmlBufferCreate();
if (buf == NULL) {
*mem = NULL;
*size = 0;
return;
}
xmlDocContentDump(buf, cur);
*mem = xmlStrndup(buf->content, buf->use);
*size = buf->use;
xmlBufferFree(buf);
}
/**
* xmlDocDumpMemoryEnc:
* @out_doc: Document to generate XML text from
* @doc_txt_ptr: Memory pointer for allocated XML text
* @doc_txt_len: Length of the generated XML text
* @txt_encoding: Character encoding to use when generating XML text
* @format: should formatting spaces been added
*
* Dump the current DOM tree into memory using the character encoding specified
* by the caller. Note it is up to the caller of this function to free the
......@@ -5616,8 +5546,8 @@ xmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) {
*/
void
xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
int * doc_txt_len, const char * txt_encoding) {
xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
int * doc_txt_len, const char * txt_encoding, int format) {
int dummy = 0;
xmlCharEncoding doc_charset;
......@@ -5631,7 +5561,7 @@ xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
if (doc_txt_ptr == NULL) {
*doc_txt_len = 0;
xmlGenericError(xmlGenericErrorContext,
"xmlDocDumpMemoryEnc: Null return buffer pointer.");
"xmlDocDumpFormatMemoryEnc: Null return buffer pointer.");
return;
}
......@@ -5641,7 +5571,7 @@ xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
if (out_doc == NULL) {
/* No document, no output */
xmlGenericError(xmlGenericErrorContext,
"xmlDocDumpMemoryEnc: Null DOM tree document pointer.\n");
"xmlDocDumpFormatMemoryEnc: Null DOM tree document pointer.\n");
return;
}
......@@ -5650,12 +5580,14 @@ xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
* This logic is copied from xmlSaveFileEnc.
*/
if (txt_encoding == NULL)
txt_encoding = (const char *) out_doc->encoding;
if (txt_encoding != NULL) {
doc_charset = xmlParseCharEncoding(txt_encoding);
if (out_doc->charset != XML_CHAR_ENCODING_UTF8) {
xmlGenericError(xmlGenericErrorContext,
"xmlDocDumpMemoryEnc: Source document not in UTF8\n");
"xmlDocDumpFormatMemoryEnc: Source document not in UTF8\n");
return;
} else if (doc_charset != XML_CHAR_ENCODING_UTF8) {
......@@ -5663,7 +5595,7 @@ xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
if ( conv_hdlr == NULL ) {
xmlGenericError(xmlGenericErrorContext,
"%s: %s %s '%s'\n",
"xmlDocDumpMemoryEnc",
"xmlDocDumpFormatMemoryEnc",
"Failed to identify encoding handler for",
"character set",
txt_encoding);
......@@ -5674,25 +5606,80 @@ xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) {
xmlGenericError(xmlGenericErrorContext,
"xmlDocDumpMemoryEnc: Failed to allocate output buffer.\n");
"xmlDocDumpFormatMemoryEnc: Failed to allocate output buffer.\n");
return;
}
xmlDocContentDumpOutput(out_buff, out_doc, txt_encoding);
*doc_txt_len = out_buff->buffer->use;
*doc_txt_ptr = xmlStrndup(out_buff->buffer->content, *doc_txt_len);
xmlDocContentDumpOutput(out_buff, out_doc, txt_encoding, 1);
xmlOutputBufferFlush(out_buff);
if (out_buff->conv != NULL) {
*doc_txt_len = out_buff->conv->use;
*doc_txt_ptr = xmlStrndup(out_buff->conv->content, *doc_txt_len);
} else {
*doc_txt_len = out_buff->buffer->use;
*doc_txt_ptr = xmlStrndup(out_buff->buffer->content, *doc_txt_len);
}
(void)xmlOutputBufferClose(out_buff);
if ((*doc_txt_ptr == NULL) && (*doc_txt_len > 0)) {
*doc_txt_len = 0;
xmlGenericError(xmlGenericErrorContext,
"xmlDocDumpMemoryEnc: %s\n",
"xmlDocDumpFormatMemoryEnc: %s\n",
"Failed to allocate memory for document text representation.");
}
return;
}
/**
* xmlDocDumpMemory:
* @cur: the document
* @mem: OUT: the memory pointer
* @size: OUT: the memory lenght
*
* Dump an XML document in memory and return the xmlChar * and it's size.
* It's up to the caller to free the memory.
*/
void
xmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) {
xmlDocDumpFormatMemoryEnc(cur, mem, size, NULL, 0);
}
/**
* xmlDocDumpFormatMemory: