diff options
author | Joe Watkins <krakjoe@php.net> | 2017-02-01 19:17:56 +0000 |
---|---|---|
committer | Joe Watkins <krakjoe@php.net> | 2017-02-01 19:18:18 +0000 |
commit | 5c34a30bdbc8924f441c8def5abece46d3dbfe8a (patch) | |
tree | bbb22b527724e7837bf37dc4a43526e7a1d5cd7d /ext/dom/document.c | |
parent | 8a0c388e11a720949897c0371ee4ac4daf4eea37 (diff) | |
download | php-git-PHP-7.1.2.tar.gz |
Revert "fixed bug #50989 (DOM support for LIBXML_NOXMLDECL)"php-7.1.2RC1PHP-7.1.2
This reverts commit 2fcf1259c6a9c1d70bcdfb96aeabc54c47e2a4a0.
Diffstat (limited to 'ext/dom/document.c')
-rw-r--r-- | ext/dom/document.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c index 0086d13c41..18d652064e 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -26,7 +26,6 @@ #include "php.h" #if HAVE_LIBXML && HAVE_DOM #include "php_dom.h" -#include <libxml/xmlsave.h> #include <libxml/SAX.h> #ifdef LIBXML_SCHEMAS_ENABLED #include <libxml/relaxng.h> @@ -1617,51 +1616,59 @@ PHP_FUNCTION(dom_document_savexml) dom_doc_propsptr doc_props; int size, format, saveempty = 0; zend_long options = 0; - xmlSaveCtxtPtr xscp; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) { return; } - options = options | XML_SAVE_AS_XML; DOM_GET_OBJ(docp, id, xmlDocPtr, intern); doc_props = dom_get_doc_props(intern->document); format = doc_props->formatoutput; - buf = xmlBufferCreate(); - if (!buf) { - php_error_docref(NULL, E_WARNING, "Could not fetch buffer"); - RETURN_FALSE; - } - xscp = xmlSaveToBuffer(buf, docp->encoding, options); - if (nodep != NULL) { /* Dump contents of Node */ DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj); if (node->doc != docp) { php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document)); - xmlBufferFree(buf); RETURN_FALSE; } - if(xmlSaveTree(xscp, node) < 0) { - xmlBufferFree(buf); + buf = xmlBufferCreate(); + if (!buf) { + php_error_docref(NULL, E_WARNING, "Could not fetch buffer"); RETURN_FALSE; } - } else { - if(xmlSaveDoc(xscp, docp) < 0) { + if (options & LIBXML_SAVE_NOEMPTYTAG) { + saveempty = xmlSaveNoEmptyTags; + xmlSaveNoEmptyTags = 1; + } + xmlNodeDump(buf, docp, node, 0, format); + if (options & LIBXML_SAVE_NOEMPTYTAG) { + xmlSaveNoEmptyTags = saveempty; + } + mem = (xmlChar*) xmlBufferContent(buf); + if (!mem) { xmlBufferFree(buf); RETURN_FALSE; } - } - xmlSaveClose(xscp); - mem = (xmlChar*) xmlBufferContent(buf); - if (!mem) { + RETVAL_STRING((char *) mem); xmlBufferFree(buf); - RETURN_FALSE; + } else { + if (options & LIBXML_SAVE_NOEMPTYTAG) { + saveempty = xmlSaveNoEmptyTags; + xmlSaveNoEmptyTags = 1; + } + /* Encoding is handled from the encoding property set on the document */ + xmlDocDumpFormatMemory(docp, &mem, &size, format); + if (options & LIBXML_SAVE_NOEMPTYTAG) { + xmlSaveNoEmptyTags = saveempty; + } + if (!size || !mem) { + RETURN_FALSE; + } + RETVAL_STRINGL((char *) mem, size); + xmlFree(mem); } - RETVAL_STRING((char *) mem); - xmlBufferFree(buf); } /* }}} end dom_document_savexml */ |