rrichards               Tue Nov 22 21:52:57 2005 EDT

  Modified files:              
    /php-src/ext/dom    element.c attr.c 
  Log:
  implement setIDAttributeXXX functionality
  
http://cvs.php.net/diff.php/php-src/ext/dom/element.c?r1=1.39&r2=1.40&ty=u
Index: php-src/ext/dom/element.c
diff -u php-src/ext/dom/element.c:1.39 php-src/ext/dom/element.c:1.40
--- php-src/ext/dom/element.c:1.39      Thu Oct 27 19:49:34 2005
+++ php-src/ext/dom/element.c   Tue Nov 22 21:52:56 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: element.c,v 1.39 2005/10/27 23:49:34 rrichards Exp $ */
+/* $Id: element.c,v 1.40 2005/11/23 02:52:56 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -910,13 +910,57 @@
 /* }}} end dom_element_has_attribute_ns */
 
 
+static void php_set_attribute_id(xmlAttrPtr attrp, zend_bool is_id)
+{
+       if (is_id == 1 && attrp->atype != XML_ATTRIBUTE_ID) {
+               xmlChar *id_val;
+
+               id_val = xmlNodeListGetString(attrp->doc, attrp->children, 1);
+               if (id_val != NULL) {
+                       xmlAddID(NULL, attrp->doc, id_val, attrp);
+                       xmlFree(id_val);
+               }
+       } else {
+               if (attrp->atype == XML_ATTRIBUTE_ID) {
+                       xmlRemoveID(attrp->doc, attrp);
+                       attrp->atype = 0;
+               }
+       }
+}
+
 /* {{{ proto void dom_element_set_id_attribute(string name, boolean isId);
 URL: 
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttr
 Since: DOM Level 3
 */
 PHP_FUNCTION(dom_element_set_id_attribute)
 {
- DOM_NOT_IMPLEMENTED();
+       zval *id;
+       xmlNode *nodep;
+       xmlAttrPtr attrp;
+       dom_object *intern;
+       char *name;
+       int name_len;
+       zend_bool is_id;
+
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Osb", &id, U_CLASS_ENTRY(dom_element_class_entry), &name, &name_len, &is_id) 
== FAILURE) {
+               return;
+       }
+
+       DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
+
+       if (dom_node_is_read_only(nodep) == SUCCESS) {
+               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, 
dom_get_strict_error(intern->document) TSRMLS_CC);
+               RETURN_NULL();
+       }
+
+       attrp = xmlHasNsProp(nodep, name, NULL);
+       if (attrp == NULL) {
+               php_dom_throw_error(NOT_FOUND_ERR, 
dom_get_strict_error(intern->document) TSRMLS_CC);
+       } else {
+               php_set_attribute_id(attrp, is_id);
+       }
+
+       RETURN_NULL();
 }
 /* }}} end dom_element_set_id_attribute */
 
@@ -927,7 +971,33 @@
 */
 PHP_FUNCTION(dom_element_set_id_attribute_ns)
 {
- DOM_NOT_IMPLEMENTED();
+       zval *id, *rv = NULL;
+       xmlNodePtr elemp;
+       xmlAttrPtr attrp;
+       dom_object *intern;
+       int uri_len, name_len, ret;
+       char *uri, *name;
+       zend_bool is_id;
+
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Ossb", &id, U_CLASS_ENTRY(dom_element_class_entry), &uri, &uri_len, &name, 
&name_len, &is_id) == FAILURE) {
+               return;
+       }
+
+       DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
+
+       if (dom_node_is_read_only(elemp) == SUCCESS) {
+               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, 
dom_get_strict_error(intern->document) TSRMLS_CC);
+               RETURN_NULL();
+       }
+
+       attrp = xmlHasNsProp(elemp, name, uri);
+       if (attrp == NULL) {
+               php_dom_throw_error(NOT_FOUND_ERR, 
dom_get_strict_error(intern->document) TSRMLS_CC);
+       } else {
+               php_set_attribute_id(attrp, is_id);
+       }
+
+       RETURN_NULL();
 }
 /* }}} end dom_element_set_id_attribute_ns */
 
@@ -938,7 +1008,34 @@
 */
 PHP_FUNCTION(dom_element_set_id_attribute_node)
 {
- DOM_NOT_IMPLEMENTED();
+       zval *id, *node;
+       xmlNode *nodep;
+       xmlAttrPtr attrp;
+       dom_object *intern, *attrobj;
+       char *name;
+       int name_len;
+       zend_bool is_id;
+
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"OOb", &id, U_CLASS_ENTRY(dom_element_class_entry), &node, 
U_CLASS_ENTRY(dom_attr_class_entry), &is_id) == FAILURE) {
+               return;
+       }
+
+       DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
+
+       if (dom_node_is_read_only(nodep) == SUCCESS) {
+               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, 
dom_get_strict_error(intern->document) TSRMLS_CC);
+               RETURN_NULL();
+       }
+
+       DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
+
+       if (attrp->parent != nodep) {
+               php_dom_throw_error(NOT_FOUND_ERR, 
dom_get_strict_error(intern->document) TSRMLS_CC);
+       } else {
+               php_set_attribute_id(attrp, is_id);
+       }
+
+       RETURN_NULL();
 }
 /* }}} end dom_element_set_id_attribute_node */
 
http://cvs.php.net/diff.php/php-src/ext/dom/attr.c?r1=1.19&r2=1.20&ty=u
Index: php-src/ext/dom/attr.c
diff -u php-src/ext/dom/attr.c:1.19 php-src/ext/dom/attr.c:1.20
--- php-src/ext/dom/attr.c:1.19 Fri Aug 12 07:29:29 2005
+++ php-src/ext/dom/attr.c      Tue Nov 22 21:52:56 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: attr.c,v 1.19 2005/08/12 11:29:29 dmitry Exp $ */
+/* $Id: attr.c,v 1.20 2005/11/23 02:52:56 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -262,7 +262,6 @@
        zval *id;
        dom_object *intern;
        xmlAttrPtr attrp;
-       xmlNodePtr nodep;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"O", &id, U_CLASS_ENTRY(dom_attr_class_entry)) == FAILURE) {
                return;
@@ -270,9 +269,7 @@
 
        DOM_GET_OBJ(attrp, id, xmlAttrPtr, intern);
 
-       nodep = attrp->parent;
-
-       if (xmlIsID(attrp->doc, nodep, attrp)) {
+       if (attrp->atype == XML_ATTRIBUTE_ID) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to