Skip to content

Commit 6ac3464

Browse files
author
Rob Richards
committed
implement namednodemap and nodelist
fix xsl/dom integration under windows update tests and examples
1 parent 154db58 commit 6ac3464

File tree

14 files changed

+418
-208
lines changed

14 files changed

+418
-208
lines changed

ext/dom/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if test "$PHP_DOM" != "no" && test "$PHP_LIBXML" != "no"; then
2222
documenttype.c domimplementationlist.c entity.c \
2323
nodelist.c text.c comment.c domconfiguration.c \
2424
domimplementationsource.c entityreference.c \
25-
notation.c xpath.c \
25+
notation.c xpath.c dom_iterators.c \
2626
typeinfo.c domerror.c domlocator.c namednodemap.c userdatahandler.c],
2727
$ext_shared)
2828
PHP_SUBST(DOM_SHARED_LIBADD)

ext/dom/document.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -884,21 +884,21 @@ PHP_FUNCTION(dom_document_get_elements_by_tag_name)
884884
{
885885
zval *id;
886886
xmlDocPtr docp;
887-
xmlNodePtr elemp;
888887
int name_len;
889-
dom_object *intern;
888+
dom_object *intern, *namednode;
890889
char *name;
890+
xmlChar *local;
891891

892892
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
893893

894894
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
895895
return;
896896
}
897897

898-
array_init(return_value);
899-
elemp = xmlDocGetRootElement(docp);
900-
901-
dom_get_elements_by_tag_name_ns_raw(elemp, NULL, name, &return_value, intern TSRMLS_CC);
898+
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
899+
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
900+
local = xmlCharStrndup(name, name_len);
901+
dom_namednode_iter(intern, 0, namednode, NULL, local, NULL);
902902
}
903903
/* }}} end dom_document_get_elements_by_tag_name */
904904

@@ -1075,21 +1075,22 @@ PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns)
10751075
{
10761076
zval *id;
10771077
xmlDocPtr docp;
1078-
xmlNodePtr elemp;
10791078
int uri_len, name_len;
1080-
dom_object *intern;
1079+
dom_object *intern, *namednode;
10811080
char *uri, *name;
1081+
xmlChar *local, *nsuri;
10821082

10831083
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
10841084

10851085
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
10861086
return;
10871087
}
10881088

1089-
array_init(return_value);
1090-
elemp = xmlDocGetRootElement(docp);
1091-
1092-
dom_get_elements_by_tag_name_ns_raw(elemp, uri, name, &return_value, intern TSRMLS_CC);
1089+
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
1090+
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
1091+
local = xmlCharStrndup(name, name_len);
1092+
nsuri = xmlCharStrndup(uri, uri_len);
1093+
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
10931094
}
10941095
/* }}} end dom_document_get_elements_by_tag_name_ns */
10951096

ext/dom/documenttype.c

Lines changed: 11 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -27,57 +27,6 @@
2727
#if HAVE_LIBXML && HAVE_DOM
2828
#include "php_dom.h"
2929

