mirror of
https://github.com/php/php-src.git
synced 2025-01-24 04:33:39 +08:00
-
This commit is contained in:
parent
495860928a
commit
bd306c8b52
@ -12,9 +12,9 @@
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Sterling Hughes <sterling@php.net> |
|
||||
| Marcus Boerger <helly@php.net> |
|
||||
| Rob Richards <rrichards@php.net> |
|
||||
| Authors: Sterling Hughes <sterling@php.net> |
|
||||
| Marcus Boerger <helly@php.net> |
|
||||
| Rob Richards <rrichards@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@ -268,7 +268,7 @@ change_node_zval(xmlNodePtr node, zval *value)
|
||||
xmlNodeSetContentLen(node, Z_STRVAL_P(value), Z_STRLEN_P(value));
|
||||
break;
|
||||
default:
|
||||
php_error(E_WARNING, "It is not yet possible to assign complex types to attributes");
|
||||
php_error(E_WARNING, "It is not possible to assign complex types to nodes");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -770,32 +770,70 @@ SXE_METHOD(xpath)
|
||||
*/
|
||||
SXE_METHOD(asXML)
|
||||
{
|
||||
php_sxe_object *sxe;
|
||||
xmlChar *strval;
|
||||
char *filename;
|
||||
int filename_len;
|
||||
php_sxe_object *sxe;
|
||||
xmlNodePtr node;
|
||||
xmlOutputBufferPtr outbuf;
|
||||
xmlChar *strval;
|
||||
int strval_len;
|
||||
char *filename;
|
||||
int filename_len;
|
||||
|
||||
if (ZEND_NUM_ARGS() > 1) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (ZEND_NUM_ARGS() == 1) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
||||
|
||||
xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
|
||||
|
||||
RETURN_TRUE;
|
||||
}
|
||||
if (ZEND_NUM_ARGS() != 0) {
|
||||
RETURN_FALSE;
|
||||
GET_NODE(sxe, node);
|
||||
|
||||
if (node) {
|
||||
if (XML_DOCUMENT_NODE == node->parent->type) {
|
||||
xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
|
||||
} else {
|
||||
outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0);
|
||||
|
||||
if (outbuf == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 1, NULL);
|
||||
xmlOutputBufferClose(outbuf);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
|
||||
xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, &strval, &Z_STRLEN_P(return_value));
|
||||
Z_STRVAL_P(return_value) = estrndup(strval, Z_STRLEN_P(return_value));
|
||||
xmlFree(strval);
|
||||
GET_NODE(sxe, node);
|
||||
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
if (node) {
|
||||
if (XML_DOCUMENT_NODE == node->parent->type) {
|
||||
xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, &strval, &strval_len);
|
||||
} else {
|
||||
/* Should we be passing encoding information instead of NULL? */
|
||||
outbuf = xmlAllocOutputBuffer(NULL);
|
||||
|
||||
if (outbuf == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 1, ((xmlDocPtr) sxe->document->ptr)->encoding);
|
||||
xmlOutputBufferFlush(outbuf);
|
||||
strval = xmlStrndup(outbuf->buffer->content, outbuf->buffer->use);
|
||||
xmlOutputBufferClose(outbuf);
|
||||
}
|
||||
|
||||
RETVAL_STRINGL(strval, strlen(strval), 1);
|
||||
xmlFree(strval);
|
||||
} else {
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user