2003-06-06 01:06:52 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 4 |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1997-2003 The PHP Group |
|
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
2003-06-06 01:06:52 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
2003-06-06 01:06:52 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Christian Stocker <chregu@php.net> |
|
|
|
|
| Rob Richards <rrichards@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
2003-08-22 23:04:29 +08:00
|
|
|
#if HAVE_LIBXML && HAVE_DOM
|
2003-06-06 01:06:52 +08:00
|
|
|
#include "php_dom.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* class domnodelist
|
|
|
|
*
|
|
|
|
* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-536297177
|
|
|
|
* Since:
|
|
|
|
*/
|
|
|
|
|
|
|
|
zend_function_entry php_dom_nodelist_class_functions[] = {
|
|
|
|
PHP_FALIAS(item, dom_nodelist_item, NULL)
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* {{{ attribute protos, not implemented yet */
|
|
|
|
|
|
|
|
/* {{{ proto length unsigned long
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_nodelist_length_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
2003-11-30 04:40:18 +08:00
|
|
|
dom_nnodemap_object *objmap;
|
|
|
|
xmlNodePtr nodep, curnode;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
count++;
|
|
|
|
curnode = curnode->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
|
|
|
|
nodep = xmlDocGetRootElement((xmlDoc *) nodep);
|
2003-12-30 00:44:47 +08:00
|
|
|
} else {
|
|
|
|
nodep = nodep->children;
|
2003-11-30 04:40:18 +08:00
|
|
|
}
|
|
|
|
curnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(*retval);
|
|
|
|
ZVAL_LONG(*retval, count);
|
2003-06-06 01:06:52 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_nodelist_item(unsigned long index);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_nodelist_item)
|
|
|
|
{
|
2003-11-30 04:40:18 +08:00
|
|
|
zval *id, *rv = NULL;
|
|
|
|
int index, ret;
|
|
|
|
dom_object *intern;
|
|
|
|
xmlNodePtr itemnode = NULL;
|
|
|
|
|
|
|
|
dom_nnodemap_object *objmap;
|
|
|
|
xmlNodePtr nodep, curnode;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
id = getThis();
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= 0) {
|
|
|
|
intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
|
|
|
|
|
|
|
|
objmap = (dom_nnodemap_object *)intern->ptr;
|
|
|
|
if (objmap->ht) {
|
|
|
|
if (objmap->nodetype == XML_ENTITY_NODE) {
|
|
|
|
itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
|
|
|
|
} else {
|
|
|
|
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);
|
2003-12-30 00:44:47 +08:00
|
|
|
} else {
|
|
|
|
nodep = nodep->children;
|
2003-11-30 04:40:18 +08:00
|
|
|
}
|
|
|
|
itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-12-22 02:22:14 +08:00
|
|
|
} else {
|
2003-12-24 01:08:44 +08:00
|
|
|
RETURN_NULL();
|
2003-11-30 04:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (itemnode) {
|
|
|
|
DOM_RET_OBJ(rv, itemnode, &ret, objmap->baseobj);
|
|
|
|
} else {
|
|
|
|
RETVAL_NULL();
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_nodelist_item */
|
2003-08-22 23:04:29 +08:00
|
|
|
#endif
|