Back to index

php5  5.3.10
element.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Christian Stocker <chregu@php.net>                          |
00016    |          Rob Richards <rrichards@php.net>                            |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: element.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025 
00026 #include "php.h"
00027 #if HAVE_LIBXML && HAVE_DOM
00028 #include "php_dom.h"
00029 
00030 /* {{{ arginfo */
00031 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_get_attribute, 0, 0, 1)
00032        ZEND_ARG_INFO(0, name)
00033 ZEND_END_ARG_INFO();
00034 
00035 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_attribute, 0, 0, 2)
00036        ZEND_ARG_INFO(0, name)
00037        ZEND_ARG_INFO(0, value)
00038 ZEND_END_ARG_INFO();
00039 
00040 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_remove_attribute, 0, 0, 1)
00041        ZEND_ARG_INFO(0, name)
00042 ZEND_END_ARG_INFO();
00043 
00044 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_get_attribute_node, 0, 0, 1)
00045        ZEND_ARG_INFO(0, name)
00046 ZEND_END_ARG_INFO();
00047 
00048 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_attribute_node, 0, 0, 1)
00049        ZEND_ARG_OBJ_INFO(0, newAttr, DOMAttr, 0)
00050 ZEND_END_ARG_INFO();
00051 
00052 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_remove_attribute_node, 0, 0, 1)
00053        ZEND_ARG_OBJ_INFO(0, oldAttr, DOMAttr, 0)
00054 ZEND_END_ARG_INFO();
00055 
00056 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_get_elements_by_tag_name, 0, 0, 1)
00057        ZEND_ARG_INFO(0, name)
00058 ZEND_END_ARG_INFO();
00059 
00060 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_get_attribute_ns, 0, 0, 2)
00061        ZEND_ARG_INFO(0, namespaceURI)
00062        ZEND_ARG_INFO(0, localName)
00063 ZEND_END_ARG_INFO();
00064 
00065 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_attribute_ns, 0, 0, 3)
00066        ZEND_ARG_INFO(0, namespaceURI)
00067        ZEND_ARG_INFO(0, qualifiedName)
00068        ZEND_ARG_INFO(0, value)
00069 ZEND_END_ARG_INFO();
00070 
00071 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_remove_attribute_ns, 0, 0, 2)
00072        ZEND_ARG_INFO(0, namespaceURI)
00073        ZEND_ARG_INFO(0, localName)
00074 ZEND_END_ARG_INFO();
00075 
00076 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_get_attribute_node_ns, 0, 0, 2)
00077        ZEND_ARG_INFO(0, namespaceURI)
00078        ZEND_ARG_INFO(0, localName)
00079 ZEND_END_ARG_INFO();
00080 
00081 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_attribute_node_ns, 0, 0, 1)
00082        ZEND_ARG_OBJ_INFO(0, newAttr, DOMAttr, 0)
00083 ZEND_END_ARG_INFO();
00084 
00085 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_get_elements_by_tag_name_ns, 0, 0, 2)
00086        ZEND_ARG_INFO(0, namespaceURI)
00087        ZEND_ARG_INFO(0, localName)
00088 ZEND_END_ARG_INFO();
00089 
00090 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_has_attribute, 0, 0, 1)
00091        ZEND_ARG_INFO(0, name)
00092 ZEND_END_ARG_INFO();
00093 
00094 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_has_attribute_ns, 0, 0, 2)
00095        ZEND_ARG_INFO(0, namespaceURI)
00096        ZEND_ARG_INFO(0, localName)
00097 ZEND_END_ARG_INFO();
00098 
00099 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_id_attribute, 0, 0, 2)
00100        ZEND_ARG_INFO(0, name)
00101        ZEND_ARG_INFO(0, isId)
00102 ZEND_END_ARG_INFO();
00103 
00104 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_id_attribute_ns, 0, 0, 3)
00105        ZEND_ARG_INFO(0, namespaceURI)
00106        ZEND_ARG_INFO(0, localName)
00107        ZEND_ARG_INFO(0, isId)
00108 ZEND_END_ARG_INFO();
00109 
00110 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_set_id_attribute_node, 0, 0, 2)
00111        ZEND_ARG_OBJ_INFO(0, attr, DOMAttr, 0)
00112        ZEND_ARG_INFO(0, isId)
00113 ZEND_END_ARG_INFO();
00114 
00115 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_element_construct, 0, 0, 1)
00116        ZEND_ARG_INFO(0, name)
00117        ZEND_ARG_INFO(0, value)
00118        ZEND_ARG_INFO(0, uri)
00119 ZEND_END_ARG_INFO();
00120 /* }}} */
00121 
00122 /*
00123 * class DOMElement extends DOMNode 
00124 *
00125 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-745549614
00126 * Since: 
00127 */
00128 
00129 const zend_function_entry php_dom_element_class_functions[] = { /* {{{ */
00130        PHP_FALIAS(getAttribute, dom_element_get_attribute, arginfo_dom_element_get_attribute)
00131        PHP_FALIAS(setAttribute, dom_element_set_attribute, arginfo_dom_element_set_attribute)
00132        PHP_FALIAS(removeAttribute, dom_element_remove_attribute, arginfo_dom_element_remove_attribute)
00133        PHP_FALIAS(getAttributeNode, dom_element_get_attribute_node, arginfo_dom_element_get_attribute_node)
00134        PHP_FALIAS(setAttributeNode, dom_element_set_attribute_node, arginfo_dom_element_set_attribute_node)
00135        PHP_FALIAS(removeAttributeNode, dom_element_remove_attribute_node, arginfo_dom_element_remove_attribute_node)
00136        PHP_FALIAS(getElementsByTagName, dom_element_get_elements_by_tag_name, arginfo_dom_element_get_elements_by_tag_name)
00137        PHP_FALIAS(getAttributeNS, dom_element_get_attribute_ns, arginfo_dom_element_get_attribute_ns)
00138        PHP_FALIAS(setAttributeNS, dom_element_set_attribute_ns, arginfo_dom_element_set_attribute_ns)
00139        PHP_FALIAS(removeAttributeNS, dom_element_remove_attribute_ns, arginfo_dom_element_remove_attribute_ns)
00140        PHP_FALIAS(getAttributeNodeNS, dom_element_get_attribute_node_ns, arginfo_dom_element_get_attribute_node_ns)
00141        PHP_FALIAS(setAttributeNodeNS, dom_element_set_attribute_node_ns, arginfo_dom_element_set_attribute_node_ns)
00142        PHP_FALIAS(getElementsByTagNameNS, dom_element_get_elements_by_tag_name_ns, arginfo_dom_element_get_elements_by_tag_name_ns)
00143        PHP_FALIAS(hasAttribute, dom_element_has_attribute, arginfo_dom_element_has_attribute)
00144        PHP_FALIAS(hasAttributeNS, dom_element_has_attribute_ns, arginfo_dom_element_has_attribute_ns)
00145        PHP_FALIAS(setIdAttribute, dom_element_set_id_attribute, arginfo_dom_element_set_id_attribute)
00146        PHP_FALIAS(setIdAttributeNS, dom_element_set_id_attribute_ns, arginfo_dom_element_set_id_attribute_ns)
00147        PHP_FALIAS(setIdAttributeNode, dom_element_set_id_attribute_node, arginfo_dom_element_set_id_attribute_node)
00148        PHP_ME(domelement, __construct, arginfo_dom_element_construct, ZEND_ACC_PUBLIC)
00149        PHP_FE_END
00150 };
00151 /* }}} */
00152 
00153 /* {{{ proto void DOMElement::__construct(string name, [string value], [string uri]); */
00154 PHP_METHOD(domelement, __construct)
00155 {
00156 
00157        zval *id;
00158        xmlNodePtr nodep = NULL, oldnode = NULL;
00159        dom_object *intern;
00160        char *name, *value = NULL, *uri = NULL;
00161        char *localname = NULL, *prefix = NULL;
00162        int errorcode = 0, uri_len = 0;
00163        int name_len, value_len = 0, name_valid;
00164        xmlNsPtr nsptr = NULL;
00165        zend_error_handling error_handling;
00166 
00167        zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
00168        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s!s", &id, dom_element_class_entry, &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) {
00169               zend_restore_error_handling(&error_handling TSRMLS_CC);
00170               return;
00171        }
00172        zend_restore_error_handling(&error_handling TSRMLS_CC);
00173 
00174        name_valid = xmlValidateName((xmlChar *) name, 0);
00175        if (name_valid != 0) {
00176               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
00177               RETURN_FALSE;
00178        }
00179 
00180        /* Namespace logic is seperate and only when uri passed in to insure no BC breakage */
00181        if (uri_len > 0) {
00182               errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
00183               if (errorcode == 0) {
00184                      nodep = xmlNewNode (NULL, (xmlChar *)localname);
00185                      if (nodep != NULL && uri != NULL) {
00186                             nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
00187                             xmlSetNs(nodep, nsptr);
00188                      }
00189               }
00190               xmlFree(localname);
00191               if (prefix != NULL) {
00192                      xmlFree(prefix);
00193               }
00194               if (errorcode != 0) {
00195                      if (nodep != NULL) {
00196                             xmlFreeNode(nodep);
00197                      }
00198                      php_dom_throw_error(errorcode, 1 TSRMLS_CC);
00199                      RETURN_FALSE;
00200               }
00201        } else {
00202            /* If you don't pass a namespace uri, then you can't set a prefix */
00203            localname = xmlSplitQName2((xmlChar *)name, (xmlChar **) &prefix);
00204            if (prefix != NULL) {
00205                      xmlFree(localname);
00206                      xmlFree(prefix);
00207                php_dom_throw_error(NAMESPACE_ERR, 1 TSRMLS_CC);
00208                RETURN_FALSE;
00209            }
00210               nodep = xmlNewNode(NULL, (xmlChar *) name);
00211        }
00212 
00213        if (!nodep) {
00214               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
00215               RETURN_FALSE;
00216        }
00217 
00218        if (value_len > 0) {
00219               xmlNodeSetContentLen(nodep, (xmlChar *) value, value_len);
00220        }
00221 
00222        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
00223        if (intern != NULL) {
00224               oldnode = dom_object_get_node(intern);
00225               if (oldnode != NULL) {
00226                      php_libxml_node_free_resource(oldnode  TSRMLS_CC);
00227               }
00228               php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
00229        }
00230 }
00231 /* }}} end DOMElement::__construct */
00232 
00233 /* {{{ tagName       string 
00234 readonly=yes 
00235 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-104682815
00236 Since: 
00237 */
00238 int dom_element_tag_name_read(dom_object *obj, zval **retval TSRMLS_DC)
00239 {
00240        xmlNodePtr nodep;
00241        xmlNsPtr ns;
00242        xmlChar *qname;
00243 
00244        nodep = dom_object_get_node(obj);
00245 
00246        if (nodep == NULL) {
00247               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00248               return FAILURE;
00249        }
00250 
00251        ALLOC_ZVAL(*retval);
00252        ns = nodep->ns;
00253        if (ns != NULL && ns->prefix) {
00254               qname = xmlStrdup(ns->prefix);
00255               qname = xmlStrcat(qname, (xmlChar *)":");
00256               qname = xmlStrcat(qname, nodep->name);
00257               ZVAL_STRING(*retval, (char *)qname, 1);
00258               xmlFree(qname);
00259        } else {
00260               ZVAL_STRING(*retval, (char *) nodep->name, 1);
00261        }
00262 
00263        return SUCCESS;
00264 }
00265 
00266 /* }}} */
00267 
00268 /* {{{ schemaTypeInfo       typeinfo      
00269 readonly=yes 
00270 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Element-schemaTypeInfo
00271 Since: DOM Level 3
00272 */
00273 int dom_element_schema_type_info_read(dom_object *obj, zval **retval TSRMLS_DC)
00274 {
00275        ALLOC_ZVAL(*retval);
00276        ZVAL_NULL(*retval);
00277        return SUCCESS;
00278 }
00279 
00280 /* }}} */
00281 
00282 static xmlNodePtr dom_get_dom1_attribute(xmlNodePtr elem, xmlChar *name) /* {{{ */
00283 {
00284     int len;
00285     const xmlChar *nqname;
00286 
00287        nqname = xmlSplitQName3(name, &len);
00288        if (nqname != NULL) {
00289               xmlNsPtr ns;
00290               xmlChar *prefix = xmlStrndup(name, len);
00291               if (prefix && xmlStrEqual(prefix, (xmlChar *)"xmlns")) {
00292                      ns = elem->nsDef;
00293                      while (ns) {
00294                             if (xmlStrEqual(ns->prefix, nqname)) {
00295                                    break;
00296                             }
00297                             ns = ns->next;
00298                      }
00299                      xmlFree(prefix);
00300                      return (xmlNodePtr)ns;
00301               }
00302               ns = xmlSearchNs(elem->doc, elem, prefix);
00303               if (prefix != NULL) {
00304                      xmlFree(prefix);
00305               }
00306               if (ns != NULL) {
00307                      return (xmlNodePtr)xmlHasNsProp(elem, nqname, ns->href);
00308               }
00309        } else {
00310               if (xmlStrEqual(name, (xmlChar *)"xmlns")) {
00311                      xmlNsPtr nsPtr = elem->nsDef;
00312                      while (nsPtr) {
00313                             if (nsPtr->prefix == NULL) {
00314                                    return (xmlNodePtr)nsPtr;
00315                             }
00316                             nsPtr = nsPtr->next;
00317                      }
00318                      return NULL;
00319               }
00320        }
00321        return (xmlNodePtr)xmlHasNsProp(elem, name, NULL);
00322 }
00323 /* }}} */
00324 
00325 /* {{{ proto string dom_element_get_attribute(string name);
00326 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-666EE0F9
00327 Since:
00328 */
00329 PHP_FUNCTION(dom_element_get_attribute)
00330 {
00331        zval *id;
00332        xmlNode *nodep;
00333        char *name;
00334        xmlChar *value = NULL;
00335        dom_object *intern;
00336        xmlNodePtr attr;
00337        int name_len;
00338 
00339        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
00340               return;
00341        }
00342 
00343        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00344 
00345        attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
00346        if (attr) {
00347               switch (attr->type) {
00348                      case XML_ATTRIBUTE_NODE:
00349                             value = xmlNodeListGetString(attr->doc, attr->children, 1);
00350                             break;
00351                      case XML_NAMESPACE_DECL:
00352                             value = xmlStrdup(((xmlNsPtr)attr)->href);
00353                             break;
00354                      default:
00355                             value = xmlStrdup(((xmlAttributePtr)attr)->defaultValue);
00356               }
00357        }
00358        
00359        if (value == NULL) {
00360               RETURN_EMPTY_STRING();
00361        } else {
00362               RETVAL_STRING((char *)value, 1);
00363               xmlFree(value);
00364        }
00365 }
00366 /* }}} end dom_element_get_attribute */
00367 
00368 /* {{{ proto void dom_element_set_attribute(string name, string value);
00369 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-F68F082
00370 Since: 
00371 */
00372 PHP_FUNCTION(dom_element_set_attribute)
00373 {
00374        zval *id, *rv = NULL;
00375        xmlNode *nodep;
00376        xmlNodePtr attr = NULL;
00377        int ret, name_len, value_len, name_valid;
00378        dom_object *intern;
00379        char *name, *value;
00380 
00381        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_element_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
00382               return;
00383        }
00384 
00385        if (name_len == 0) {
00386               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required");
00387               RETURN_FALSE;
00388        }
00389 
00390        name_valid = xmlValidateName((xmlChar *) name, 0);
00391        if (name_valid != 0) {
00392               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
00393               RETURN_FALSE;
00394        }
00395 
00396        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00397 
00398        if (dom_node_is_read_only(nodep) == SUCCESS) {
00399               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00400               RETURN_FALSE;
00401        }
00402 
00403        attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
00404        if (attr != NULL) {
00405               switch (attr->type) {
00406                      case XML_ATTRIBUTE_NODE:
00407                             node_list_unlink(attr->children TSRMLS_CC);
00408                             break;
00409                      case XML_NAMESPACE_DECL:
00410                             RETURN_FALSE;
00411                      default:
00412                             break;
00413               }
00414 
00415        }
00416 
00417        if (xmlStrEqual((xmlChar *)name, (xmlChar *)"xmlns")) {
00418               if (xmlNewNs(nodep, (xmlChar *)value, NULL)) {
00419                      RETURN_TRUE;
00420               }
00421        } else {
00422               attr = (xmlNodePtr)xmlSetProp(nodep, (xmlChar *) name, (xmlChar *)value);
00423        }
00424        if (!attr) {
00425               php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such attribute '%s'", name);
00426               RETURN_FALSE;
00427        }
00428 
00429        DOM_RET_OBJ(rv, attr, &ret, intern);
00430 
00431 }
00432 /* }}} end dom_element_set_attribute */
00433 
00434 /* {{{ proto void dom_element_remove_attribute(string name);
00435 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D6AC0F9
00436 Since:
00437 */
00438 PHP_FUNCTION(dom_element_remove_attribute)
00439 {
00440        zval *id;
00441        xmlNodePtr nodep, attrp;
00442        dom_object *intern;
00443        int name_len;
00444        char *name;
00445 
00446        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
00447               return;
00448        }
00449 
00450        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00451 
00452        if (dom_node_is_read_only(nodep) == SUCCESS) {
00453               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00454               RETURN_FALSE;
00455        }
00456 
00457        attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
00458        if (attrp == NULL) {
00459               RETURN_FALSE;
00460        }
00461 
00462        switch (attrp->type) {
00463               case XML_ATTRIBUTE_NODE:
00464                      if (php_dom_object_get_data(attrp) == NULL) {
00465                      node_list_unlink(attrp->children TSRMLS_CC);
00466                             xmlUnlinkNode(attrp);
00467                             xmlFreeProp((xmlAttrPtr)attrp);
00468               } else {
00469                             xmlUnlinkNode(attrp);
00470               }
00471                      break;
00472               case XML_NAMESPACE_DECL:
00473                      RETURN_FALSE;
00474               default:
00475                      break;
00476        }
00477 
00478        RETURN_TRUE;
00479 }
00480 /* }}} end dom_element_remove_attribute */
00481 
00482 /* {{{ proto DOMAttr dom_element_get_attribute_node(string name);
00483 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-217A91B8
00484 Since: 
00485 */
00486 PHP_FUNCTION(dom_element_get_attribute_node)
00487 {
00488        zval *id, *rv = NULL;
00489        xmlNodePtr nodep, attrp;
00490        int name_len, ret;
00491        dom_object *intern;
00492        char *name;
00493 
00494        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
00495               return;
00496        }
00497 
00498        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00499 
00500        attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
00501        if (attrp == NULL) {
00502               RETURN_FALSE;
00503        }
00504 
00505        if (attrp->type == XML_NAMESPACE_DECL) {
00506               xmlNsPtr curns;
00507               xmlNodePtr nsparent;
00508 
00509               nsparent = attrp->_private;
00510               curns = xmlNewNs(NULL, attrp->name, NULL);
00511               if (attrp->children) {
00512                      curns->prefix = xmlStrdup((xmlChar *) attrp->children);
00513               }
00514               if (attrp->children) {
00515                      attrp = xmlNewDocNode(nodep->doc, NULL, (xmlChar *) attrp->children, attrp->name);
00516               } else {
00517                      attrp = xmlNewDocNode(nodep->doc, NULL, (xmlChar *)"xmlns", attrp->name);
00518               }
00519               attrp->type = XML_NAMESPACE_DECL;
00520               attrp->parent = nsparent;
00521               attrp->ns = curns;
00522        }
00523 
00524        DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret, intern);
00525 }
00526 /* }}} end dom_element_get_attribute_node */
00527 
00528 /* {{{ proto DOMAttr dom_element_set_attribute_node(DOMAttr newAttr);
00529 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-887236154
00530 Since: 
00531 */
00532 PHP_FUNCTION(dom_element_set_attribute_node)
00533 {
00534        zval *id, *node, *rv = NULL;
00535        xmlNode *nodep;
00536        xmlAttr *attrp, *existattrp = NULL;
00537        dom_object *intern, *attrobj, *oldobj;
00538        int ret;
00539 
00540        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_element_class_entry, &node, dom_attr_class_entry) == FAILURE) {
00541               return;
00542        }
00543 
00544        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00545 
00546        if (dom_node_is_read_only(nodep) == SUCCESS) {
00547               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00548               RETURN_FALSE;
00549        }
00550 
00551        DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
00552 
00553        if (attrp->type != XML_ATTRIBUTE_NODE) {
00554               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is required");
00555               RETURN_FALSE;
00556        }
00557 
00558        if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
00559               php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00560               RETURN_FALSE;
00561        }
00562 
00563        existattrp = xmlHasProp(nodep, attrp->name);
00564        if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
00565               if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL && 
00566                      ((php_libxml_node_ptr *)oldobj->ptr)->node == (xmlNodePtr) attrp)
00567               {
00568                      RETURN_NULL();
00569               }
00570               xmlUnlinkNode((xmlNodePtr) existattrp);
00571        }
00572 
00573        if (attrp->parent != NULL) {
00574               xmlUnlinkNode((xmlNodePtr) attrp);
00575        }
00576 
00577        if (attrp->doc == NULL && nodep->doc != NULL) {
00578               attrobj->document = intern->document;
00579               php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL TSRMLS_CC);
00580        }
00581 
00582        xmlAddChild(nodep, (xmlNodePtr) attrp);
00583 
00584        /* Returns old property if removed otherwise NULL */
00585        if (existattrp != NULL) {
00586               DOM_RET_OBJ(rv, (xmlNodePtr) existattrp, &ret, intern);
00587        } else {
00588               RETVAL_NULL();
00589        }
00590 
00591 }
00592 /* }}} end dom_element_set_attribute_node */
00593 
00594 /* {{{ proto DOMAttr dom_element_remove_attribute_node(DOMAttr oldAttr);
00595 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D589198
00596 Since: 
00597 */
00598 PHP_FUNCTION(dom_element_remove_attribute_node)
00599 {
00600        zval *id, *node, *rv = NULL;
00601        xmlNode *nodep;
00602        xmlAttr *attrp;
00603        dom_object *intern, *attrobj;
00604        int ret;
00605 
00606        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_element_class_entry, &node, dom_attr_class_entry) == FAILURE) {
00607               return;
00608        }
00609 
00610        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00611 
00612        if (dom_node_is_read_only(nodep) == SUCCESS) {
00613               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00614               RETURN_FALSE;
00615        }
00616 
00617        DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
00618 
00619        if (attrp->type != XML_ATTRIBUTE_NODE || attrp->parent != nodep) {
00620               php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00621               RETURN_FALSE;
00622        }
00623 
00624        xmlUnlinkNode((xmlNodePtr) attrp);
00625 
00626        DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret, intern);
00627 
00628 }
00629 /* }}} end dom_element_remove_attribute_node */
00630 
00631 /* {{{ proto DOMNodeList dom_element_get_elements_by_tag_name(string name);
00632 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1938918D
00633 Since: 
00634 */
00635 PHP_FUNCTION(dom_element_get_elements_by_tag_name)
00636 {
00637        zval *id;
00638        xmlNodePtr elemp;
00639        int name_len;
00640        dom_object *intern, *namednode;
00641        char *name;
00642        xmlChar *local;
00643 
00644        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
00645               return;
00646        }
00647 
00648        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
00649 
00650        php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
00651        namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
00652        local = xmlCharStrndup(name, name_len);
00653        dom_namednode_iter(intern, 0, namednode, NULL, local, NULL TSRMLS_CC);
00654 }
00655 /* }}} end dom_element_get_elements_by_tag_name */
00656 
00657 /* {{{ proto string dom_element_get_attribute_ns(string namespaceURI, string localName);
00658 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElGetAttrNS
00659 Since: DOM Level 2
00660 */
00661 PHP_FUNCTION(dom_element_get_attribute_ns)
00662 {
00663        zval *id;
00664        xmlNodePtr elemp;
00665        xmlNsPtr nsptr;
00666        dom_object *intern;
00667        int uri_len = 0, name_len = 0;
00668        char *uri, *name;
00669        xmlChar *strattr;
00670 
00671        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
00672               return;
00673        }
00674 
00675        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
00676 
00677        strattr = xmlGetNsProp(elemp, (xmlChar *) name, (xmlChar *) uri);
00678 
00679        if (strattr != NULL) {
00680               RETVAL_STRING((char *)strattr, 1);
00681               xmlFree(strattr);
00682        } else {
00683               if (xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
00684                      nsptr = dom_get_nsdecl(elemp, (xmlChar *)name);
00685                      if (nsptr != NULL) {
00686                             RETVAL_STRING((char *) nsptr->href, 1);
00687                      } else {
00688                             RETVAL_EMPTY_STRING();
00689                      }
00690               } else {
00691                      RETVAL_EMPTY_STRING();
00692               }
00693        }
00694 
00695 }
00696 /* }}} end dom_element_get_attribute_ns */
00697 
00698 static xmlNsPtr _dom_new_reconNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) /* {{{ */
00699 {
00700     xmlNsPtr def;
00701     xmlChar prefix[50];
00702     int counter = 1;
00703 
00704        if ((tree == NULL) || (ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
00705               return NULL;
00706        }
00707 
00708        /* Code taken from libxml2 (2.6.20) xmlNewReconciliedNs
00709         *
00710         * Find a close prefix which is not already in use.
00711         * Let's strip namespace prefixes longer than 20 chars !
00712         */
00713        if (ns->prefix == NULL)
00714               snprintf((char *) prefix, sizeof(prefix), "default");
00715        else
00716               snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix);
00717 
00718        def = xmlSearchNs(doc, tree, prefix);
00719        while (def != NULL) {
00720               if (counter > 1000) return(NULL);
00721               if (ns->prefix == NULL)
00722                      snprintf((char *) prefix, sizeof(prefix), "default%d", counter++);
00723               else
00724                      snprintf((char *) prefix, sizeof(prefix), "%.20s%d", 
00725                      (char *)ns->prefix, counter++);
00726               def = xmlSearchNs(doc, tree, prefix);
00727        }
00728 
00729        /*
00730         * OK, now we are ready to create a new one.
00731         */
00732        def = xmlNewNs(tree, ns->href, prefix);
00733        return(def);
00734 }
00735 /* }}} */
00736 
00737 /* {{{ proto void dom_element_set_attribute_ns(string namespaceURI, string qualifiedName, string value);
00738 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetAttrNS
00739 Since: DOM Level 2
00740 */
00741 PHP_FUNCTION(dom_element_set_attribute_ns)
00742 {
00743        zval *id;
00744        xmlNodePtr elemp, nodep = NULL;
00745        xmlNsPtr nsptr;
00746        xmlAttr *attr;
00747        int uri_len = 0, name_len = 0, value_len = 0;
00748        char *uri, *name, *value;
00749        char *localname = NULL, *prefix = NULL;
00750        dom_object *intern;
00751        int errorcode = 0, stricterror, is_xmlns = 0, name_valid;
00752 
00753        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!ss", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len, &value, &value_len) == FAILURE) {
00754               return;
00755        }
00756 
00757        if (name_len == 0) {
00758               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required");
00759               RETURN_FALSE;
00760        }
00761 
00762        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
00763 
00764        stricterror = dom_get_strict_error(intern->document);
00765 
00766        if (dom_node_is_read_only(elemp) == SUCCESS) {
00767               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror TSRMLS_CC);
00768               RETURN_NULL();
00769        }
00770 
00771        errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
00772 
00773        if (errorcode == 0) {
00774               if (uri_len > 0) {
00775                      nodep = (xmlNodePtr) xmlHasNsProp(elemp, (xmlChar *) localname, (xmlChar *) uri);
00776                      if (nodep != NULL && nodep->type != XML_ATTRIBUTE_DECL) {
00777                             node_list_unlink(nodep->children TSRMLS_CC);
00778                      }
00779 
00780                      if ((xmlStrEqual((xmlChar *) prefix, (xmlChar *)"xmlns") || 
00781                             (prefix == NULL && xmlStrEqual((xmlChar *) localname, (xmlChar *)"xmlns"))) && 
00782                             xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
00783                             is_xmlns = 1;
00784                             if (prefix == NULL) {
00785                                    nsptr = dom_get_nsdecl(elemp, NULL);
00786                             } else {
00787                                    nsptr = dom_get_nsdecl(elemp, (xmlChar *)localname);
00788                             }
00789                      } else {
00790                             nsptr = xmlSearchNsByHref(elemp->doc, elemp, (xmlChar *)uri);
00791                             if (nsptr && nsptr->prefix == NULL) {
00792                                    xmlNsPtr tmpnsptr;
00793 
00794                                    tmpnsptr = nsptr->next;
00795                                    while (tmpnsptr) {
00796                                           if ((tmpnsptr->prefix != NULL) && (tmpnsptr->href != NULL) && 
00797                                                  (xmlStrEqual(tmpnsptr->href, (xmlChar *) uri))) {
00798                                                  nsptr = tmpnsptr;
00799                                                  break;
00800                                           }
00801                                           tmpnsptr = tmpnsptr->next;
00802                                    }
00803                                    if (tmpnsptr == NULL) {
00804                                           nsptr = _dom_new_reconNs(elemp->doc, elemp, nsptr);
00805                                    }
00806                             }
00807                      }
00808 
00809                      if (nsptr == NULL) {
00810                             if (prefix == NULL) {
00811                                    if (is_xmlns == 1) {
00812                                           xmlNewNs(elemp, (xmlChar *)value, NULL);
00813                                           xmlReconciliateNs(elemp->doc, elemp);
00814                                    } else {
00815                                           errorcode = NAMESPACE_ERR;
00816                                    }
00817                             } else {
00818                                    if (is_xmlns == 1) {
00819                                           xmlNewNs(elemp, (xmlChar *)value, (xmlChar *)localname);
00820                                    } else {
00821                                           nsptr = dom_get_ns(elemp, uri, &errorcode, prefix);
00822                                    }
00823                                    xmlReconciliateNs(elemp->doc, elemp);
00824                             }
00825                      } else {
00826                             if (is_xmlns == 1) {
00827                                    if (nsptr->href) {
00828                                           xmlFree((xmlChar *) nsptr->href);
00829                                    }
00830                                    nsptr->href = xmlStrdup((xmlChar *)value);
00831                             }
00832                      }
00833 
00834                      if (errorcode == 0 && is_xmlns == 0) {
00835                             attr = xmlSetNsProp(elemp, nsptr, (xmlChar *)localname, (xmlChar *)value);
00836                      }
00837               } else {
00838                      name_valid = xmlValidateName((xmlChar *) localname, 0);
00839                      if (name_valid != 0) {
00840                             errorcode = INVALID_CHARACTER_ERR;
00841                             stricterror = 1;
00842                      } else {
00843                             attr = xmlHasProp(elemp, (xmlChar *)localname);
00844                             if (attr != NULL && attr->type != XML_ATTRIBUTE_DECL) {
00845                                    node_list_unlink(attr->children TSRMLS_CC);
00846                             }
00847                             attr = xmlSetProp(elemp, (xmlChar *)localname, (xmlChar *)value);
00848                      }
00849               }
00850        }
00851 
00852        xmlFree(localname);
00853        if (prefix != NULL) {
00854               xmlFree(prefix);
00855        }
00856 
00857        if (errorcode != 0) {
00858               php_dom_throw_error(errorcode, stricterror TSRMLS_CC);
00859        }
00860 
00861        RETURN_NULL();
00862 }
00863 /* }}} end dom_element_set_attribute_ns */
00864 
00865 /* {{{ proto void dom_element_remove_attribute_ns(string namespaceURI, string localName);
00866 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElRemAtNS
00867 Since: DOM Level 2
00868 */
00869 PHP_FUNCTION(dom_element_remove_attribute_ns)
00870 {
00871        zval *id;
00872        xmlNode *nodep;
00873        xmlAttr *attrp;
00874        xmlNsPtr nsptr;
00875        dom_object *intern;
00876        int name_len, uri_len;
00877        char *name, *uri;
00878 
00879        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
00880               return;
00881        }
00882 
00883        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00884 
00885        if (dom_node_is_read_only(nodep) == SUCCESS) {
00886               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00887               RETURN_NULL();
00888        }
00889 
00890        attrp = xmlHasNsProp(nodep, (xmlChar *)name, (xmlChar *)uri);
00891 
00892        nsptr = dom_get_nsdecl(nodep, (xmlChar *)name);
00893        if (nsptr != NULL) {
00894               if (xmlStrEqual((xmlChar *)uri, nsptr->href)) {
00895                      if (nsptr->href != NULL) {
00896                             xmlFree((char *) nsptr->href);
00897                             nsptr->href = NULL;
00898                      }
00899                      if (nsptr->prefix != NULL) {
00900                             xmlFree((char *) nsptr->prefix);
00901                             nsptr->prefix = NULL;
00902                      }
00903               } else {
00904                      RETURN_NULL();
00905               }
00906        }
00907 
00908        if (attrp && attrp->type != XML_ATTRIBUTE_DECL) {
00909               if (php_dom_object_get_data((xmlNodePtr) attrp) == NULL) {
00910                      node_list_unlink(attrp->children TSRMLS_CC);
00911                      xmlUnlinkNode((xmlNodePtr) attrp);
00912                      xmlFreeProp(attrp);
00913               } else {
00914                      xmlUnlinkNode((xmlNodePtr) attrp);
00915               }
00916        }
00917 
00918        RETURN_NULL();
00919 }
00920 /* }}} end dom_element_remove_attribute_ns */
00921 
00922 /* {{{ proto DOMAttr dom_element_get_attribute_node_ns(string namespaceURI, string localName);
00923 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElGetAtNodeNS
00924 Since: DOM Level 2
00925 */
00926 PHP_FUNCTION(dom_element_get_attribute_node_ns)
00927 {
00928        zval *id, *rv = NULL;
00929        xmlNodePtr elemp;
00930        xmlAttrPtr attrp;
00931        dom_object *intern;
00932        int uri_len, name_len, ret;
00933        char *uri, *name;
00934 
00935        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
00936               return;
00937        }
00938 
00939        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
00940 
00941        attrp = xmlHasNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
00942 
00943        if (attrp == NULL) {
00944               RETURN_NULL();
00945        }
00946 
00947        DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret, intern);
00948 
00949 }
00950 /* }}} end dom_element_get_attribute_node_ns */
00951 
00952 /* {{{ proto DOMAttr dom_element_set_attribute_node_ns(DOMAttr newAttr);
00953 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetAtNodeNS
00954 Since: DOM Level 2
00955 */
00956 PHP_FUNCTION(dom_element_set_attribute_node_ns)
00957 {
00958        zval *id, *node, *rv = NULL;
00959        xmlNode *nodep;
00960        xmlNs *nsp;
00961        xmlAttr *attrp, *existattrp = NULL;
00962        dom_object *intern, *attrobj, *oldobj;
00963        int ret;
00964 
00965        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_element_class_entry, &node, dom_attr_class_entry) == FAILURE) {
00966               return;
00967        }
00968 
00969        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
00970 
00971        if (dom_node_is_read_only(nodep) == SUCCESS) {
00972               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00973               RETURN_FALSE;
00974        }
00975 
00976        DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
00977 
00978        if (attrp->type != XML_ATTRIBUTE_NODE) {
00979               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is required");
00980               RETURN_FALSE;
00981        }
00982 
00983        if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
00984               php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00985               RETURN_FALSE;
00986        }
00987 
00988     nsp = attrp->ns;
00989     if (nsp != NULL) {
00990         existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name);
00991     } else {
00992         existattrp = xmlHasProp(nodep, attrp->name);
00993     }
00994 
00995        if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
00996               if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL && 
00997                      ((php_libxml_node_ptr *)oldobj->ptr)->node == (xmlNodePtr) attrp)
00998               {
00999                      RETURN_NULL();
01000               }
01001               xmlUnlinkNode((xmlNodePtr) existattrp);
01002        }
01003 
01004        if (attrp->parent != NULL) {
01005               xmlUnlinkNode((xmlNodePtr) attrp);
01006        }
01007 
01008        if (attrp->doc == NULL && nodep->doc != NULL) {
01009               attrobj->document = intern->document;
01010               php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL TSRMLS_CC);
01011        }
01012 
01013        xmlAddChild(nodep, (xmlNodePtr) attrp);
01014 
01015        /* Returns old property if removed otherwise NULL */
01016        if (existattrp != NULL) {
01017               DOM_RET_OBJ(rv, (xmlNodePtr) existattrp, &ret, intern);
01018        } else {
01019               RETVAL_NULL();
01020        }
01021 
01022 }
01023 /* }}} end dom_element_set_attribute_node_ns */
01024 
01025 /* {{{ proto DOMNodeList dom_element_get_elements_by_tag_name_ns(string namespaceURI, string localName);
01026 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C90942
01027 Since: DOM Level 2
01028 */
01029 PHP_FUNCTION(dom_element_get_elements_by_tag_name_ns)
01030 {
01031        zval *id;
01032        xmlNodePtr elemp;
01033        int uri_len, name_len;
01034        dom_object *intern, *namednode;
01035        char *uri, *name;
01036        xmlChar *local, *nsuri;
01037 
01038        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
01039               return;
01040        }
01041 
01042        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
01043 
01044        php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
01045        namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
01046        local = xmlCharStrndup(name, name_len);
01047        nsuri = xmlCharStrndup(uri, uri_len);
01048        dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri TSRMLS_CC);
01049 
01050 }
01051 /* }}} end dom_element_get_elements_by_tag_name_ns */
01052 
01053 /* {{{ proto boolean dom_element_has_attribute(string name);
01054 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElHasAttr
01055 Since: DOM Level 2
01056 */
01057 PHP_FUNCTION(dom_element_has_attribute)
01058 {
01059        zval *id;
01060        xmlNode *nodep;
01061        dom_object *intern;
01062        char *name;
01063        int name_len;
01064        xmlNodePtr attr;
01065 
01066        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
01067               return;
01068        }
01069 
01070        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
01071 
01072        attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
01073        if (attr == NULL) {
01074               RETURN_FALSE;
01075        } else {
01076               RETURN_TRUE;
01077        }
01078 }
01079 /* }}} end dom_element_has_attribute */
01080 
01081 /* {{{ proto boolean dom_element_has_attribute_ns(string namespaceURI, string localName);
01082 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElHasAttrNS
01083 Since: DOM Level 2
01084 */
01085 PHP_FUNCTION(dom_element_has_attribute_ns)
01086 {
01087        zval *id;
01088        xmlNodePtr elemp;
01089        xmlNs *nsp;
01090        dom_object *intern;
01091        int uri_len, name_len;
01092        char *uri, *name;
01093        xmlChar *value;
01094 
01095        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
01096               return;
01097        }
01098 
01099        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
01100 
01101        value = xmlGetNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
01102 
01103        if (value != NULL) {
01104               xmlFree(value);
01105               RETURN_TRUE;
01106        } else {
01107               if (xmlStrEqual((xmlChar *)uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
01108                      nsp = dom_get_nsdecl(elemp, (xmlChar *)name);
01109                      if (nsp != NULL) {
01110                             RETURN_TRUE;
01111                      }
01112               }
01113        }
01114 
01115        RETURN_FALSE;
01116 }
01117 /* }}} end dom_element_has_attribute_ns */
01118 
01119 static void php_set_attribute_id(xmlAttrPtr attrp, zend_bool is_id) /* {{{ */
01120 {
01121        if (is_id == 1 && attrp->atype != XML_ATTRIBUTE_ID) {
01122               xmlChar *id_val;
01123 
01124               id_val = xmlNodeListGetString(attrp->doc, attrp->children, 1);
01125               if (id_val != NULL) {
01126                      xmlAddID(NULL, attrp->doc, id_val, attrp);
01127                      xmlFree(id_val);
01128               }
01129        } else {
01130               if (attrp->atype == XML_ATTRIBUTE_ID) {
01131                      xmlRemoveID(attrp->doc, attrp);
01132                      attrp->atype = 0;
01133               }
01134        }
01135 }
01136 /* }}} */
01137 
01138 /* {{{ proto void dom_element_set_id_attribute(string name, boolean isId);
01139 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttr
01140 Since: DOM Level 3
01141 */
01142 PHP_FUNCTION(dom_element_set_id_attribute)
01143 {
01144        zval *id;
01145        xmlNode *nodep;
01146        xmlAttrPtr attrp;
01147        dom_object *intern;
01148        char *name;
01149        int name_len;
01150        zend_bool is_id;
01151 
01152        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osb", &id, dom_element_class_entry, &name, &name_len, &is_id) == FAILURE) {
01153               return;
01154        }
01155 
01156        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
01157 
01158        if (dom_node_is_read_only(nodep) == SUCCESS) {
01159               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01160               RETURN_NULL();
01161        }
01162 
01163        attrp = xmlHasNsProp(nodep, (xmlChar *)name, NULL);
01164        if (attrp == NULL || attrp->type == XML_ATTRIBUTE_DECL) {
01165               php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01166        } else {
01167               php_set_attribute_id(attrp, is_id);
01168        }
01169 
01170        RETURN_NULL();
01171 }
01172 /* }}} end dom_element_set_id_attribute */
01173 
01174 /* {{{ proto void dom_element_set_id_attribute_ns(string namespaceURI, string localName, boolean isId);
01175 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNS
01176 Since: DOM Level 3
01177 */
01178 PHP_FUNCTION(dom_element_set_id_attribute_ns)
01179 {
01180        zval *id;
01181        xmlNodePtr elemp;
01182        xmlAttrPtr attrp;
01183        dom_object *intern;
01184        int uri_len, name_len;
01185        char *uri, *name;
01186        zend_bool is_id;
01187 
01188        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) {
01189               return;
01190        }
01191 
01192        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
01193 
01194        if (dom_node_is_read_only(elemp) == SUCCESS) {
01195               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01196               RETURN_NULL();
01197        }
01198 
01199        attrp = xmlHasNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
01200        if (attrp == NULL || attrp->type == XML_ATTRIBUTE_DECL) {
01201               php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01202        } else {
01203               php_set_attribute_id(attrp, is_id);
01204        }
01205 
01206        RETURN_NULL();
01207 }
01208 /* }}} end dom_element_set_id_attribute_ns */
01209 
01210 /* {{{ proto void dom_element_set_id_attribute_node(attr idAttr, boolean isId);
01211 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNode
01212 Since: DOM Level 3
01213 */
01214 PHP_FUNCTION(dom_element_set_id_attribute_node)
01215 {
01216        zval *id, *node;
01217        xmlNode *nodep;
01218        xmlAttrPtr attrp;
01219        dom_object *intern, *attrobj;
01220        zend_bool is_id;
01221 
01222        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) {
01223               return;
01224        }
01225 
01226        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
01227 
01228        if (dom_node_is_read_only(nodep) == SUCCESS) {
01229               php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01230               RETURN_NULL();
01231        }
01232 
01233        DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
01234 
01235        if (attrp->parent != nodep) {
01236               php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01237        } else {
01238               php_set_attribute_id(attrp, is_id);
01239        }
01240 
01241        RETURN_NULL();
01242 }
01243 /* }}} end dom_element_set_id_attribute_node */
01244 
01245 #endif
01246 
01247 /*
01248  * Local variables:
01249  * tab-width: 4
01250  * c-basic-offset: 4
01251  * End:
01252  * vim600: noet sw=4 ts=4 fdm=marker
01253  * vim<600: noet sw=4 ts=4
01254  */