summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSterling Hughes <sterling@php.net>2004-01-20 05:31:50 +0000
committerSterling Hughes <sterling@php.net>2004-01-20 05:31:50 +0000
commitbd306c8b522d649bec2f32386034cf75059565b0 (patch)
tree058a058d8d9f2321c2e4ea56f89f37d03aa76f45
parent495860928a9a794e39a0ac854818b926900d622b (diff)
downloadphp-git-bd306c8b522d649bec2f32386034cf75059565b0.tar.gz
-
-rw-r--r--ext/simplexml/simplexml.c78
1 files changed, 58 insertions, 20 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index eeb752ece1..5b74d6ef0b 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -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);
+
+ 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);
- Z_TYPE_P(return_value) = IS_STRING;
+ 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;
+ }
}
/* }}} */