diff options
author | Uwe Steinmann <steinm@php.net> | 2000-03-02 16:58:07 +0000 |
---|---|---|
committer | Uwe Steinmann <steinm@php.net> | 2000-03-02 16:58:07 +0000 |
commit | 2552876786f069c7c4979e579bf3b96d4af654a7 (patch) | |
tree | d7693a09a9fe630ef8eea2151ea1945fce0bc141 | |
parent | ad311c35c75f1f99ab6b505e01fc1305dae05ae3 (diff) | |
download | php-git-2552876786f069c7c4979e579bf3b96d4af654a7.tar.gz |
- dom class now distinguishes between $dom->root() and $dom->children()
$dom->root() returns just the element, $dom->children() all nodes e.g.
comments
-rw-r--r-- | ext/domxml/domxml.c | 34 | ||||
-rw-r--r-- | tests/testdom | 4 |
2 files changed, 24 insertions, 14 deletions
diff --git a/ext/domxml/domxml.c b/ext/domxml/domxml.c index 6984b7aaba..8c79818ce3 100644 --- a/ext/domxml/domxml.c +++ b/ext/domxml/domxml.c @@ -55,7 +55,8 @@ static zend_function_entry php_domxml_functions[] = { static zend_function_entry php_domxmldoc_class_functions[] = { - PHP_FALIAS(root, domxml_children, NULL) + PHP_FALIAS(root, domxml_root, NULL) + PHP_FALIAS(children, domxml_children, NULL) PHP_FALIAS(add_root, domxml_add_root, NULL) PHP_FALIAS(dtd, domxml_intdtd, NULL) PHP_FALIAS(dumpmem, domxml_dumpmem, NULL) @@ -713,9 +714,9 @@ PHP_FUNCTION(domxml_attributes) } /* }}} */ -/* {{{ proto string domxml_root([int doc]) +/* {{{ proto string domxml_rootnew([int doc]) Returns list of children nodes */ -PHP_FUNCTION(domxml_root) +PHP_FUNCTION(domxml_rootnew) { zval *id, **tmp; int id_to_find; @@ -778,7 +779,7 @@ PHP_FUNCTION(domxml_root) /* {{{ proto string domxml_root([int doc_handle]) Returns root node of document */ -PHP_FUNCTION(domxml_rootold) +PHP_FUNCTION(domxml_root) { zval *id, **tmp; int id_to_find; @@ -815,16 +816,23 @@ PHP_FUNCTION(domxml_rootold) if (!node) { RETURN_FALSE; } - ret = zend_list_insert(node, le_domxmlnodep); - /* construct an object with some methods */ - object_init_ex(return_value, domxmlnode_class_entry_ptr); - add_property_resource(return_value, "node", ret); - add_property_long(return_value, "type", node->type); - add_property_stringl(return_value, "name", (char *) node->name, strlen(node->name), 1); - if(node->content) - add_property_stringl(return_value, "content", (char *) node->content, strlen(node->content), 1); - zend_list_addref(ret); + while(node) { + if(node->type == XML_ELEMENT_NODE) { + ret = zend_list_insert(node, le_domxmlnodep); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmlnode_class_entry_ptr); + add_property_resource(return_value, "node", ret); + add_property_long(return_value, "type", node->type); + add_property_stringl(return_value, "name", (char *) node->name, strlen(node->name), 1); + if(node->content) + add_property_stringl(return_value, "content", (char *) node->content, strlen(node->content), 1); + zend_list_addref(ret); + return; + } + node = node->next; + } } /* }}} */ diff --git a/tests/testdom b/tests/testdom index 2c64f3de6c..923a88491d 100644 --- a/tests/testdom +++ b/tests/testdom @@ -73,9 +73,11 @@ if(!$dom = xmldoc($xmlstr)) { } echo "XML Version: ".$dom->version."\n"; $dtd = $dom->dtd(); -$rootnode = $dom->root(); +$rootnode = $dom->children(); foreach($rootnode as $root) output_node($root); +$rootnode = $dom->root(); + output_node($rootnode); /* This one creates a dom tree made of php objects */ echo "Test 2: creating a tree with php objects\n"; |