2003-06-06 01:06:52 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| PHP Version 5 |
|
2003-06-06 01:06:52 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| Copyright (c) 1997-2006 The PHP Group |
|
2003-06-06 01:06:52 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2003-06-06 01:06:52 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2003-06-06 01:06:52 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Christian Stocker <chregu@php.net> |
|
|
|
|
| Rob Richards <rrichards@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
2003-08-22 23:04:29 +08:00
|
|
|
#if HAVE_LIBXML && HAVE_DOM
|
2003-06-06 01:06:52 +08:00
|
|
|
#include "php_dom.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-05-31 20:50:28 +08:00
|
|
|
* class DOMElement extends DOMNode
|
2003-06-06 01:06:52 +08:00
|
|
|
*
|
|
|
|
* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-745549614
|
|
|
|
* Since:
|
|
|
|
*/
|
|
|
|
|
|
|
|
zend_function_entry php_dom_element_class_functions[] = {
|
|
|
|
PHP_FALIAS(getAttribute, dom_element_get_attribute, NULL)
|
|
|
|
PHP_FALIAS(setAttribute, dom_element_set_attribute, NULL)
|
|
|
|
PHP_FALIAS(removeAttribute, dom_element_remove_attribute, NULL)
|
|
|
|
PHP_FALIAS(getAttributeNode, dom_element_get_attribute_node, NULL)
|
|
|
|
PHP_FALIAS(setAttributeNode, dom_element_set_attribute_node, NULL)
|
|
|
|
PHP_FALIAS(removeAttributeNode, dom_element_remove_attribute_node, NULL)
|
|
|
|
PHP_FALIAS(getElementsByTagName, dom_element_get_elements_by_tag_name, NULL)
|
|
|
|
PHP_FALIAS(getAttributeNS, dom_element_get_attribute_ns, NULL)
|
|
|
|
PHP_FALIAS(setAttributeNS, dom_element_set_attribute_ns, NULL)
|
|
|
|
PHP_FALIAS(removeAttributeNS, dom_element_remove_attribute_ns, NULL)
|
|
|
|
PHP_FALIAS(getAttributeNodeNS, dom_element_get_attribute_node_ns, NULL)
|
|
|
|
PHP_FALIAS(setAttributeNodeNS, dom_element_set_attribute_node_ns, NULL)
|
|
|
|
PHP_FALIAS(getElementsByTagNameNS, dom_element_get_elements_by_tag_name_ns, NULL)
|
|
|
|
PHP_FALIAS(hasAttribute, dom_element_has_attribute, NULL)
|
|
|
|
PHP_FALIAS(hasAttributeNS, dom_element_has_attribute_ns, NULL)
|
|
|
|
PHP_FALIAS(setIdAttribute, dom_element_set_id_attribute, NULL)
|
|
|
|
PHP_FALIAS(setIdAttributeNS, dom_element_set_id_attribute_ns, NULL)
|
|
|
|
PHP_FALIAS(setIdAttributeNode, dom_element_set_id_attribute_node, NULL)
|
2004-04-01 01:18:59 +08:00
|
|
|
PHP_ME(domelement, __construct, NULL, ZEND_ACC_PUBLIC)
|
2003-06-06 01:06:52 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void DOMElement::__construct(string name, [string value], [string uri]); */
|
2004-04-01 01:18:59 +08:00
|
|
|
PHP_METHOD(domelement, __construct)
|
2003-06-06 01:06:52 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
zval *id;
|
|
|
|
xmlNodePtr nodep = NULL, oldnode = NULL;
|
|
|
|
dom_object *intern;
|
2004-02-22 21:05:49 +08:00
|
|
|
char *name, *value = NULL, *uri = NULL;
|
|
|
|
char *localname = NULL, *prefix = NULL;
|
|
|
|
int errorcode = 0, uri_len = 0;
|
2004-05-16 18:30:16 +08:00
|
|
|
int name_len, value_len = 0, name_valid;
|
2004-02-22 21:05:49 +08:00
|
|
|
xmlNsPtr nsptr = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-05-16 18:30:16 +08:00
|
|
|
php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
|
2004-02-22 21:05:49 +08:00
|
|
|
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) {
|
2004-05-16 18:30:16 +08:00
|
|
|
php_std_error_handling();
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-16 18:30:16 +08:00
|
|
|
php_std_error_handling();
|
|
|
|
name_valid = xmlValidateName((xmlChar *) name, 0);
|
|
|
|
if (name_valid != 0) {
|
|
|
|
php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-02-22 21:05:49 +08:00
|
|
|
/* Namespace logic is seperate and only when uri passed in to insure no BC breakage */
|
|
|
|
if (uri_len > 0) {
|
|
|
|
errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
|
|
|
|
if (errorcode == 0) {
|
2006-09-28 18:11:36 +08:00
|
|
|
nodep = xmlNewNode (NULL, (xmlChar *)localname);
|
2004-02-22 21:05:49 +08:00
|
|
|
if (nodep != NULL && uri != NULL) {
|
|
|
|
nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
|
|
|
|
xmlSetNs(nodep, nsptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(localname);
|
|
|
|
if (prefix != NULL) {
|
|
|
|
xmlFree(prefix);
|
|
|
|
}
|
|
|
|
if (errorcode != 0) {
|
|
|
|
if (nodep != NULL) {
|
2006-09-15 15:44:20 +08:00
|
|
|
xmlFreeNode(nodep);
|
2004-02-22 21:05:49 +08:00
|
|
|
}
|
2004-05-16 18:30:16 +08:00
|
|
|
php_dom_throw_error(errorcode, 1 TSRMLS_CC);
|
2004-02-22 21:05:49 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2004-05-27 19:15:45 +08:00
|
|
|
/* If you don't pass a namespace uri, then you can't set a prefix */
|
2006-09-28 18:11:36 +08:00
|
|
|
localname = xmlSplitQName2((xmlChar *)name, (xmlChar **) &prefix);
|
2004-05-27 19:15:45 +08:00
|
|
|
if (prefix != NULL) {
|
|
|
|
xmlFree(localname);
|
|
|
|
xmlFree(prefix);
|
|
|
|
php_dom_throw_error(NAMESPACE_ERR, 1 TSRMLS_CC);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2004-02-22 21:05:49 +08:00
|
|
|
nodep = xmlNewNode(NULL, (xmlChar *) name);
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-05-16 18:30:16 +08:00
|
|
|
if (!nodep) {
|
|
|
|
php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
2004-05-16 18:30:16 +08:00
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (value_len > 0) {
|
2006-09-28 18:11:36 +08:00
|
|
|
xmlNodeSetContentLen(nodep, (xmlChar *) value, value_len);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
|
|
|
|
if (intern != NULL) {
|
2006-05-03 16:43:04 +08:00
|
|
|
oldnode = dom_object_get_node(intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
if (oldnode != NULL) {
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(oldnode TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
}
|
2004-05-31 20:50:28 +08:00
|
|
|
/* }}} end DOMElement::__construct */
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-11-19 03:54:30 +08:00
|
|
|
/* {{{ tagName string
|
2003-06-06 01:06:52 +08:00
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-104682815
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_element_tag_name_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNodePtr nodep;
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlNsPtr ns;
|
|
|
|
xmlChar *qname;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2004-02-16 21:06:33 +08:00
|
|
|
|
|
|
|
if (nodep == NULL) {
|
|
|
|
php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
2003-10-05 19:52:22 +08:00
|
|
|
ns = nodep->ns;
|
|
|
|
if (ns != NULL && ns->prefix) {
|
|
|
|
qname = xmlStrdup(ns->prefix);
|
|
|
|
qname = xmlStrcat(qname, ":");
|
2003-10-06 05:49:47 +08:00
|
|
|
qname = xmlStrcat(qname, nodep->name);
|
2006-09-28 18:11:36 +08:00
|
|
|
ZVAL_STRING(*retval, (char *)qname, 1);
|
2003-10-06 05:49:47 +08:00
|
|
|
xmlFree(qname);
|
|
|
|
} else {
|
2003-10-07 05:28:01 +08:00
|
|
|
ZVAL_STRING(*retval, (char *) nodep->name, 1);
|
2003-10-05 19:52:22 +08:00
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-19 03:54:30 +08:00
|
|
|
/* {{{ schemaTypeInfo typeinfo
|
2003-06-06 01:06:52 +08:00
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Element-schemaTypeInfo
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
int dom_element_schema_type_info_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2006-09-27 18:31:24 +08:00
|
|
|
static xmlNodePtr dom_get_dom1_attribute(xmlNodePtr elem, xmlChar *name) {
|
2006-08-29 07:36:23 +08:00
|
|
|
int len;
|
|
|
|
const xmlChar *nqname;
|
|
|
|
|
|
|
|
nqname = xmlSplitQName3(name, &len);
|
|
|
|
if (nqname != NULL) {
|
|
|
|
xmlNsPtr ns;
|
|
|
|
xmlChar *prefix = xmlStrndup(name, len);
|
2006-09-27 18:31:24 +08:00
|
|
|
if (prefix && xmlStrEqual(prefix, "xmlns")) {
|
|
|
|
ns = elem->nsDef;
|
|
|
|
while (ns) {
|
|
|
|
if (xmlStrEqual(ns->prefix, nqname)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ns = ns->next;
|
|
|
|
}
|
|
|
|
xmlFree(prefix);
|
|
|
|
return (xmlNodePtr)ns;
|
|
|
|
}
|
2006-08-29 07:36:23 +08:00
|
|
|
ns = xmlSearchNs(elem->doc, elem, prefix);
|
|
|
|
if (prefix != NULL) {
|
|
|
|
xmlFree(prefix);
|
|
|
|
}
|
|
|
|
if (ns != NULL) {
|
2006-09-27 18:31:24 +08:00
|
|
|
return (xmlNodePtr)xmlHasNsProp(elem, nqname, ns->href);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (xmlStrEqual(name, "xmlns")) {
|
|
|
|
xmlNsPtr nsPtr = elem->nsDef;
|
|
|
|
while (nsPtr) {
|
|
|
|
if (nsPtr->prefix == NULL) {
|
|
|
|
return (xmlNodePtr)nsPtr;
|
|
|
|
}
|
|
|
|
nsPtr = nsPtr->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-08-29 07:36:23 +08:00
|
|
|
}
|
|
|
|
}
|
2006-09-27 18:31:24 +08:00
|
|
|
return (xmlNodePtr)xmlHasNsProp(elem, name, NULL);
|
2006-08-29 07:36:23 +08:00
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto string dom_element_get_attribute(string name);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-666EE0F9
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_get_attribute)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNode *nodep;
|
2006-08-29 07:36:23 +08:00
|
|
|
char *name, *value = NULL;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlNodePtr attr;
|
2003-06-06 01:06:52 +08:00
|
|
|
int name_len;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2006-08-29 07:36:23 +08:00
|
|
|
attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
|
|
|
|
if (attr) {
|
2006-09-27 18:31:24 +08:00
|
|
|
switch (attr->type) {
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
2006-08-29 07:36:23 +08:00
|
|
|
value = xmlNodeListGetString(attr->doc, attr->children, 1);
|
2006-09-27 18:31:24 +08:00
|
|
|
break;
|
|
|
|
case XML_NAMESPACE_DECL:
|
|
|
|
value = xmlStrdup(((xmlNsPtr)attr)->href);
|
|
|
|
break;
|
|
|
|
default:
|
2006-08-29 07:36:23 +08:00
|
|
|
value = xmlStrdup(((xmlAttributePtr)attr)->defaultValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (value == NULL) {
|
|
|
|
RETURN_EMPTY_STRING();
|
|
|
|
} else {
|
|
|
|
RETVAL_STRING(value, 1);
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_get_attribute */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_set_attribute(string name, string value);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-F68F082
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_set_attribute)
|
|
|
|
{
|
|
|
|
zval *id, *rv = NULL;
|
|
|
|
xmlNode *nodep;
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlNodePtr attr = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
int ret, name_len, value_len;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
char *name, *value;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_element_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (name_len == 0) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-08-29 07:36:23 +08:00
|
|
|
attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
|
2006-09-27 18:31:24 +08:00
|
|
|
if (attr != NULL) {
|
|
|
|
switch (attr->type) {
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
2003-06-06 01:06:52 +08:00
|
|
|
node_list_unlink(attr->children TSRMLS_CC);
|
2006-09-27 18:31:24 +08:00
|
|
|
break;
|
|
|
|
case XML_NAMESPACE_DECL:
|
|
|
|
RETURN_FALSE;
|
2006-09-28 18:11:36 +08:00
|
|
|
default:
|
|
|
|
break;
|
2006-09-27 18:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xmlStrEqual((xmlChar *)name, "xmlns")) {
|
|
|
|
if (xmlNewNs(nodep, (xmlChar *)value, NULL)) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
2006-09-28 18:11:36 +08:00
|
|
|
attr = (xmlNodePtr)xmlSetProp(nodep, (xmlChar *) name, value);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
if (!attr) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such attribute '%s'", name);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-09-27 18:31:24 +08:00
|
|
|
DOM_RET_OBJ(rv, attr, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_attribute */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_remove_attribute(string name);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D6AC0F9
|
2003-08-24 18:23:43 +08:00
|
|
|
Since:
|
2003-06-06 01:06:52 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_remove_attribute)
|
|
|
|
{
|
|
|
|
zval *id;
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlNodePtr nodep, attrp;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
int name_len;
|
|
|
|
char *name;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-08-29 07:36:23 +08:00
|
|
|
attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
|
2003-06-06 01:06:52 +08:00
|
|
|
if (attrp == NULL) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-09-27 18:31:24 +08:00
|
|
|
switch (attrp->type) {
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
|
|
|
if (php_dom_object_get_data(attrp) == NULL) {
|
2005-05-20 23:01:38 +08:00
|
|
|
node_list_unlink(attrp->children TSRMLS_CC);
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlUnlinkNode(attrp);
|
|
|
|
xmlFreeProp((xmlAttrPtr)attrp);
|
2005-05-20 23:01:38 +08:00
|
|
|
} else {
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlUnlinkNode(attrp);
|
2005-05-20 23:01:38 +08:00
|
|
|
}
|
2006-09-27 18:31:24 +08:00
|
|
|
break;
|
|
|
|
case XML_NAMESPACE_DECL:
|
|
|
|
RETURN_FALSE;
|
2006-09-28 18:11:36 +08:00
|
|
|
default:
|
|
|
|
break;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_remove_attribute */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMAttr dom_element_get_attribute_node(string name);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-217A91B8
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_get_attribute_node)
|
|
|
|
{
|
|
|
|
zval *id, *rv = NULL;
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlNodePtr nodep, attrp;
|
2003-06-06 01:06:52 +08:00
|
|
|
int name_len, ret;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
char *name;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2006-08-29 07:36:23 +08:00
|
|
|
attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
|
2003-06-06 01:06:52 +08:00
|
|
|
if (attrp == NULL) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-06-10 04:20:55 +08:00
|
|
|
|
2006-09-27 18:31:24 +08:00
|
|
|
if (attrp->type == XML_NAMESPACE_DECL) {
|
|
|
|
xmlNsPtr curns;
|
|
|
|
xmlNodePtr nsparent;
|
|
|
|
|
|
|
|
nsparent = attrp->_private;
|
|
|
|
curns = xmlNewNs(NULL, attrp->name, NULL);
|
|
|
|
if (attrp->children) {
|
|
|
|
curns->prefix = xmlStrdup((xmlChar *) attrp->children);
|
|
|
|
}
|
|
|
|
if (attrp->children) {
|
|
|
|
attrp = xmlNewDocNode(nodep->doc, NULL, (xmlChar *) attrp->children, attrp->name);
|
|
|
|
} else {
|
|
|
|
attrp = xmlNewDocNode(nodep->doc, NULL, "xmlns", attrp->name);
|
|
|
|
}
|
|
|
|
attrp->type = XML_NAMESPACE_DECL;
|
|
|
|
attrp->parent = nsparent;
|
|
|
|
attrp->ns = curns;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_get_attribute_node */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMAttr dom_element_set_attribute_node(DOMAttr newAttr);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-887236154
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_set_attribute_node)
|
|
|
|
{
|
2003-06-10 04:20:55 +08:00
|
|
|
zval *id, *node, *rv = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlNode *nodep;
|
|
|
|
xmlAttr *attrp, *existattrp = NULL;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *attrobj, *oldobj;
|
2003-06-06 01:06:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_element_class_entry, &node, dom_attr_class_entry) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (attrp->type != XML_ATTRIBUTE_NODE) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is required");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2005-10-28 07:51:22 +08:00
|
|
|
if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
|
|
|
|
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
existattrp = xmlHasProp(nodep, attrp->name);
|
2005-05-20 23:01:38 +08:00
|
|
|
if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
|
2003-11-29 05:55:59 +08:00
|
|
|
if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL &&
|
2003-10-26 23:57:02 +08:00
|
|
|
((php_libxml_node_ptr *)oldobj->ptr)->node == (xmlNodePtr) attrp)
|
2003-10-05 19:52:22 +08:00
|
|
|
{
|
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlUnlinkNode((xmlNodePtr) existattrp);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
if (attrp->doc == NULL && nodep->doc != NULL) {
|
|
|
|
attrobj->document = intern->document;
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlAddChild(nodep, (xmlNodePtr) attrp);
|
|
|
|
|
|
|
|
/* Returns old property if removed otherwise NULL */
|
|
|
|
if (existattrp != NULL) {
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, (xmlNodePtr) existattrp, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
} else {
|
|
|
|
RETVAL_NULL();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_attribute_node */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMAttr dom_element_remove_attribute_node(DOMAttr oldAttr);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D589198
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_remove_attribute_node)
|
|
|
|
{
|
2003-10-05 19:52:22 +08:00
|
|
|
zval *id, *node, *rv = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlNode *nodep;
|
|
|
|
xmlAttr *attrp;
|
2003-10-05 19:52:22 +08:00
|
|
|
dom_object *intern, *attrobj;
|
|
|
|
int ret;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_element_class_entry, &node, dom_attr_class_entry) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-10-05 19:52:22 +08:00
|
|
|
DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
|
|
|
|
|
|
|
|
if (attrp->type != XML_ATTRIBUTE_NODE || attrp->parent != nodep) {
|
|
|
|
php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlUnlinkNode((xmlNodePtr) attrp);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-10-05 19:52:22 +08:00
|
|
|
DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_remove_attribute_node */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMNodeList dom_element_get_elements_by_tag_name(string name);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1938918D
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_get_elements_by_tag_name)
|
|
|
|
{
|
|
|
|
zval *id;
|
2003-10-20 23:50:34 +08:00
|
|
|
xmlNodePtr elemp;
|
|
|
|
int name_len;
|
2003-11-30 04:40:18 +08:00
|
|
|
dom_object *intern, *namednode;
|
2003-10-20 23:50:34 +08:00
|
|
|
char *name;
|
2003-11-30 04:40:18 +08:00
|
|
|
xmlChar *local;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
|
|
|
|
|
2003-11-30 04:40:18 +08:00
|
|
|
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
|
|
|
|
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
|
|
|
|
local = xmlCharStrndup(name, name_len);
|
2004-08-30 23:07:20 +08:00
|
|
|
dom_namednode_iter(intern, 0, namednode, NULL, local, NULL TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_get_elements_by_tag_name */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto string dom_element_get_attribute_ns(string namespaceURI, string localName);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElGetAttrNS
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_get_attribute_ns)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNodePtr elemp;
|
|
|
|
xmlNsPtr nsptr;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
int uri_len = 0, name_len = 0;
|
|
|
|
char *uri, *name, *strattr;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
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) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2004-02-15 22:05:17 +08:00
|
|
|
|
|
|
|
DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
|
|
|
|
|
2006-09-28 18:11:36 +08:00
|
|
|
strattr = xmlGetNsProp(elemp, (xmlChar *) name, (xmlChar *) uri);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (strattr != NULL) {
|
|
|
|
RETVAL_STRING(strattr, 1);
|
|
|
|
xmlFree(strattr);
|
|
|
|
} else {
|
2006-09-28 18:11:36 +08:00
|
|
|
if (xmlStrEqual((xmlChar *) uri, DOM_XMLNS_NAMESPACE)) {
|
2003-06-06 01:06:52 +08:00
|
|
|
nsptr = dom_get_nsdecl(elemp, name);
|
|
|
|
if (nsptr != NULL) {
|
|
|
|
RETVAL_STRING((char *) nsptr->href, 1);
|
|
|
|
} else {
|
|
|
|
RETVAL_EMPTY_STRING();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RETVAL_EMPTY_STRING();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_get_attribute_ns */
|
|
|
|
|
2005-08-29 00:23:25 +08:00
|
|
|
static xmlNsPtr _dom_new_reconNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
|
|
|
|
xmlNsPtr def;
|
|
|
|
xmlChar prefix[50];
|
|
|
|
int counter = 1;
|
|
|
|
|
|
|
|
if ((tree == NULL) || (ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Code taken from libxml2 (2.6.20) xmlNewReconciliedNs
|
|
|
|
*
|
|
|
|
* Find a close prefix which is not already in use.
|
|
|
|
* Let's strip namespace prefixes longer than 20 chars !
|
|
|
|
*/
|
|
|
|
if (ns->prefix == NULL)
|
|
|
|
snprintf((char *) prefix, sizeof(prefix), "default");
|
|
|
|
else
|
|
|
|
snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix);
|
|
|
|
|
|
|
|
def = xmlSearchNs(doc, tree, prefix);
|
|
|
|
while (def != NULL) {
|
|
|
|
if (counter > 1000) return(NULL);
|
|
|
|
if (ns->prefix == NULL)
|
|
|
|
snprintf((char *) prefix, sizeof(prefix), "default%d", counter++);
|
|
|
|
else
|
|
|
|
snprintf((char *) prefix, sizeof(prefix), "%.20s%d",
|
|
|
|
(char *)ns->prefix, counter++);
|
|
|
|
def = xmlSearchNs(doc, tree, prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, now we are ready to create a new one.
|
|
|
|
*/
|
|
|
|
def = xmlNewNs(tree, ns->href, prefix);
|
|
|
|
return(def);
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_set_attribute_ns(string namespaceURI, string qualifiedName, string value);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetAttrNS
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_set_attribute_ns)
|
|
|
|
{
|
2003-10-20 23:50:34 +08:00
|
|
|
zval *id;
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlNodePtr elemp, nodep = NULL;
|
|
|
|
xmlNsPtr nsptr;
|
2003-10-06 04:45:27 +08:00
|
|
|
xmlAttr *attr;
|
2003-10-20 23:50:34 +08:00
|
|
|
int uri_len = 0, name_len = 0, value_len = 0;
|
2003-10-06 04:45:27 +08:00
|
|
|
char *uri, *name, *value;
|
2003-07-28 01:57:06 +08:00
|
|
|
char *localname = NULL, *prefix = NULL;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-10-20 23:50:34 +08:00
|
|
|
int errorcode = 0, stricterror, is_xmlns = 0;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
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) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-07-13 01:29:20 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (name_len == 0) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
stricterror = dom_get_strict_error(intern->document);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(elemp) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror TSRMLS_CC);
|
2003-10-20 23:50:34 +08:00
|
|
|
RETURN_NULL();
|
2003-07-13 01:29:20 +08:00
|
|
|
}
|
|
|
|
|
2003-07-28 01:57:06 +08:00
|
|
|
errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (errorcode == 0) {
|
2003-10-07 05:28:01 +08:00
|
|
|
if (uri_len > 0) {
|
2006-09-28 18:11:36 +08:00
|
|
|
nodep = (xmlNodePtr) xmlHasNsProp(elemp, (xmlChar *) localname, (xmlChar *) uri);
|
2005-05-20 23:01:38 +08:00
|
|
|
if (nodep != NULL && nodep->type != XML_ATTRIBUTE_DECL) {
|
2003-10-07 05:28:01 +08:00
|
|
|
node_list_unlink(nodep->children TSRMLS_CC);
|
|
|
|
}
|
2003-10-20 23:50:34 +08:00
|
|
|
|
2006-09-28 18:11:36 +08:00
|
|
|
if (xmlStrEqual((xmlChar *) prefix,"xmlns") && xmlStrEqual((xmlChar *) uri, DOM_XMLNS_NAMESPACE)) {
|
2003-10-20 23:50:34 +08:00
|
|
|
is_xmlns = 1;
|
|
|
|
nsptr = dom_get_nsdecl(elemp, localname);
|
|
|
|
} else {
|
|
|
|
nsptr = xmlSearchNsByHref(elemp->doc, elemp, uri);
|
2005-08-29 00:23:25 +08:00
|
|
|
if (nsptr && nsptr->prefix == NULL) {
|
|
|
|
xmlNsPtr tmpnsptr;
|
|
|
|
|
|
|
|
tmpnsptr = nsptr->next;
|
|
|
|
while (tmpnsptr) {
|
|
|
|
if ((tmpnsptr->prefix != NULL) && (tmpnsptr->href != NULL) &&
|
|
|
|
(xmlStrEqual(tmpnsptr->href, (xmlChar *) uri))) {
|
|
|
|
nsptr = tmpnsptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmpnsptr = tmpnsptr->next;
|
|
|
|
}
|
|
|
|
if (tmpnsptr == NULL) {
|
|
|
|
nsptr = _dom_new_reconNs(elemp->doc, elemp, nsptr);
|
|
|
|
}
|
2003-10-20 23:50:34 +08:00
|
|
|
}
|
2003-10-07 05:28:01 +08:00
|
|
|
}
|
2003-10-20 23:50:34 +08:00
|
|
|
|
2003-10-07 05:28:01 +08:00
|
|
|
if (nsptr == NULL) {
|
|
|
|
if (prefix == NULL) {
|
|
|
|
errorcode = NAMESPACE_ERR;
|
|
|
|
} else {
|
2003-10-20 23:50:34 +08:00
|
|
|
if (is_xmlns == 1) {
|
|
|
|
xmlNewNs(elemp, value, localname);
|
|
|
|
} else {
|
|
|
|
nsptr = dom_get_ns(elemp, uri, &errorcode, prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (is_xmlns == 1) {
|
|
|
|
if (nsptr->href) {
|
|
|
|
xmlFree((xmlChar *) nsptr->href);
|
|
|
|
}
|
|
|
|
nsptr->href = xmlStrdup(value);
|
2003-10-07 05:28:01 +08:00
|
|
|
}
|
2003-07-28 01:57:06 +08:00
|
|
|
}
|
2003-10-06 04:45:27 +08:00
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
if (errorcode == 0 && is_xmlns == 0) {
|
2003-10-07 05:28:01 +08:00
|
|
|
attr = xmlSetNsProp(elemp, nsptr, localname, value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
attr = xmlHasProp(elemp, localname);
|
2005-05-20 23:01:38 +08:00
|
|
|
if (attr != NULL && attr->type != XML_ATTRIBUTE_DECL) {
|
2003-10-07 05:28:01 +08:00
|
|
|
node_list_unlink(attr->children TSRMLS_CC);
|
|
|
|
}
|
|
|
|
attr = xmlSetProp(elemp, localname, value);
|
2003-10-06 04:45:27 +08:00
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-07-28 01:57:06 +08:00
|
|
|
|
|
|
|
xmlFree(localname);
|
|
|
|
if (prefix != NULL) {
|
|
|
|
xmlFree(prefix);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (errorcode != 0) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(errorcode, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_attribute_ns */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_remove_attribute_ns(string namespaceURI, string localName);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElRemAtNS
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_remove_attribute_ns)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNode *nodep;
|
|
|
|
xmlAttr *attrp;
|
2003-10-20 23:50:34 +08:00
|
|
|
xmlNsPtr nsptr;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
int name_len, uri_len;
|
|
|
|
char *name, *uri;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
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) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-10-20 23:50:34 +08:00
|
|
|
RETURN_NULL();
|
2003-07-13 01:29:20 +08:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:11:36 +08:00
|
|
|
attrp = xmlHasNsProp(nodep, (xmlChar *)name, (xmlChar *)uri);
|
2003-10-20 23:50:34 +08:00
|
|
|
|
2006-09-28 18:11:36 +08:00
|
|
|
nsptr = dom_get_nsdecl(nodep, (xmlChar *)name);
|
2003-10-20 23:50:34 +08:00
|
|
|
if (nsptr != NULL) {
|
2006-09-28 18:11:36 +08:00
|
|
|
if (xmlStrEqual((xmlChar *)uri, nsptr->href)) {
|
2003-10-20 23:50:34 +08:00
|
|
|
if (nsptr->href != NULL) {
|
|
|
|
xmlFree((char *) nsptr->href);
|
|
|
|
nsptr->href = NULL;
|
|
|
|
}
|
|
|
|
if (nsptr->prefix != NULL) {
|
|
|
|
xmlFree((char *) nsptr->prefix);
|
|
|
|
nsptr->prefix = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-10-20 23:50:34 +08:00
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2005-05-20 23:01:38 +08:00
|
|
|
if (attrp && attrp->type != XML_ATTRIBUTE_DECL) {
|
2003-11-29 05:55:59 +08:00
|
|
|
if (php_dom_object_get_data((xmlNodePtr) attrp) == NULL) {
|
2003-06-06 01:06:52 +08:00
|
|
|
node_list_unlink(attrp->children TSRMLS_CC);
|
|
|
|
xmlUnlinkNode((xmlNodePtr) attrp);
|
|
|
|
xmlFreeProp(attrp);
|
|
|
|
} else {
|
|
|
|
xmlUnlinkNode((xmlNodePtr) attrp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_remove_attribute_ns */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMAttr dom_element_get_attribute_node_ns(string namespaceURI, string localName);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElGetAtNodeNS
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_get_attribute_node_ns)
|
|
|
|
{
|
2003-10-20 23:50:34 +08:00
|
|
|
zval *id, *rv = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlNodePtr elemp;
|
2003-10-20 23:50:34 +08:00
|
|
|
xmlAttrPtr attrp;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-10-20 23:50:34 +08:00
|
|
|
int uri_len, name_len, ret;
|
|
|
|
char *uri, *name;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2005-07-07 18:36:08 +08:00
|
|
|
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) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
|
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
attrp = xmlHasNsProp(elemp, name, uri);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
if (attrp == NULL) {
|
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret, intern);
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_get_attribute_node_ns */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMAttr dom_element_set_attribute_node_ns(DOMAttr newAttr);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetAtNodeNS
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_set_attribute_node_ns)
|
|
|
|
{
|
2003-06-10 04:20:55 +08:00
|
|
|
zval *id, *node, *rv = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlNode *nodep;
|
|
|
|
xmlNs *nsp;
|
|
|
|
xmlAttr *attrp, *existattrp = NULL;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *attrobj, *oldobj;
|
2003-06-06 01:06:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_element_class_entry, &node, dom_attr_class_entry) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (attrp->type != XML_ATTRIBUTE_NODE) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is required");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2005-10-28 07:51:22 +08:00
|
|
|
if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
|
|
|
|
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
nsp = attrp->ns;
|
|
|
|
if (nsp != NULL) {
|
|
|
|
existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name);
|
|
|
|
} else {
|
|
|
|
existattrp = xmlHasProp(nodep, attrp->name);
|
|
|
|
}
|
|
|
|
|
2005-05-20 23:01:38 +08:00
|
|
|
if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
|
2003-11-29 05:55:59 +08:00
|
|
|
if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL &&
|
2003-10-26 23:57:02 +08:00
|
|
|
((php_libxml_node_ptr *)oldobj->ptr)->node == (xmlNodePtr) attrp)
|
2003-10-05 19:52:22 +08:00
|
|
|
{
|
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlUnlinkNode((xmlNodePtr) existattrp);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
if (attrp->doc == NULL && nodep->doc != NULL) {
|
|
|
|
attrobj->document = intern->document;
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlAddChild(nodep, (xmlNodePtr) attrp);
|
|
|
|
|
|
|
|
/* Returns old property if removed otherwise NULL */
|
|
|
|
if (existattrp != NULL) {
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, (xmlNodePtr) existattrp, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
} else {
|
|
|
|
RETVAL_NULL();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_attribute_node_ns */
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto DOMNodeList dom_element_get_elements_by_tag_name_ns(string namespaceURI, string localName);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C90942
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_get_elements_by_tag_name_ns)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNodePtr elemp;
|
|
|
|
int uri_len, name_len;
|
2003-11-30 04:40:18 +08:00
|
|
|
dom_object *intern, *namednode;
|
2003-06-06 01:06:52 +08:00
|
|
|
char *uri, *name;
|
2003-11-30 04:40:18 +08:00
|
|
|
xmlChar *local, *nsuri;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
|
|
|
|
|
2003-11-30 04:40:18 +08:00
|
|
|
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
|
|
|
|
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
|
|
|
|
local = xmlCharStrndup(name, name_len);
|
|
|
|
nsuri = xmlCharStrndup(uri, uri_len);
|
2004-08-30 23:07:20 +08:00
|
|
|
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_get_elements_by_tag_name_ns */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_element_has_attribute(string name);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElHasAttr
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_has_attribute)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNode *nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2006-08-29 07:36:23 +08:00
|
|
|
char *name;
|
2003-06-06 01:06:52 +08:00
|
|
|
int name_len;
|
2006-09-27 18:31:24 +08:00
|
|
|
xmlNodePtr attr;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
2006-08-29 07:36:23 +08:00
|
|
|
attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
|
|
|
|
if (attr == NULL) {
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_has_attribute */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_element_has_attribute_ns(string namespaceURI, string localName);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElHasAttrNS
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_has_attribute_ns)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNodePtr elemp;
|
|
|
|
xmlNs *nsp;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
int uri_len, name_len;
|
2006-09-28 18:11:36 +08:00
|
|
|
char *uri, *name;
|
|
|
|
xmlChar *value;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
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) {
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-15 22:05:17 +08:00
|
|
|
DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
|
|
|
|
|
2006-09-28 18:11:36 +08:00
|
|
|
value = xmlGetNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
xmlFree(value);
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
if (xmlStrEqual(uri, DOM_XMLNS_NAMESPACE)) {
|
|
|
|
nsp = dom_get_nsdecl(elemp, name);
|
|
|
|
if (nsp != NULL) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} end dom_element_has_attribute_ns */
|
|
|
|
|
|
|
|
|
2006-06-03 00:17:25 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_set_id_attribute(string name, boolean isId);
|
2003-06-06 01:06:52 +08:00
|
|
|
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)
|
|
|
|
{
|
2006-06-03 00:17:25 +08:00
|
|
|
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();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_id_attribute */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_set_id_attribute_ns(string namespaceURI, string localName, boolean isId);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNS
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_set_id_attribute_ns)
|
|
|
|
{
|
2006-06-14 04:19:37 +08:00
|
|
|
zval *id;
|
2006-06-03 00:17:25 +08:00
|
|
|
xmlNodePtr elemp;
|
|
|
|
xmlAttrPtr attrp;
|
|
|
|
dom_object *intern;
|
2006-06-14 04:19:37 +08:00
|
|
|
int uri_len, name_len;
|
2006-06-03 00:17:25 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2006-09-28 18:11:36 +08:00
|
|
|
attrp = xmlHasNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
|
2006-06-03 00:17:25 +08:00
|
|
|
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();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_id_attribute_ns */
|
|
|
|
|
|
|
|
|
2004-05-31 20:50:28 +08:00
|
|
|
/* {{{ proto void dom_element_set_id_attribute_node(attr idAttr, boolean isId);
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNode
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_element_set_id_attribute_node)
|
|
|
|
{
|
2006-06-03 00:17:25 +08:00
|
|
|
zval *id, *node;
|
|
|
|
xmlNode *nodep;
|
|
|
|
xmlAttrPtr attrp;
|
|
|
|
dom_object *intern, *attrobj;
|
|
|
|
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();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_element_set_id_attribute_node */
|
2003-08-22 23:04:29 +08:00
|
|
|
|
|
|
|
#endif
|