@@ -367,13 +367,12 @@ _get_base_node_value(xmlNodePtr node, zval **value TSRMLS_DC)
367
367
if (node -> children && node -> children -> type == XML_TEXT_NODE && !xmlIsBlankNode (node -> children )) {
368
368
contents = xmlNodeListGetString (node -> doc , node -> children , 1 );
369
369
if (contents ) {
370
- ZVAL_STRING (* value , contents , 1 );
371
- xmlFree (contents );
370
+ ZVAL_STRING (* value , contents , 0 );
372
371
}
373
372
} else {
374
373
subnode = php_sxe_object_new (TSRMLS_C );
375
374
subnode -> document = emalloc (sizeof (simplexml_ref_obj ));
376
- subnode -> document -> refcount = 2 ;
375
+ subnode -> document -> refcount = 1 ;
377
376
subnode -> document -> ptr = node -> doc ;
378
377
subnode -> node = node ;
379
378
@@ -613,6 +612,44 @@ simplexml_ce_register_ns(INTERNAL_FUNCTION_PARAMETERS)
613
612
}
614
613
/* }}} */
615
614
615
+ /* {{{ simplexml_ce_to_xml_string()
616
+ */
617
+ static void
618
+ simplexml_ce_to_xml_string (INTERNAL_FUNCTION_PARAMETERS )
619
+ {
620
+ php_sxe_object * sxe ;
621
+
622
+ if (ZEND_NUM_ARGS () != 0 ) {
623
+ RETURN_FALSE ;
624
+ }
625
+
626
+ sxe = php_sxe_fetch_object (getThis () TSRMLS_CC );
627
+ xmlDocDumpMemory ((xmlDocPtr ) sxe -> document -> ptr , (xmlChar * * ) & Z_STRVAL_P (return_value ), & Z_STRLEN_P (return_value ));
628
+ Z_TYPE_P (return_value ) = IS_STRING ;
629
+ zval_add_ref (& return_value );
630
+ }
631
+ /* }}} */
632
+
633
+ /* {{{ simplexml_ce_to_xml_file()
634
+ */
635
+ static void
636
+ simplexml_ce_to_xml_file (INTERNAL_FUNCTION_PARAMETERS )
637
+ {
638
+ php_sxe_object * sxe ;
639
+ char * filename ;
640
+ int filename_len ;
641
+
642
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & filename , & filename_len ) == FAILURE ) {
643
+ return ;
644
+ }
645
+
646
+ sxe = php_sxe_fetch_object (getThis () TSRMLS_CC );
647
+
648
+ xmlSaveFile (filename , (xmlDocPtr ) sxe -> document -> ptr );
649
+
650
+ RETURN_TRUE ;
651
+ }
652
+ /* }}} */
616
653
617
654
/* {{{ sxe_call_method()
618
655
*/
@@ -627,6 +664,10 @@ sxe_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS)
627
664
simplexml_ce_schema_validate (INTERNAL_FUNCTION_PARAM_PASSTHRU , SCHEMA_BLOB );
628
665
} else if (!strcmp (method , "register_ns" )) {
629
666
simplexml_ce_register_ns (INTERNAL_FUNCTION_PARAM_PASSTHRU );
667
+ } else if (!strcmp (method , "to_xml" )) {
668
+ simplexml_ce_to_xml_string (INTERNAL_FUNCTION_PARAM_PASSTHRU );
669
+ } else if (!strcmp (method , "to_xml_file" )) {
670
+ simplexml_ce_to_xml_file (INTERNAL_FUNCTION_PARAM_PASSTHRU );
630
671
} else {
631
672
return 0 ;
632
673
}
@@ -919,58 +960,9 @@ PHP_FUNCTION(simplexml_load_string)
919
960
}
920
961
/* }}} */
921
962
922
- /* {{{ proto bool simplexml_save_document_file(string filename, simplexml_element node)
923
- Save a XML document to a file from a SimpleXML node */
924
- PHP_FUNCTION (simplexml_save_document_file )
925
- {
926
- php_sxe_object * sxe ;
927
- zval * element ;
928
- char * filename ;
929
- int filename_len ;
930
-
931
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "sz" , & filename , & filename_len , & element ) == FAILURE ) {
932
- return ;
933
- }
934
-
935
- sxe = php_sxe_fetch_object (element TSRMLS_CC );
936
-
937
- xmlSaveFile (filename , (xmlDocPtr ) sxe -> document -> ptr );
938
-
939
- RETURN_TRUE ;
940
- }
941
- /* }}} */
942
-
943
- /* {{{ proto bool simplexml_save_document_string(string &var, simplexml_element node)
944
- Save a document to a variable from a SimpleXML node */
945
- PHP_FUNCTION (simplexml_save_document_string )
946
- {
947
- php_sxe_object * sxe ;
948
- zval * data ;
949
- zval * element ;
950
-
951
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "zz" , & data , & element ) == FAILURE ) {
952
- return ;
953
- }
954
-
955
- sxe = php_sxe_fetch_object (element TSRMLS_CC );
956
- xmlDocDumpMemory ((xmlDocPtr ) sxe -> document -> ptr , (xmlChar * * ) & Z_STRVAL_P (data ), & Z_STRLEN_P (data ));
957
- Z_TYPE_P (data ) = IS_STRING ;
958
- zval_add_ref (& data );
959
-
960
- RETURN_TRUE ;
961
- }
962
- /* }}} */
963
-
964
- /* this is lame, first_arg_force_ref (and others) doesn't
965
- work through dll linkage on windows. no other extension
966
- outside basic_functions uses first_arg_force_ref. */
967
- unsigned char fix_first_arg_force_ref [] = { 1 , BYREF_FORCE };
968
-
969
963
function_entry simplexml_functions [] = {
970
964
PHP_FE (simplexml_load_file , NULL )
971
965
PHP_FE (simplexml_load_string , NULL )
972
- PHP_FE (simplexml_save_document_file , NULL )
973
- PHP_FE (simplexml_save_document_string , fix_first_arg_force_ref )
974
966
{NULL , NULL , NULL }
975
967
};
976
968
0 commit comments