fix getElementsByTagname iteration

This commit is contained in:
Rob Richards 2003-12-08 17:08:10 +00:00
parent 862a7e589d
commit 3084e72ef1
2 changed files with 20 additions and 14 deletions

View File

@ -183,11 +183,11 @@ static void php_dom_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC)
{
zval *curobj, *curattr = NULL;
zval *object;
xmlNodePtr curnode = NULL;
xmlNodePtr curnode = NULL, basenode;
dom_object *intern;
dom_object *nnmap;
dom_nnodemap_object *objmap;
int ret, previndex=0;
int ret, previndex=1;
php_dom_iterator *iterator = (php_dom_iterator *)iter;
@ -203,8 +203,12 @@ static void php_dom_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC)
if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
curnode = curnode->next;
} else {
previndex = iter->index - 1;
curnode = dom_get_elements_by_tag_name_ns_raw(curnode, objmap->ns, objmap->local, &previndex, iter->index);
/* 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 = dom_get_elements_by_tag_name_ns_raw(basenode, objmap->ns, objmap->local, &previndex, iter->index);
}
} else {
if (objmap->nodetype == XML_ENTITY_NODE) {

View File

@ -1092,18 +1092,20 @@ xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *l
xmlNodePtr ret = NULL;
while (nodep != NULL && (*cur <= index || index == -1)) {
if (nodep->type == XML_ELEMENT_NODE && xmlStrEqual(nodep->name, local)) {
if (ns == NULL || (nodep->ns != NULL && xmlStrEqual(nodep->ns->href, ns))) {
if (*cur == index) {
ret = nodep;
break;
if (nodep->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(nodep->name, local)) {
if (ns == NULL || (nodep->ns != NULL && xmlStrEqual(nodep->ns->href, ns))) {
if (*cur == index) {
ret = nodep;
break;
}
(*cur)++;
}
(*cur)++;
}
}
ret = dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, cur, index);
if (ret != NULL) {
break;
ret = dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, cur, index);
if (ret != NULL) {
break;
}
}
nodep = nodep->next;
}