30-
typedef struct _nodeIterator nodeIterator;
31-
struct _nodeIterator {
32-
int cur;
33-
int index;
34-
xmlNode *node;
35-
};
36-
37-
typedef struct _notationIterator notationIterator;
38-
struct _notationIterator {
39-
int cur;
40-
int index;
41-
xmlNotation *notation;
42-
};
43-
44-
static void itemHashScanner (void *payload, void *data, xmlChar *name) {
45-
nodeIterator *priv = (nodeIterator *)data;
46-
47-
if(priv->cur < priv->index) {
48-
priv->cur++;
49-
} else {
50-
if(priv->node == NULL) {
51-
priv->node = (xmlNode *)payload;
52-
}
53-
}
54-
}
55-
56-
/* {{{ static xmlEntityPtr create_notation(const xmlChar *name,
57-
const xmlChar *ExternalID, const xmlChar *SystemID) */
58-
static xmlNodePtr create_notation(const xmlChar *name,
59-
const xmlChar *ExternalID, const xmlChar *SystemID) {
60-
xmlEntityPtr ret;
61-
62-
ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
63-
memset(ret, 0, sizeof(xmlEntity));
64-
ret->type = XML_NOTATION_NODE;
65-
ret->name = xmlStrdup(name);
66-
ret->ExternalID = xmlStrdup(ExternalID);
67-
ret->SystemID = xmlStrdup(SystemID);
68-
ret->length = 0;
69-
ret->content = NULL;
70-
ret->URI = NULL;
71-
ret->orig = NULL;
72-
ret->children = NULL;
73-
ret->parent = NULL;
74-
ret->doc = NULL;
75-
ret->_private = NULL;
76-
ret->last = NULL;
77-
ret->prev = NULL;
78-
return((xmlNodePtr) ret);
79-
}
80-
8130
/*
8231
* class domdocumenttype extends domnode
8332
*
@@ -120,36 +69,18 @@ int dom_documenttype_entities_read(dom_object *obj, zval **retval TSRMLS_DC)
12069
{
12170
xmlDtdPtr doctypep;
12271
xmlHashTable *entityht;
123-
nodeIterator *iter;
124-
xmlNode *nodep = NULL;
125-
int ret, htsize, index = 0;
72+
dom_object *intern;
12673

12774
doctypep = (xmlDtdPtr) dom_object_get_node(obj);
12875

129-
ALLOC_ZVAL(*retval);
130-
array_init(*retval);
76+
MAKE_STD_ZVAL(*retval);
77+
php_dom_create_interator(*retval, DOM_NAMEDNODEMAP TSRMLS_CC);
13178

13279
entityht = (xmlHashTable *) doctypep->entities;
133-
if (entityht) {
134-
if ((htsize = xmlHashSize(entityht)) > 0) {
135-
iter = emalloc(sizeof(nodeIterator));
136-
while (index < htsize) {
137-
iter->cur = 0;
138-
iter->index = index;
139-
iter->node = NULL;
140-
xmlHashScan(entityht, itemHashScanner, iter);
141-
index++;
142-
nodep = iter->node;
143-
if (nodep != NULL) {
144-
zval *child;
145-
MAKE_STD_ZVAL(child);
146-
child = php_dom_create_object(nodep, &ret, NULL, child, obj TSRMLS_CC);
147-
add_assoc_zval(*retval, (char *) nodep->name, child);
148-
}
149-
}
150-
efree(iter);
151-
}
152-
}
80+
81+
intern = (dom_object *)zend_objects_get_address(*retval TSRMLS_CC);
82+
dom_namednode_iter(obj, XML_ENTITY_NODE, intern, entityht, NULL, NULL);
83+
15384
return SUCCESS;
15485
}
15586

@@ -166,38 +97,14 @@ int dom_documenttype_notations_read(dom_object *obj, zval **retval TSRMLS_DC)
16697
{
16798
xmlDtdPtr doctypep;
16899
xmlHashTable *notationht;
169-
notationIterator *iter;
170-
xmlNotationPtr notep = NULL;
171-
xmlNode *nodep = NULL;
172-
int ret, htsize, index = 0;
100+
dom_object *intern;
173101

174102
doctypep = (xmlDtdPtr) dom_object_get_node(obj);
103+
notationht = (xmlHashTable *) doctypep->notations;
175104

176-
MAKE_STD_ZVAL(*retval);
177-
array_init(*retval);
105+
intern = (dom_object *)zend_objects_get_address(*retval TSRMLS_CC);
106+
dom_namednode_iter(obj, XML_NOTATION_NODE, intern, notationht, NULL, NULL);
178107

179-
notationht = (xmlHashTable *) doctypep->notations;
180-
if (notationht) {
181-
if ((htsize = xmlHashSize(notationht)) > 0) {
182-
iter = emalloc(sizeof(nodeIterator));
183-
while (index < htsize) {
184-
iter->cur = 0;
185-
iter->index = index;
186-
iter->notation = NULL;
187-
xmlHashScan(notationht, itemHashScanner, iter);
188-
index++;
189-
notep = iter->notation;
190-
if (notep != NULL) {
191-
zval *child;
192-
nodep = create_notation(notep->name, notep->PublicID, notep->SystemID);
193-
MAKE_STD_ZVAL(child);
194-
child = php_dom_create_object(nodep, &ret, NULL, child, obj TSRMLS_CC);
195-
add_assoc_zval(*retval, (char *) nodep->name, child);
196-
}
197-
}
198-
efree(iter);
199-
}
200-
}
201108
return SUCCESS;
202109
}
203110

ext/dom/element.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,20 @@ PHP_FUNCTION(dom_element_get_elements_by_tag_name)
394394
zval *id;
395395
xmlNodePtr elemp;
396396
int name_len;
397-
dom_object *intern;
397+
dom_object *intern, *namednode;
398398
char *name;
399+
xmlChar *local;
399400

400401
DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr, intern);
401402

402403
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
403404
return;
404405
}
405406

406-
array_init(return_value);
407-
elemp = elemp->children;
408-
409-
dom_get_elements_by_tag_name_ns_raw(elemp, NULL, name, &return_value, intern TSRMLS_CC);
407+
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
408+
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
409+
local = xmlCharStrndup(name, name_len);
410+
dom_namednode_iter(intern, 0, namednode, NULL, local, NULL);
410411
}
411412
/* }}} end dom_element_get_elements_by_tag_name */
412413

@@ -708,18 +709,23 @@ PHP_FUNCTION(dom_element_get_elements_by_tag_name_ns)
708709
zval *id;
709710
xmlNodePtr elemp;
710711
int uri_len, name_len;
711-
dom_object *intern;
712+
dom_object *intern, *namednode;
712713
char *uri, *name;
714+
xmlChar *local, *nsuri;
715+
// xmlHashTable *ht;
713716

714717
DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr, intern);
715718

716719
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
717720
return;
718721
}
719722

720-
array_init(return_value);
723+
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
724+
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
725+
local = xmlCharStrndup(name, name_len);
726+
nsuri = xmlCharStrndup(uri, uri_len);
727+
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
721728

722-
dom_get_elements_by_tag_name_ns_raw(elemp->children, uri, name, &return_value, intern TSRMLS_CC);
723729
}
724730
/* }}} end dom_element_get_elements_by_tag_name_ns */
725731

ext/dom/examples/dom1.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function print_node($node)
2424
{
2525
print "Node Name: " . $node->nodeName;
2626
print "\nNode Type: " . $node->nodeType;
27-
$child_count = count($node->childNodes);
27+
$child_count = $node->childNodes->length;
2828
print "\nNum Children: " . $child_count;
2929
if($child_count <= 1){
3030
print "\nNode Content: " . $node->nodeValue;

ext/dom/examples/dom1.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
print_node_list($attrs);
6161

6262
echo "--------- children of an attribute\n";
63-
$children = current($attrs)->childNodes;
63+
$children = $attrs->item(0)->childNodes;
6464
print_node_list($children);
6565

6666
echo "--------- Add child to root\n";
@@ -80,8 +80,8 @@
8080
print_node_list($children);
8181

8282
echo "--------- Unlink Node\n";
83-
print_node($children[0]);
84-
$rootnode->removeChild($children[0]);
83+
print_node($children.item(0));
84+
$rootnode->removeChild($children.item(0));
8585
print_node_list($rootnode->childNodes);
8686
print $dom->savexml();
8787

0 commit comments

Comments
 (0)