diff options
author | Christian Stocker <chregu@php.net> | 2002-08-16 08:42:41 +0000 |
---|---|---|
committer | Christian Stocker <chregu@php.net> | 2002-08-16 08:42:41 +0000 |
commit | 9c20c7c9ba99e214a337093fc06bfe5cb3675e26 (patch) | |
tree | 953d67c6c27839a569fe8b08439f4a1fb9fefe6c | |
parent | 38eea2e817baf6742321703256e2738272cf6c30 (diff) | |
download | php-git-9c20c7c9ba99e214a337093fc06bfe5cb3675e26.tar.gz |
More on the way to W3C coformance:
@- Changed DomNode->next_sibling and DomNode->previous_sibling to return NULL
@ instead of false (W3C specs). (chregu)
@- Changed DomNode->insert_before() and DomNode->append_child() to conform to
@ W3C specs (moving not copying nodes, accepting NULL as 2nd param). (chregu)
-rw-r--r-- | ext/domxml/php_domxml.c | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c index 025dcd069a..a10561d5d8 100644 --- a/ext/domxml/php_domxml.c +++ b/ext/domxml/php_domxml.c @@ -2115,7 +2115,8 @@ PHP_FUNCTION(domxml_node_next_sibling) first = nodep->next; if (!first) { - RETURN_FALSE; + rv = NULL; + return; } DOMXML_RET_OBJ(rv, first, &ret); @@ -2136,7 +2137,8 @@ PHP_FUNCTION(domxml_node_previous_sibling) first = nodep->prev; if (!first) { - RETURN_FALSE; + rv = NULL; + return; } DOMXML_RET_OBJ(rv, first, &ret); @@ -2357,15 +2359,11 @@ PHP_FUNCTION(domxml_node_replace_node) PHP_FUNCTION(domxml_node_append_child) { zval *id, *rv = NULL, *node; - xmlNodePtr child, nodep, new_child; + xmlNodePtr child, parent, new_child; int ret; - DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) { - return; - } - + DOMXML_PARAM_ONE(parent, id, le_domxmlnodep, "o", &node); + DOMXML_GET_OBJ(child, node, le_domxmlnodep); if (child->type == XML_ATTRIBUTE_NODE) { @@ -2373,29 +2371,18 @@ PHP_FUNCTION(domxml_node_append_child) RETURN_FALSE; } - if (NULL == (new_child = xmlCopyNode(child, 1))) { - php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - /* copy namespace if one is there */ - if (child->ns) { - new_child->ns = child->ns; + /* first unlink node, if child is already a child of parent */ + if (child->parent == parent){ + xmlUnlinkNode(child); } + new_child = xmlAddChild(parent, child); - /* FIXME reverted xmlAddChildList; crashes - * Uwe: must have been a temporary problem. It works for me with both - * xmlAddChildList and xmlAddChild - */ - - child = xmlAddChild(nodep, new_child); - - if (NULL == child) { + if (NULL == new_child) { php_error(E_WARNING, "%s(): couldn't append node", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } - DOMXML_RET_OBJ(rv, child, &ret); + DOMXML_RET_OBJ(rv, new_child, &ret); } /* }}} */ @@ -2442,19 +2429,26 @@ PHP_FUNCTION(domxml_node_append_sibling) PHP_FUNCTION(domxml_node_insert_before) { zval *id, *rv = NULL, *node, *ref; - xmlNodePtr child, new_child, nodep, refp; + xmlNodePtr child, new_child, parent, refp; int ret; - DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo", &node, &ref) == FAILURE) { - return; - } + DOMXML_PARAM_TWO(parent, id, le_domxmlnodep, "oo!", &node, &ref); DOMXML_GET_OBJ(child, node, le_domxmlnodep); - DOMXML_GET_OBJ(refp, ref, le_domxmlnodep); - new_child = xmlAddPrevSibling(refp, child); + if (ref != NULL) { + DOMXML_GET_OBJ(refp, ref, le_domxmlnodep); + new_child = xmlAddPrevSibling(refp, child); + } else { + /* first unlink node, if child is already a child of parent + for some strange reason, this is needed + */ + if (child->parent == parent){ + xmlUnlinkNode(child); + } + new_child = xmlAddChild(parent, child); + } + if (NULL == new_child) { php_error(E_WARNING, "%s(): couldn't add newnode as the previous sibling of refnode", get_active_function_name(TSRMLS_C)); |