rrichards Sat Jan 10 06:50:25 2004 EDT Modified files: /php-src/ext/dom dom_iterators.c nodelist.c php_dom.h xpath.c Log: XPath query returns nodelist object rather than array
Index: php-src/ext/dom/dom_iterators.c diff -u php-src/ext/dom/dom_iterators.c:1.4 php-src/ext/dom/dom_iterators.c:1.5 --- php-src/ext/dom/dom_iterators.c:1.4 Thu Jan 8 03:15:16 2004 +++ php-src/ext/dom/dom_iterators.c Sat Jan 10 06:50:25 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dom_iterators.c,v 1.4 2004/01/08 08:15:16 andi Exp $ */ +/* $Id: dom_iterators.c,v 1.5 2004/01/10 11:50:25 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -188,6 +188,8 @@ dom_object *nnmap; dom_nnodemap_object *objmap; int ret, previndex=1; + HashTable *nodeht; + pval **entry; php_dom_iterator *iterator = (php_dom_iterator *)iter; @@ -199,18 +201,26 @@ intern = (dom_object *)zend_object_store_get_object(curobj TSRMLS_CC); if (intern != NULL && intern->ptr != NULL) { if (objmap->ht == NULL) { - curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node; - if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { - curnode = curnode->next; + if (objmap->nodetype == DOM_NODESET) { + nodeht = HASH_OF(objmap->baseobjptr); + zend_hash_move_forward(nodeht); + if (zend_hash_get_current_data(nodeht, (void **) &entry)==SUCCESS) { + curattr = *entry; + } } else { - /* Nav the tree evey time as this is LIVE */ - basenode = dom_object_get_node(objmap->baseobj); - if (basenode && (basenode->type == XML_DOCUMENT_NODE || basenode->type == XML_HTML_DOCUMENT_NODE)) { - basenode = xmlDocGetRootElement((xmlDoc *) basenode); + curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node; + if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { + curnode = curnode->next; } else { - basenode = basenode->children; + /* Nav the tree evey time as this is LIVE */ + basenode = dom_object_get_node(objmap->baseobj); + if (basenode && (basenode->type == XML_DOCUMENT_NODE || basenode->type == XML_HTML_DOCUMENT_NODE)) { + basenode = xmlDocGetRootElement((xmlDoc *) basenode); + } else { + basenode = basenode->children; + } + curnode = dom_get_elements_by_tag_name_ns_raw(basenode, objmap->ns, objmap->local, &previndex, iter->index); } - curnode = dom_get_elements_by_tag_name_ns_raw(basenode, objmap->ns, objmap->local, &previndex, iter->index); } } else { if (objmap->nodetype == XML_ENTITY_NODE) { @@ -243,9 +253,11 @@ { dom_object *intern; dom_nnodemap_object *objmap; - xmlNodePtr nodep, curnode; + xmlNodePtr nodep, curnode=NULL; zval *curattr = NULL; int ret, curindex = 0; + HashTable *nodeht; + pval **entry; php_dom_iterator *iterator = emalloc(sizeof(php_dom_iterator)); @@ -256,20 +268,28 @@ intern = (dom_object *)zend_object_store_get_object(object TSRMLS_CC); objmap = (dom_nnodemap_object *)intern->ptr; if (objmap->ht == NULL) { - nodep = (xmlNode *)dom_object_get_node(objmap->baseobj); - if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { - if (objmap->nodetype == XML_ATTRIBUTE_NODE) { - curnode = (xmlNodePtr) nodep->properties; - } else { - curnode = (xmlNodePtr) nodep->children; + if (objmap->nodetype == DOM_NODESET) { + nodeht = HASH_OF(objmap->baseobjptr); + zend_hash_internal_pointer_reset(nodeht); + if (zend_hash_get_current_data(nodeht, (void **) &entry)==SUCCESS) { + curattr = *entry; } } else { - if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { - nodep = xmlDocGetRootElement((xmlDoc *) nodep); + nodep = (xmlNode *)dom_object_get_node(objmap->baseobj); + if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { + if (objmap->nodetype == XML_ATTRIBUTE_NODE) { + curnode = (xmlNodePtr) nodep->properties; + } else { + curnode = (xmlNodePtr) nodep->children; + } } else { - nodep = nodep->children; + if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { + nodep = xmlDocGetRootElement((xmlDoc *) nodep); + } else { + nodep = nodep->children; + } + curnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &curindex, 0); } - curnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &curindex, 0); } } else { curnode = php_dom_libxml_hash_iter(objmap->ht, 0); Index: php-src/ext/dom/nodelist.c diff -u php-src/ext/dom/nodelist.c:1.8 php-src/ext/dom/nodelist.c:1.9 --- php-src/ext/dom/nodelist.c:1.8 Thu Jan 8 03:15:17 2004 +++ php-src/ext/dom/nodelist.c Sat Jan 10 06:50:25 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: nodelist.c,v 1.8 2004/01/08 08:15:17 andi Exp $ */ +/* $Id: nodelist.c,v 1.9 2004/01/10 11:50:25 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -52,29 +52,35 @@ dom_nnodemap_object *objmap; xmlNodePtr nodep, curnode; int count = 0; + HashTable *nodeht; objmap = (dom_nnodemap_object *)obj->ptr; if (objmap->ht) { count = xmlHashSize(objmap->ht); } else { - nodep = dom_object_get_node(objmap->baseobj); - if (nodep) { - if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { - curnode = nodep->children; - if (curnode) { - count++; - while (curnode->next != NULL) { + if (objmap->nodetype == DOM_NODESET) { + nodeht = HASH_OF(objmap->baseobjptr); + count = zend_hash_num_elements(nodeht); + } else { + nodep = dom_object_get_node(objmap->baseobj); + if (nodep) { + if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { + curnode = nodep->children; + if (curnode) { count++; - curnode = curnode->next; + while (curnode->next != NULL) { + count++; + curnode = curnode->next; + } } - } - } else { - if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { - nodep = xmlDocGetRootElement((xmlDoc *) nodep); } else { - nodep = nodep->children; + if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { + nodep = xmlDocGetRootElement((xmlDoc *) nodep); + } else { + nodep = nodep->children; + } + curnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, -1); } - curnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, -1); } } } @@ -101,6 +107,8 @@ dom_nnodemap_object *objmap; xmlNodePtr nodep, curnode; int count = 0; + HashTable *nodeht; + pval **entry; id = getThis(); @@ -119,22 +127,31 @@ itemnode = php_dom_libxml_notation_iter(objmap->ht, index); } } else { - nodep = dom_object_get_node(objmap->baseobj); - if (nodep) { - if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { - curnode = nodep->children; - while (count < index && curnode != NULL) { - count++; - curnode = curnode->next; - } - itemnode = curnode; - } else { - if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { - nodep = xmlDocGetRootElement((xmlDoc *) nodep); + if (objmap->nodetype == DOM_NODESET) { + nodeht = HASH_OF(objmap->baseobjptr); + if (zend_hash_index_find(nodeht, index, (void **) &entry)==SUCCESS) { + *return_value = **entry; + zval_copy_ctor(return_value); + return; + } + } else { + nodep = dom_object_get_node(objmap->baseobj); + if (nodep) { + if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { + curnode = nodep->children; + while (count < index && curnode != NULL) { + count++; + curnode = curnode->next; + } + itemnode = curnode; } else { - nodep = nodep->children; + if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { + nodep = xmlDocGetRootElement((xmlDoc *) nodep); + } else { + nodep = nodep->children; + } + itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, index); } - itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, index); } } } Index: php-src/ext/dom/php_dom.h diff -u php-src/ext/dom/php_dom.h:1.21 php-src/ext/dom/php_dom.h:1.22 --- php-src/ext/dom/php_dom.h:1.21 Thu Jan 8 12:32:03 2004 +++ php-src/ext/dom/php_dom.h Sat Jan 10 06:50:25 2004 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dom.h,v 1.21 2004/01/08 17:32:03 sniper Exp $ */ +/* $Id: php_dom.h,v 1.22 2004/01/10 11:50:25 rrichards Exp $ */ #ifndef PHP_DOM_H #define PHP_DOM_H @@ -62,6 +62,8 @@ Can be checked with phpversion("dom"); */ #define DOM_API_VERSION "20031129" +/* Define a custom type for iterating using an unused nodetype */ +#define DOM_NODESET XML_XINCLUDE_START typedef struct _dom_nnodemap_object { dom_object *baseobj; Index: php-src/ext/dom/xpath.c diff -u php-src/ext/dom/xpath.c:1.10 php-src/ext/dom/xpath.c:1.11 --- php-src/ext/dom/xpath.c:1.10 Thu Jan 8 03:15:17 2004 +++ php-src/ext/dom/xpath.c Sat Jan 10 06:50:25 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xpath.c,v 1.10 2004/01/08 08:15:17 andi Exp $ */ +/* $Id: xpath.c,v 1.11 2004/01/10 11:50:25 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -128,10 +128,20 @@ RETURN_TRUE; } +static void dom_xpath_iter(zval *baseobj, dom_object *intern) +{ + dom_nnodemap_object *mapptr; + + mapptr = (dom_nnodemap_object *)intern->ptr; + mapptr->baseobjptr = baseobj; + mapptr->nodetype = DOM_NODESET; + +} + /* {{{ proto domnodelist dom_xpath_query(string expr [,domNode context]); */ PHP_FUNCTION(dom_xpath_query) { - zval *id, *context = NULL; + zval *id, *retval, *context = NULL; xmlXPathContextPtr ctxp; xmlNodePtr nodep = NULL; xmlXPathObjectPtr xpathobjp; @@ -200,6 +210,10 @@ if (! xpathobjp) { RETURN_FALSE; } + + MAKE_STD_ZVAL(retval); + array_init(retval); + if (xpathobjp->type == XPATH_NODESET) { int i; xmlNodeSetPtr nodesetp; @@ -209,8 +223,6 @@ RETURN_FALSE; } - array_init(return_value); - for (i = 0; i < nodesetp->nodeNr; i++) { xmlNodePtr node = nodesetp->nodeTab[i]; zval *child; @@ -236,10 +248,14 @@ node->ns = curns; } child = php_dom_create_object(node, &ret, NULL, child, intern TSRMLS_CC); - add_next_index_zval(return_value, child); + add_next_index_zval(retval, child); } } + php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC); + intern = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC); + dom_xpath_iter(retval, intern); + xmlXPathFreeObject(xpathobjp); } /* }}} end dom_xpath_query */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php