chregu Thu Apr 3 05:21:19 2003 EDT
Modified files:
/php4/ext/domxml php_domxml.c php_domxml.h
Log:
- Added domxml_elem_set_attribute_node() method. (Rob Richards)
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.242 php4/ext/domxml/php_domxml.c:1.243
--- php4/ext/domxml/php_domxml.c:1.242 Wed Apr 2 05:31:33 2003
+++ php4/ext/domxml/php_domxml.c Thu Apr 3 05:21:19 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.242 2003/04/02 10:31:33 chregu Exp $ */
+/* $Id: php_domxml.c,v 1.243 2003/04/03 10:21:19 chregu Exp $ */
/* TODO
* - Support Notation Nodes
@@ -429,9 +429,7 @@
PHP_FALIAS(set_attribute, domxml_elem_set_attribute,
NULL)
PHP_FALIAS(remove_attribute, domxml_elem_remove_attribute, NULL)
PHP_FALIAS(get_attribute_node, domxml_elem_get_attribute_node, NULL)
-/* since this function is not implemented, outcomment it for the time beeing
PHP_FALIAS(set_attribute_node, domxml_elem_set_attribute_node, NULL)
-*/
#if defined(LIBXML_XPATH_ENABLED)
PHP_FALIAS(get_elements_by_tagname, domxml_elem_get_elements_by_tagname,
NULL)
#endif
@@ -2849,32 +2847,72 @@
/* {{{ proto bool domxml_elem_set_attribute_node(object attr)
Sets value of given attribute */
-/* since this function is not implemented, outcomment it for the time beeing
PHP_FUNCTION(domxml_elem_set_attribute_node)
{
- zval *id, **arg1, *rv = NULL;
+ zval *id, *node, *rv = NULL;
xmlNode *nodep;
- xmlAttr *attrp, *newattrp;
+ xmlAttr *attrp, *newattrp, *existattrp;
int ret;
- if ((ZEND_NUM_ARGS() == 1) && (zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
+ DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
+ return;
}
- id = getThis();
- nodep = php_dom_get_object(id, le_domxmlelementp, 0 TSRMLS_CC);
- attrp = php_dom_get_object(*arg1, le_domxmlattrp, 0 TSRMLS_CC);
+ DOMXML_GET_OBJ(attrp, node, le_domxmlnodep);
- FIXME: The following line doesn't work
- newattrp = xmlCopyProp(nodep, attrp);
- if (!newattrp) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such attribute '%s'",
attrp->name);
+ if (attrp->type != XML_ATTRIBUTE_NODE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is
required");
RETURN_FALSE;
}
+
+ existattrp = xmlHasProp(nodep,attrp->name);
+ if (existattrp != NULL) {
+ /* We cannot unlink an existing attribute as it may never be freed
+ Only the content of the text node of an attribute node is transfered
over */
+
+ xmlChar *mem;
+ xmlNode *first, *firstattrp;
+
+ first = existattrp->children;
+ firstattrp = attrp->children;
+ if (mem = xmlNodeGetContent(firstattrp)) {
+ if (!first) {
+ xmlNodeSetContent((xmlNode *) existattrp, mem);
+ } else {
+ xmlNodeSetContent(first, mem);
+ }
+ xmlFree(mem);
+ newattrp = existattrp;
+ } else {
+ RETURN_FALSE;
+ }
+ } else {
+ /* xmlCopyProp does not add the copy to the element node.
+ It does set the parent of the copy to the element node however
*/
+ newattrp = xmlCopyProp(nodep, attrp);
+ if (!newattrp) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such attribute
'%s'", attrp->name);
+ RETURN_FALSE;
+ } else {
+ xmlAttr *prop;
+ prop = nodep->properties;
+ if (prop == NULL) {
+ nodep->properties = newattrp;
+ } else {
+ while (prop->next != NULL) {
+ prop = prop->next;
+ }
+ prop->next = newattrp;
+ newattrp->prev = prop;
+ }
+ }
+ }
+
DOMXML_RET_OBJ(rv, (xmlNodePtr) newattrp, &ret);
}
-*/
/* }}} */
/* {{{ proto string domxml_elem_has_attribute(string attrname)
Index: php4/ext/domxml/php_domxml.h
diff -u php4/ext/domxml/php_domxml.h:1.75 php4/ext/domxml/php_domxml.h:1.76
--- php4/ext/domxml/php_domxml.h:1.75 Mon Jan 6 04:59:53 2003
+++ php4/ext/domxml/php_domxml.h Thu Apr 3 05:21:19 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.h,v 1.75 2003/01/06 09:59:53 chregu Exp $ */
+/* $Id: php_domxml.h,v 1.76 2003/04/03 10:21:19 chregu Exp $ */
#ifndef PHP_DOMXML_H
#define PHP_DOMXML_H
@@ -170,9 +170,7 @@
PHP_FUNCTION(domxml_elem_set_attribute);
PHP_FUNCTION(domxml_elem_remove_attribute);
PHP_FUNCTION(domxml_elem_get_attribute_node);
-/* since this function is not really implemented, outcomment it for the time beeing
PHP_FUNCTION(domxml_elem_set_attribute_node);
-*/
PHP_FUNCTION(domxml_elem_get_elements_by_tagname);
PHP_FUNCTION(domxml_elem_has_attribute);
/* Class CData methods */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php