cvs: php-src(PHP_5_2) /ext/dom element.c
| From: | Rob Richards | Date: | Fri, 02 Jun 2006 16:17:25 +0000 |
| Subject: | cvs: php-src(PHP_5_2) /ext/dom element.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-38569@lists.php.net to get a copy of this message | ||
rrichards Fri Jun 2 16:17:25 2006 UTC
Modified files: (Branch: PHP_5_2)
/php-src/ext/dom element.c
Log:
MFH: add setIdAttribute, setIdAttributeNS and setIdAttributeNode functionality
http://cvs.php.net/viewcvs.cgi/php-src/ext/dom/element.c?r1=1.36.2.4&r2=1.36.2.4.2.1&diff_format=u
Index: php-src/ext/dom/element.c
diff -u php-src/ext/dom/element.c:1.36.2.4 php-src/ext/dom/element.c:1.36.2.4.2.1
--- php-src/ext/dom/element.c:1.36.2.4 Wed May 3 08:43:04 2006
+++ php-src/ext/dom/element.c Fri Jun 2 16:17:25 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: element.c,v 1.36.2.4 2006/05/03 08:43:04 rrichards Exp $ */
+/* $Id: element.c,v 1.36.2.4.2.1 2006/06/02 16:17:25 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,
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 || attrp->type == XML_ATTRIBUTE_DECL) {
+ 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,
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 || attrp->type == XML_ATTRIBUTE_DECL) {
+ 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,
dom_element_class_entry, &node, 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 */