|
26 | 26 | #include "php.h"
|
27 | 27 | #if HAVE_LIBXML && HAVE_DOM
|
28 | 28 | #include "php_dom.h"
|
29 |
| -#include <libxml/xmlsave.h> |
30 | 29 | #include <libxml/SAX.h>
|
31 | 30 | #ifdef LIBXML_SCHEMAS_ENABLED
|
32 | 31 | #include <libxml/relaxng.h>
|
@@ -1617,54 +1616,59 @@ PHP_FUNCTION(dom_document_savexml)
|
1617 | 1616 | dom_doc_propsptr doc_props;
|
1618 | 1617 | int size, format, saveempty = 0;
|
1619 | 1618 | zend_long options = 0;
|
1620 |
| - xmlSaveCtxtPtr xscp; |
1621 | 1619 |
|
1622 | 1620 | if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
|
1623 | 1621 | return;
|
1624 | 1622 | }
|
1625 |
| - options = options | XML_SAVE_AS_XML; |
1626 | 1623 |
|
1627 | 1624 | DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
|
1628 | 1625 |
|
1629 | 1626 | doc_props = dom_get_doc_props(intern->document);
|
1630 | 1627 | format = doc_props->formatoutput;
|
1631 |
| - if (format) { |
1632 |
| - options = options | XML_SAVE_FORMAT; |
1633 |
| - } |
1634 | 1628 |
|
1635 |
| - buf = xmlBufferCreate(); |
1636 |
| - if (!buf) { |
1637 |
| - php_error_docref(NULL, E_WARNING, "Could not fetch buffer"); |
1638 |
| - RETURN_FALSE; |
1639 |
| - } |
1640 |
| - xscp = xmlSaveToBuffer(buf, docp->encoding, options); |
1641 |
| - |
1642 | 1629 | if (nodep != NULL) {
|
1643 | 1630 | /* Dump contents of Node */
|
1644 | 1631 | DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
|
1645 | 1632 | if (node->doc != docp) {
|
1646 | 1633 | php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
|
1647 |
| - xmlBufferFree(buf); |
1648 | 1634 | RETURN_FALSE;
|
1649 | 1635 | }
|
1650 |
| - if(xmlSaveTree(xscp, node) < 0) { |
1651 |
| - xmlBufferFree(buf); |
| 1636 | + buf = xmlBufferCreate(); |
| 1637 | + if (!buf) { |
| 1638 | + php_error_docref(NULL, E_WARNING, "Could not fetch buffer"); |
1652 | 1639 | RETURN_FALSE;
|
1653 | 1640 | }
|
1654 |
| - } else { |
1655 |
| - if(xmlSaveDoc(xscp, docp) < 0) { |
| 1641 | + if (options & LIBXML_SAVE_NOEMPTYTAG) { |
| 1642 | + saveempty = xmlSaveNoEmptyTags; |
| 1643 | + xmlSaveNoEmptyTags = 1; |
| 1644 | + } |
| 1645 | + xmlNodeDump(buf, docp, node, 0, format); |
| 1646 | + if (options & LIBXML_SAVE_NOEMPTYTAG) { |
| 1647 | + xmlSaveNoEmptyTags = saveempty; |
| 1648 | + } |
| 1649 | + mem = (xmlChar*) xmlBufferContent(buf); |
| 1650 | + if (!mem) { |
1656 | 1651 | xmlBufferFree(buf);
|
1657 | 1652 | RETURN_FALSE;
|
1658 | 1653 | }
|
1659 |
| - } |
1660 |
| - xmlSaveClose(xscp); |
1661 |
| - mem = (xmlChar*) xmlBufferContent(buf); |
1662 |
| - if (!mem) { |
| 1654 | + RETVAL_STRING((char *) mem); |
1663 | 1655 | xmlBufferFree(buf);
|
1664 |
| - RETURN_FALSE; |
| 1656 | + } else { |
| 1657 | + if (options & LIBXML_SAVE_NOEMPTYTAG) { |
| 1658 | + saveempty = xmlSaveNoEmptyTags; |
| 1659 | + xmlSaveNoEmptyTags = 1; |
| 1660 | + } |
| 1661 | + /* Encoding is handled from the encoding property set on the document */ |
| 1662 | + xmlDocDumpFormatMemory(docp, &mem, &size, format); |
| 1663 | + if (options & LIBXML_SAVE_NOEMPTYTAG) { |
| 1664 | + xmlSaveNoEmptyTags = saveempty; |
| 1665 | + } |
| 1666 | + if (!size || !mem) { |
| 1667 | + RETURN_FALSE; |
| 1668 | + } |
| 1669 | + RETVAL_STRINGL((char *) mem, size); |
| 1670 | + xmlFree(mem); |
1665 | 1671 | }
|
1666 |
| - RETVAL_STRING((char *) mem); |
1667 |
| - xmlBufferFree(buf); |
1668 | 1672 | }
|
1669 | 1673 | /* }}} end dom_document_savexml */
|
1670 | 1674 |
|
|
0 commit comments