From: Marcus Boerger Date: Thu, 13 Nov 2003 20:32:38 +0000 (+0000) Subject: Fix classname, CDATA handling (semantically identical to text) and X-Git-Tag: php-5.0.0b3RC1~694 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b35596d7f3762b805a24df481a65ed3cc5de319;p=php Fix classname, CDATA handling (semantically identical to text) and iterators (Return sub elements as objects, converted to string you get the text). --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index b6ca21b51b..ca18e0b40a 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -553,16 +553,15 @@ sxe_properties_get(zval *object TSRMLS_DC) while (node) { SKIP_TEXT(node); - _get_base_node_value(sxe, node, &value TSRMLS_CC); - name = (char *) node->name; if (!name) { - name = "CDATA"; - namelen = sizeof("CDATA"); + goto next_iter; } else { namelen = xmlStrlen(node->name) + 1; } + _get_base_node_value(sxe, node, &value TSRMLS_CC); + h = zend_hash_func(name, namelen); if (zend_hash_quick_find(rv, name, namelen, h, (void **) &data_ptr) == SUCCESS) { if (Z_TYPE_PP(data_ptr) == IS_ARRAY) { @@ -884,7 +883,7 @@ static int sxe_class_name_get(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) { *class_name = estrdup("simplexml_element"); - *class_name_len = sizeof("simplexml_element"); + *class_name_len = sizeof("simplexml_element")-1; return 0; } @@ -1216,17 +1215,28 @@ zend_object_iterator_funcs php_sxe_iterator_funcs = { static void php_sxe_iterator_current(php_sxe_iterator *iterator TSRMLS_DC) { + xmlNodePtr node; + while (iterator->node) { - SKIP_TEXT(iterator->node); + node = iterator->node; + + SKIP_TEXT(node); + + do if (node->ns) { + if (node->parent->ns) { + if (!xmlStrcmp(node->ns->href, node->parent->ns->href)) { + break; + } + } + } while (0); - _get_base_node_value(iterator->sxe, iterator->node, &iterator->data TSRMLS_CC); - if (!iterator->node->name) { - iterator->name = "CDATA"; - iterator->namelen = sizeof("CDATA"); + goto next_iter; } else { - iterator->namelen = xmlStrlen(iterator->node->name)+1; - iterator->name = (char *) iterator->node->name; + iterator->namelen = xmlStrlen(node->name)+1; + iterator->name = (char *) node->name; + MAKE_STD_ZVAL(iterator->data); + _node_as_zval(iterator->sxe, node, iterator->data TSRMLS_CC); } break; next_iter: diff --git a/ext/simplexml/tests/004.phpt b/ext/simplexml/tests/004.phpt index 30759118a3..7f01ec1490 100755 --- a/ext/simplexml/tests/004.phpt +++ b/ext/simplexml/tests/004.phpt @@ -11,11 +11,10 @@ print_r($sxe); $elem1 = $sxe->elem1; $elem2 = $elem1->elem2; -echo($elem2->CDATA); - -echo "---Done---\n"; +var_dump(trim((string)$elem2)); ?> +===DONE=== --EXPECT-- simplexml_element Object ( @@ -27,10 +26,6 @@ simplexml_element Object [elem2] => simplexml_element Object ( - [CDATA] => simplexml_element Object - ( - ) - [elem3] => simplexml_element Object ( [elem4] => simplexml_element Object @@ -48,4 +43,5 @@ simplexml_element Object ) ) ----Done--- +string(11) "CDATA block" +===DONE=== diff --git a/ext/simplexml/tests/009.phpt b/ext/simplexml/tests/009.phpt new file mode 100755 index 0000000000..c7bbe02245 --- /dev/null +++ b/ext/simplexml/tests/009.phpt @@ -0,0 +1,22 @@ +--TEST-- +SimpleXML and XPath +--SKIPIF-- + +--FILE-- +$val) { + var_dump($name); + var_dump(get_class($val)); + var_dump(trim((string)$val)); +} +?> +===DONE=== +--EXPECT-- +string(5) "elem1" +string(17) "simplexml_element" +string(10) "Bla bla 1." +string(6) "elem11" +string(17) "simplexml_element" +string(10) "Bla bla 2." +===DONE=== diff --git a/ext/simplexml/tests/009.xml b/ext/simplexml/tests/009.xml new file mode 100755 index 0000000000..d8d93debde --- /dev/null +++ b/ext/simplexml/tests/009.xml @@ -0,0 +1,24 @@ + + +%incent; +]> + + Plain text. + + Bla bla 1. + + + Here we have some text data. + + And here some more. + + Wow once again. + + + + + + Bla bla 2. + + \ No newline at end of file