cvs: /php4/ext/domxml domxml.c
| From: | Uwe Steinmann | Date: | Fri, 03 Mar 2000 08:44:56 +0000 |
| Subject: | cvs: /php4/ext/domxml domxml.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-11433@lists.php.net to get a copy of this message | ||
steinm Fri Mar 3 00:44:56 2000 EDT
Modified files:
/php4/ext/domxml domxml.c
Log:
- xmltree() now returns an 'Dom Document' object with prop root and
children. root contains just the root element, children is an array
with all nodes on root level, e.g. comment, pi, element
Index: php4/ext/domxml/domxml.c
diff -u php4/ext/domxml/domxml.c:1.25 php4/ext/domxml/domxml.c:1.26
--- php4/ext/domxml/domxml.c:1.25 Fri Mar 3 00:02:22 2000
+++ php4/ext/domxml/domxml.c Fri Mar 3 00:44:25 2000
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domxml.c,v 1.25 2000/03/03 08:02:22 steinm Exp $ */
+/* $Id: domxml.c,v 1.26 2000/03/03 08:44:25 steinm Exp $ */
#include "php.h"
@@ -1237,20 +1237,26 @@
/* construct a node object for each child */
object_init_ex(child, domxmlnode_class_entry_ptr);
+
+ /* Add the node object to the array of children */
+ zend_hash_next_index_insert((*children)->value.ht, &child, sizeof(zval *), NULL);
+
+ /* Add name, content and type as properties */
add_property_stringl(child, "name", (char *) last->name, strlen(last->name), 1);
+ add_property_long(child, "type", last->type);
if(last->content)
add_property_stringl(child, "content", (char *) last->content,
strlen(last->content), 1);
// add_property_resource(child, "node", ret);
- add_property_long(child, "type", last->type);
- /* Add the node object to the array of children */
- zend_hash_next_index_insert((*children)->value.ht, &child, sizeof(zval *), NULL);
- /* Get the namespace of the current node */
+
+ /* Get the namespace of the current node and add it as a property */
if(!node_namespace(&namespace, last))
zend_hash_update(child->value.obj.properties, "namespace",
strlen("namespace")+1, (void *) &namespace, sizeof(zval *), NULL);
- /* Get the attributes of the current node */
+
+ /* Get the attributes of the current node and add it as a property */
if(!node_attributes(&attributes, last))
zend_hash_update(child->value.obj.properties, "attributes",
strlen("attributes")+1, (void *) &attributes, sizeof(zval *), NULL);
- /* Get recursively the children of the current node */
+
+ /* Get recursively the children of the current node and add it as a property */
if(!node_children(&mchildren, last->childs))
zend_hash_update(child->value.obj.properties, "children",
strlen("children")+1, (void *) &mchildren, sizeof(zval *), NULL);
@@ -1296,9 +1302,29 @@
as root, you may have a comment, pi and and element as root.
Thanks to Paul DuBois for pointing me at this.
*/
- if(0 == node_children(&children, root))
- zend_hash_update(return_value->value.obj.properties, "root",
strlen("root")+1, (void *) &children, sizeof(zval *), NULL);
-
+ if(0 == node_children(&children, root)) {
+ int i, count;
+ HashTable *lht;
+ zend_hash_update(return_value->value.obj.properties, "children",
strlen("children")+1, (void *) &children, sizeof(zval *), NULL);
+
+ /* Find the child of xml type element */
+ lht = children->value.ht;
+ count = zend_hash_num_elements(lht);
+ zend_hash_internal_pointer_reset(lht);
+ for(i=0; i<count; i++) {
+ zval **prop, **keydata;
+ zend_hash_get_current_data(lht, (void **) &keydata);
+ if((*keydata)->type == IS_OBJECT) {
+ if (zend_hash_find((*keydata)->value.obj.properties, "type",
sizeof("type"), (void **)&prop) == SUCCESS) {
+ if((*prop)->value.lval == XML_ELEMENT_NODE) {
+ root = *keydata;
+ zend_hash_update(return_value->value.obj.properties, "root",
strlen("root")+1, (void *) &root, sizeof(zval *), NULL);
+ }
+ }
+ }
+ zend_hash_move_forward(lht);
+ }
+ }
xmlFreeDoc(docp);
}
/* }}} */