2003-06-06 01:06:52 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 4 |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1997-2003 The PHP Group |
|
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
| This source file is subject to version 3.0 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: |
|
|
|
|
| http://www.php.net/license/3_0.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"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* class domnode
|
|
|
|
*
|
|
|
|
* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1950641247
|
|
|
|
* Since:
|
|
|
|
*/
|
|
|
|
|
|
|
|
zend_function_entry php_dom_node_class_functions[] = {
|
|
|
|
PHP_FALIAS(insertBefore, dom_node_insert_before, NULL)
|
|
|
|
PHP_FALIAS(replaceChild, dom_node_replace_child, NULL)
|
|
|
|
PHP_FALIAS(removeChild, dom_node_remove_child, NULL)
|
|
|
|
PHP_FALIAS(appendChild, dom_node_append_child, NULL)
|
|
|
|
PHP_FALIAS(hasChildNodes, dom_node_has_child_nodes, NULL)
|
|
|
|
PHP_FALIAS(cloneNode, dom_node_clone_node, NULL)
|
|
|
|
PHP_FALIAS(normalize, dom_node_normalize, NULL)
|
|
|
|
PHP_FALIAS(isSupported, dom_node_is_supported, NULL)
|
|
|
|
PHP_FALIAS(hasAttributes, dom_node_has_attributes, NULL)
|
|
|
|
PHP_FALIAS(compareDocumentPosition, dom_node_compare_document_position, NULL)
|
|
|
|
PHP_FALIAS(isSameNode, dom_node_is_same_node, NULL)
|
|
|
|
PHP_FALIAS(lookupPrefix, dom_node_lookup_prefix, NULL)
|
|
|
|
PHP_FALIAS(isDefaultNamespace, dom_node_is_default_namespace, NULL)
|
|
|
|
PHP_FALIAS(lookupNamespaceUri, dom_node_lookup_namespace_uri, NULL)
|
|
|
|
PHP_FALIAS(isEqualNode, dom_node_is_equal_node, NULL)
|
|
|
|
PHP_FALIAS(getFeature, dom_node_get_feature, NULL)
|
|
|
|
PHP_FALIAS(setUserData, dom_node_set_user_data, NULL)
|
|
|
|
PHP_FALIAS(getUserData, dom_node_get_user_data, NULL)
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* {{{ proto nodeName string
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-F68D095
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_node_name_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlNsPtr ns;
|
2003-06-06 01:06:52 +08:00
|
|
|
char *str = NULL;
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlChar *qname = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
switch (nodep->type) {
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
|
|
|
case XML_ELEMENT_NODE:
|
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:53:08 +08:00
|
|
|
qname = xmlStrcat(qname, nodep->name);
|
|
|
|
str = qname;
|
|
|
|
} else {
|
|
|
|
str = (char *) nodep->name;
|
2003-10-05 19:52:22 +08:00
|
|
|
}
|
|
|
|
break;
|
2003-10-20 23:50:34 +08:00
|
|
|
case XML_NAMESPACE_DECL:
|
|
|
|
ns = nodep->ns;
|
|
|
|
if (ns != NULL && ns->prefix) {
|
|
|
|
qname = xmlStrdup("xmlns");
|
|
|
|
qname = xmlStrcat(qname, ":");
|
|
|
|
qname = xmlStrcat(qname, nodep->name);
|
|
|
|
str = qname;
|
|
|
|
} else {
|
|
|
|
str = (char *) nodep->name;
|
|
|
|
}
|
|
|
|
break;
|
2003-06-06 01:06:52 +08:00
|
|
|
case XML_DOCUMENT_TYPE_NODE:
|
|
|
|
case XML_DTD_NODE:
|
|
|
|
case XML_PI_NODE:
|
|
|
|
case XML_ENTITY_DECL:
|
|
|
|
case XML_ENTITY_REF_NODE:
|
|
|
|
case XML_NOTATION_NODE:
|
|
|
|
str = (char *) nodep->name;
|
|
|
|
break;
|
|
|
|
case XML_CDATA_SECTION_NODE:
|
|
|
|
str = "#cdata-section";
|
|
|
|
break;
|
|
|
|
case XML_COMMENT_NODE:
|
|
|
|
str = "#comment";
|
|
|
|
break;
|
|
|
|
case XML_HTML_DOCUMENT_NODE:
|
|
|
|
case XML_DOCUMENT_NODE:
|
|
|
|
str = "#document";
|
|
|
|
break;
|
|
|
|
case XML_DOCUMENT_FRAG_NODE:
|
|
|
|
str = "#document-fragment";
|
|
|
|
break;
|
|
|
|
case XML_TEXT_NODE:
|
|
|
|
str = "#text";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Node Type");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if(str != NULL) {
|
|
|
|
ZVAL_STRING(*retval, str, 1);
|
|
|
|
} else {
|
|
|
|
ZVAL_EMPTY_STRING(*retval);
|
|
|
|
}
|
2003-10-05 19:52:22 +08:00
|
|
|
|
|
|
|
if (qname != NULL) {
|
|
|
|
xmlFree(qname);
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto nodeValue string
|
|
|
|
readonly=no
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-F68D080
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_node_value_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
char *str = NULL;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-12-10 05:56:42 +08:00
|
|
|
/* Access to Element node is implemented as a convience method */
|
2003-06-06 01:06:52 +08:00
|
|
|
switch (nodep->type) {
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
|
|
|
case XML_TEXT_NODE:
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
case XML_COMMENT_NODE:
|
|
|
|
case XML_CDATA_SECTION_NODE:
|
|
|
|
case XML_PI_NODE:
|
|
|
|
str = xmlNodeGetContent(nodep);
|
|
|
|
break;
|
2003-10-20 23:50:34 +08:00
|
|
|
case XML_NAMESPACE_DECL:
|
|
|
|
str = xmlNodeGetContent(nodep->children);
|
|
|
|
break;
|
2003-06-06 01:06:52 +08:00
|
|
|
default:
|
|
|
|
str = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if(str != NULL) {
|
|
|
|
ZVAL_STRING(*retval, str, 1);
|
|
|
|
xmlFree(str);
|
|
|
|
} else {
|
2003-07-13 01:29:20 +08:00
|
|
|
ZVAL_NULL(*retval);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int dom_node_node_value_write(dom_object *obj, zval *newval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-12-10 05:56:42 +08:00
|
|
|
/* Access to Element node is implemented as a convience method */
|
2003-06-06 01:06:52 +08:00
|
|
|
switch (nodep->type) {
|
2003-12-10 05:56:42 +08:00
|
|
|
case XML_ELEMENT_NODE:
|
2003-06-06 01:06:52 +08:00
|
|
|
case XML_ATTRIBUTE_NODE:
|
|
|
|
if (nodep->children) {
|
|
|
|
node_list_unlink(nodep->children TSRMLS_CC);
|
|
|
|
}
|
|
|
|
case XML_TEXT_NODE:
|
|
|
|
case XML_COMMENT_NODE:
|
|
|
|
case XML_CDATA_SECTION_NODE:
|
|
|
|
case XML_PI_NODE:
|
2003-12-10 04:19:44 +08:00
|
|
|
convert_to_string(newval);
|
2003-06-06 01:06:52 +08:00
|
|
|
xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto nodeType unsigned short
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-111237558
|
2003-08-24 18:23:43 +08:00
|
|
|
Since:
|
2003-06-06 01:06:52 +08:00
|
|
|
*/
|
|
|
|
int dom_node_node_type_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
2003-07-13 01:29:20 +08:00
|
|
|
|
|
|
|
/* Specs dictate that they are both type XML_DOCUMENT_TYPE_NODE */
|
|
|
|
if (nodep->type == XML_DTD_NODE) {
|
|
|
|
ZVAL_LONG(*retval, XML_DOCUMENT_TYPE_NODE);
|
|
|
|
} else {
|
|
|
|
ZVAL_LONG(*retval, nodep->type);
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto parentNode node
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1060184317
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_parent_node_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep, *nodeparent;
|
|
|
|
int ret;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
nodeparent = nodep->parent;
|
|
|
|
if (!nodeparent) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (NULL == (*retval = php_dom_create_object(nodeparent, &ret, NULL, *retval, obj TSRMLS_CC))) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Cannot create required DOM object");
|
2003-06-06 01:06:52 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto childNodes nodelist
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1451460987
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_child_nodes_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
2003-12-02 23:17:02 +08:00
|
|
|
xmlNode *nodep;
|
2003-11-30 04:40:18 +08:00
|
|
|
dom_object *intern;
|
2003-07-08 03:37:32 +08:00
|
|
|
|
2003-12-02 23:17:02 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-12-02 23:17:02 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (dom_node_children_valid(nodep) == FAILURE) {
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
} else {
|
|
|
|
php_dom_create_interator(*retval, DOM_NODELIST TSRMLS_CC);
|
|
|
|
intern = (dom_object *)zend_objects_get_address(*retval TSRMLS_CC);
|
|
|
|
dom_namednode_iter(obj, XML_ELEMENT_NODE, intern, NULL, NULL, NULL);
|
|
|
|
}
|
2003-07-13 01:29:20 +08:00
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto firstChild node
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-169727388
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_first_child_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
2003-07-13 01:29:20 +08:00
|
|
|
xmlNode *nodep, *first = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_children_valid(nodep) == SUCCESS) {
|
|
|
|
first = nodep->children;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (!first) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (NULL == (*retval = php_dom_create_object(first, &ret, NULL, *retval, obj TSRMLS_CC))) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Cannot create required DOM object");
|
2003-06-06 01:06:52 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto lastChild node
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-61AD09FB
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_last_child_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
2003-07-13 01:29:20 +08:00
|
|
|
xmlNode *nodep, *last = NULL;
|
2003-06-06 01:06:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_children_valid(nodep) == SUCCESS) {
|
|
|
|
last = nodep->last;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (!last) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (NULL == (*retval = php_dom_create_object(last, &ret, NULL, *retval, obj TSRMLS_CC))) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Cannot create required DOM object");
|
2003-06-06 01:06:52 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto previousSibling node
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-640FB3C8
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_previous_sibling_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep, *prevsib;
|
|
|
|
int ret;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
prevsib = nodep->prev;
|
|
|
|
if (!prevsib) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (NULL == (*retval = php_dom_create_object(prevsib, &ret, NULL, *retval, obj TSRMLS_CC))) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Cannot create required DOM object");
|
2003-06-06 01:06:52 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
/* {{{ proto nextSibling node
|
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-6AC54C2F
|
2003-08-24 18:23:43 +08:00
|
|
|
Since:
|
2003-06-06 01:06:52 +08:00
|
|
|
*/
|
|
|
|
int dom_node_next_sibling_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep, *nextsib;
|
|
|
|
int ret;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
nextsib = nodep->next;
|
|
|
|
if (!nextsib) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (NULL == (*retval = php_dom_create_object(nextsib, &ret, NULL, *retval, obj TSRMLS_CC))) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Cannot create required DOM object");
|
2003-06-06 01:06:52 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto attributes namednodemap
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-84CF096
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_attributes_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
2003-12-02 23:17:02 +08:00
|
|
|
xmlNode *nodep;
|
2003-11-30 04:40:18 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-12-02 23:17:02 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
2003-12-02 23:17:02 +08:00
|
|
|
if (nodep->type == XML_ELEMENT_NODE) {
|
|
|
|
php_dom_create_interator(*retval, DOM_NAMEDNODEMAP TSRMLS_CC);
|
|
|
|
intern = (dom_object *)zend_objects_get_address(*retval TSRMLS_CC);
|
|
|
|
dom_namednode_iter(obj, XML_ATTRIBUTE_NODE, intern, NULL, NULL, NULL);
|
|
|
|
} else {
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto ownerDocument dom_document
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-node-ownerDoc
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
int dom_node_owner_document_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
xmlDocPtr docp;
|
|
|
|
int ret;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
docp = nodep->doc;
|
|
|
|
if (!docp) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (NULL == (*retval = php_dom_create_object((xmlNodePtr) docp, &ret, NULL, *retval, obj TSRMLS_CC))) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Cannot create required DOM object");
|
2003-06-06 01:06:52 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto namespaceUri string
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-NodeNSname
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
int dom_node_namespace_uri_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
char *str = NULL;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
switch (nodep->type) {
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
2003-10-20 23:50:34 +08:00
|
|
|
case XML_NAMESPACE_DECL:
|
2003-06-06 01:06:52 +08:00
|
|
|
if (nodep->ns != NULL) {
|
|
|
|
str = (char *) nodep->ns->href;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if(str != NULL) {
|
|
|
|
ZVAL_STRING(*retval, str, 1);
|
|
|
|
} else {
|
2003-07-13 01:29:20 +08:00
|
|
|
ZVAL_NULL(*retval);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto prefix string
|
|
|
|
readonly=no
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-NodeNSPrefix
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
int dom_node_prefix_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
xmlNsPtr ns;
|
|
|
|
char *str = NULL;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
switch (nodep->type) {
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
2003-10-20 23:50:34 +08:00
|
|
|
case XML_NAMESPACE_DECL:
|
2003-06-06 01:06:52 +08:00
|
|
|
ns = nodep->ns;
|
2003-07-28 01:57:06 +08:00
|
|
|
if (ns != NULL && ns->prefix) {
|
|
|
|
str = (char *) ns->prefix;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
ZVAL_EMPTY_STRING(*retval);
|
|
|
|
} else {
|
|
|
|
ZVAL_STRING(*retval, str, 1);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int dom_node_prefix_write(dom_object *obj, zval *newval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
xmlDocPtr doc;
|
|
|
|
xmlNsPtr ns, curns = NULL;
|
|
|
|
char *strURI;
|
|
|
|
char *prefix;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
switch (nodep->type) {
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
case XML_ATTRIBUTE_NODE:
|
|
|
|
prefix = Z_STRVAL_P(newval);
|
2003-07-28 01:57:06 +08:00
|
|
|
if (nodep->ns != NULL && !xmlStrEqual(nodep->ns->prefix, (xmlChar *)prefix)) {
|
|
|
|
strURI = (char *) nodep->ns->href;
|
|
|
|
if (strURI == NULL ||
|
|
|
|
(!strcmp (prefix, "xml") && strcmp(strURI, XML_XML_NAMESPACE)) ||
|
|
|
|
(nodep->type == XML_ATTRIBUTE_NODE && !strcmp (prefix, "xmlns") &&
|
|
|
|
strcmp (strURI, DOM_XMLNS_NAMESPACE)) ||
|
|
|
|
(nodep->type == XML_ATTRIBUTE_NODE && !strcmp (nodep->name, "xmlns"))) {
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NAMESPACE_ERR, dom_get_strict_error(obj->document) TSRMLS_CC);
|
2003-07-28 01:57:06 +08:00
|
|
|
return FAILURE;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-07-28 01:57:06 +08:00
|
|
|
ns = xmlNewNs(NULL, nodep->ns->href, (xmlChar *)prefix);
|
|
|
|
if (nodep->doc != NULL) {
|
|
|
|
doc = nodep->doc;
|
|
|
|
if (doc->oldNs == NULL) {
|
|
|
|
doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
|
|
|
|
memset(doc->oldNs, 0, sizeof(xmlNs));
|
|
|
|
doc->oldNs->type = XML_LOCAL_NAMESPACE;
|
|
|
|
doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE);
|
|
|
|
doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
curns = doc->oldNs;
|
|
|
|
while (curns->next != NULL) {
|
|
|
|
curns = curns->next;
|
|
|
|
}
|
|
|
|
curns->next = ns;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2003-07-28 01:57:06 +08:00
|
|
|
nodep->ns = curns;
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto localName string
|
|
|
|
readonly=yes
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-NodeNSLocalN
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
int dom_node_local_name_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
2003-07-08 03:37:32 +08:00
|
|
|
|
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
2003-10-20 23:50:34 +08:00
|
|
|
if (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE || nodep->type == XML_NAMESPACE_DECL) {
|
2003-06-06 01:06:52 +08:00
|
|
|
ZVAL_STRING(*retval, (char *) (nodep->name), 1);
|
|
|
|
} else {
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
/* {{{ proto baseURI string
|
|
|
|
readonly=yes
|
2003-06-06 01:06:52 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-baseURI
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
int dom_node_base_uri_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
2003-10-05 19:52:22 +08:00
|
|
|
xmlNode *nodep;
|
|
|
|
xmlChar *baseuri;
|
|
|
|
|
|
|
|
nodep = dom_object_get_node(obj);
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
2003-10-05 19:52:22 +08:00
|
|
|
|
|
|
|
baseuri = xmlNodeGetBase(nodep->doc, nodep);
|
|
|
|
if (baseuri) {
|
|
|
|
ZVAL_STRING(*retval, (char *) (baseuri), 1);
|
|
|
|
xmlFree(baseuri);
|
|
|
|
} else {
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto textContent string
|
|
|
|
readonly=no
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-textContent
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
int dom_node_text_content_read(dom_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
xmlNode *nodep;
|
|
|
|
char *str = NULL;
|
|
|
|
|
2003-07-08 03:37:32 +08:00
|
|
|
nodep = dom_object_get_node(obj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
str = xmlNodeGetContent(nodep);
|
|
|
|
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
|
|
|
|
if(str != NULL) {
|
|
|
|
ZVAL_STRING(*retval, str, 1);
|
|
|
|
} else {
|
|
|
|
ZVAL_EMPTY_STRING(*retval);
|
|
|
|
}
|
|
|
|
xmlFree(str);
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dom_node_text_content_write(dom_object *obj, zval *newval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_node_insert_before(node newChild, node refChild);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-952280727
|
2003-08-24 18:23:43 +08:00
|
|
|
Since:
|
2003-06-06 01:06:52 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_insert_before)
|
|
|
|
{
|
|
|
|
zval *id, *node, *ref, *rv = NULL;
|
|
|
|
xmlNodePtr child, new_child, parentp, refp;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *childobj, *refpobj;
|
2003-08-24 18:23:43 +08:00
|
|
|
int ret, stricterror;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(parentp, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo!", &node, &ref) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(child, node, xmlNodePtr, childobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
new_child = NULL;
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
stricterror = dom_get_strict_error(intern->document);
|
|
|
|
|
|
|
|
if (dom_node_is_read_only(parentp) == SUCCESS ||
|
2003-07-13 01:29:20 +08:00
|
|
|
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (dom_hierarchy(parentp, child) == FAILURE) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
RETURN_FALSE;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-06-10 04:20:55 +08:00
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (child->doc != parentp->doc && child->doc != NULL) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
if (child->doc == NULL && parentp->doc != NULL) {
|
|
|
|
childobj->document = intern->document;
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_increment_doc_ref((php_libxml_node_object *)childobj, NULL TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (ref != NULL) {
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(refp, ref, xmlNodePtr, refpobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
if (refp->parent != parentp) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NOT_FOUND_ERR, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child->parent != NULL) {
|
|
|
|
xmlUnlinkNode(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child->type == XML_TEXT_NODE) {
|
|
|
|
if (refp->type == XML_TEXT_NODE) {
|
|
|
|
xmlChar *tmp;
|
|
|
|
|
|
|
|
tmp = xmlStrdup(child->content);
|
|
|
|
tmp = xmlStrcat(tmp, refp->content);
|
|
|
|
xmlNodeSetContent(refp, tmp);
|
|
|
|
xmlFree(tmp);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(child TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, refp, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((refp->prev != NULL) && (refp->prev->type == XML_TEXT_NODE)
|
|
|
|
&& (refp->name == refp->prev->name)) {
|
|
|
|
xmlNodeAddContent(refp->prev, child->content);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(child TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, refp->prev, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (child->type == XML_ATTRIBUTE_NODE) {
|
|
|
|
xmlAttrPtr lastattr;
|
|
|
|
|
|
|
|
if (child->ns == NULL)
|
|
|
|
lastattr = xmlHasProp(refp->parent, child->name);
|
|
|
|
else
|
|
|
|
lastattr = xmlHasNsProp(refp->parent, child->name, child->ns->href);
|
|
|
|
if (lastattr != NULL) {
|
|
|
|
if (lastattr != (xmlAttrPtr) child) {
|
|
|
|
xmlUnlinkNode((xmlNodePtr) lastattr);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource((xmlNodePtr) lastattr TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
} else {
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
new_child = xmlAddPrevSibling(refp, child);
|
|
|
|
} else {
|
|
|
|
if (child->parent == parentp){
|
|
|
|
xmlUnlinkNode(child);
|
|
|
|
}
|
|
|
|
if (child->type == XML_TEXT_NODE) {
|
|
|
|
if ((parentp->type == XML_TEXT_NODE) &&
|
|
|
|
(parentp->content != NULL) &&
|
|
|
|
(parentp != child)) {
|
|
|
|
xmlNodeAddContent(parentp, child->content);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(child TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, parentp, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((parentp->last != NULL) && (parentp->last->type == XML_TEXT_NODE) &&
|
|
|
|
(parentp->last->name == child->name) &&
|
|
|
|
(parentp->last != child)) {
|
|
|
|
xmlNodeAddContent(parentp->last, child->content);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(child TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, parentp->last, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (child->type == XML_ATTRIBUTE_NODE) {
|
|
|
|
xmlAttrPtr lastattr;
|
|
|
|
|
|
|
|
if (child->ns == NULL)
|
|
|
|
lastattr = xmlHasProp(parentp, child->name);
|
|
|
|
else
|
|
|
|
lastattr = xmlHasNsProp(parentp, child->name, child->ns->href);
|
|
|
|
if (lastattr != NULL) {
|
|
|
|
if (lastattr != (xmlAttrPtr) child) {
|
|
|
|
xmlUnlinkNode((xmlNodePtr) lastattr);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource((xmlNodePtr) lastattr TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
} else {
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (child->type == XML_DOCUMENT_FRAG_NODE) {
|
|
|
|
new_child = xmlAddChildList(parentp, child->children);
|
|
|
|
if (new_child != NULL) {
|
|
|
|
child->children = NULL;
|
|
|
|
}
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, new_child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
new_child = xmlAddChild(parentp, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == new_child) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't add newnode as the previous sibling of refnode");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, new_child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_insert_before */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_node_replace_child(node newChild, node oldChild);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-785887307
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_replace_child)
|
|
|
|
{
|
|
|
|
zval *id, *newnode, *oldnode;
|
|
|
|
xmlNodePtr children, newchild, oldchild, nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *newchildobj, *oldchildobj;
|
2003-08-24 18:23:43 +08:00
|
|
|
int foundoldchild = 0, stricterror;
|
2003-06-10 04:20:55 +08:00
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_children_valid(nodep) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo", &newnode, &oldnode) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(newchild, newnode, xmlNodePtr, newchildobj);
|
|
|
|
DOM_GET_OBJ(oldchild, oldnode, xmlNodePtr, oldchildobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
children = nodep->children;
|
|
|
|
if (!children) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
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(nodep) == SUCCESS ||
|
|
|
|
(newchild->parent != NULL && dom_node_is_read_only(newchild->parent) == SUCCESS)) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (newchild->doc != nodep->doc && newchild->doc != NULL) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dom_hierarchy(nodep, newchild) == FAILURE) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
RETURN_FALSE;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for the old child and wether the new child is already a child */
|
|
|
|
while (children) {
|
|
|
|
if (children == oldchild) {
|
|
|
|
foundoldchild = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
children = children->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundoldchild) {
|
|
|
|
zval *rv = NULL;
|
|
|
|
if (oldchild != newchild) {
|
|
|
|
xmlNodePtr node;
|
2003-06-10 04:20:55 +08:00
|
|
|
if (newchild->doc == NULL && nodep->doc != NULL) {
|
2003-07-13 01:29:20 +08:00
|
|
|
xmlSetTreeDoc(newchild, nodep->doc);
|
2003-06-10 04:20:55 +08:00
|
|
|
newchildobj->document = intern->document;
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_increment_doc_ref((php_libxml_node_object *)newchildobj, NULL TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-06-16 03:58:42 +08:00
|
|
|
node = xmlReplaceNode(oldchild, newchild);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, oldchild, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
} else {
|
2003-08-24 18:23:43 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_replace_child */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_node_remove_child(node oldChild);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1734834066
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_remove_child)
|
|
|
|
{
|
|
|
|
zval *id, *node;
|
|
|
|
xmlNodePtr children, child, nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *childobj;
|
2003-08-24 18:23:43 +08:00
|
|
|
int ret, stricterror;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_children_valid(nodep) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(child, node, xmlNodePtr, childobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
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(nodep) == SUCCESS ||
|
|
|
|
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
children = nodep->children;
|
|
|
|
if (!children) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NOT_FOUND_ERR, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (children) {
|
|
|
|
if (children == child) {
|
|
|
|
zval *rv = NULL;
|
|
|
|
xmlUnlinkNode(child);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
children = children->next;
|
|
|
|
}
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NOT_FOUND_ERR, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_remove_child */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_node_append_child(node newChild);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-184E7107
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_append_child)
|
|
|
|
{
|
|
|
|
zval *id, *node, *rv = NULL;
|
|
|
|
xmlNodePtr child, nodep, new_child = NULL;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *childobj;
|
2003-07-28 01:57:06 +08:00
|
|
|
xmlNsPtr nsptr;
|
2003-08-24 18:23:43 +08:00
|
|
|
int ret, stricterror;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-13 01:29:20 +08:00
|
|
|
if (dom_node_children_valid(nodep) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(child, node, xmlNodePtr, childobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
stricterror = dom_get_strict_error(intern->document);
|
|
|
|
|
|
|
|
if (dom_node_is_read_only(nodep) == SUCCESS ||
|
2003-07-13 01:29:20 +08:00
|
|
|
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror TSRMLS_CC);
|
2003-07-13 01:29:20 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (dom_hierarchy(nodep, child) == FAILURE) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
RETURN_FALSE;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(child->doc == NULL || child->doc == nodep->doc)) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_dom_throw_error(WRONG_DOCUMENT_ERR, stricterror TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
if (child->doc == NULL && nodep->doc != NULL) {
|
|
|
|
childobj->document = intern->document;
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_increment_doc_ref((php_libxml_node_object *)childobj, NULL TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (child->parent != NULL){
|
|
|
|
xmlUnlinkNode(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child->type == XML_TEXT_NODE) {
|
|
|
|
if ((nodep->type == XML_TEXT_NODE) &&
|
|
|
|
(nodep->content != NULL)) {
|
|
|
|
xmlNodeAddContent(nodep, child->content);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(child TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, nodep, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((nodep->last != NULL) && (nodep->last->type == XML_TEXT_NODE) &&
|
|
|
|
(nodep->last->name == child->name)) {
|
|
|
|
xmlNodeAddContent(nodep->last, child->content);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource(child TSRMLS_CC);
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, nodep->last, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (child->type == XML_ATTRIBUTE_NODE) {
|
|
|
|
xmlAttrPtr lastattr;
|
|
|
|
|
|
|
|
if (child->ns == NULL)
|
|
|
|
lastattr = xmlHasProp(nodep, child->name);
|
|
|
|
else
|
|
|
|
lastattr = xmlHasNsProp(nodep, child->name, child->ns->href);
|
|
|
|
if (lastattr != NULL) {
|
|
|
|
if (lastattr != (xmlAttrPtr) child) {
|
|
|
|
xmlUnlinkNode((xmlNodePtr) lastattr);
|
2003-10-26 23:57:02 +08:00
|
|
|
php_libxml_node_free_resource((xmlNodePtr) lastattr TSRMLS_CC);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (child->type == XML_DOCUMENT_FRAG_NODE) {
|
|
|
|
new_child = xmlAddChildList(nodep, child->children);
|
|
|
|
if (new_child != NULL) {
|
|
|
|
child->children = NULL;
|
|
|
|
}
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, new_child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_child = xmlAddChild(nodep, child);
|
|
|
|
|
|
|
|
if (new_child == NULL) {
|
2003-08-24 18:23:43 +08:00
|
|
|
php_error(E_WARNING, "Couldn't append node");
|
2003-06-06 01:06:52 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-28 01:57:06 +08:00
|
|
|
if (new_child->nsDef != NULL && new_child->type == XML_ELEMENT_NODE && new_child->nsDef->href != NULL) {
|
|
|
|
if((nsptr = xmlSearchNsByHref(nodep->doc, new_child->parent, new_child->nsDef->href)) &&
|
|
|
|
(new_child->nsDef->prefix == NULL || xmlStrEqual(nsptr->prefix, new_child->nsDef->prefix))) {
|
|
|
|
dom_set_old_ns(nodep->doc, new_child->ns);
|
|
|
|
new_child->nsDef = NULL;
|
|
|
|
new_child->ns = nsptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, new_child, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_node_append_child */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_node_has_child_nodes();
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-810594187
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_has_child_nodes)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNode *nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
DOM_NO_ARGS();
|
2003-07-13 01:29:20 +08:00
|
|
|
|
|
|
|
if (dom_node_children_valid(nodep) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (nodep->children) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_has_child_nodes */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_node_clone_node(boolean deep);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-3A0ED0A4
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_clone_node)
|
|
|
|
{
|
|
|
|
zval *rv = NULL;
|
|
|
|
zval *id;
|
|
|
|
xmlNode *n, *node;
|
2003-06-10 04:20:55 +08:00
|
|
|
int ret;
|
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
long recursive = 0;
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(n, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &recursive) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-24 18:23:43 +08:00
|
|
|
node = xmlDocCopyNode(n, n->doc, recursive);
|
2003-10-26 23:57:02 +08:00
|
|
|
|
|
|
|
/* When deep is false Element nodes still require the attributes
|
|
|
|
Following taken from libxml as xmlDocCopyNode doesnt do this */
|
|
|
|
if (node && n->type == XML_ELEMENT_NODE && recursive == 0) {
|
|
|
|
if (n->nsDef != NULL) {
|
|
|
|
node->nsDef = xmlCopyNamespaceList(n->nsDef);
|
|
|
|
}
|
|
|
|
if (n->ns != NULL) {
|
|
|
|
xmlNsPtr ns;
|
|
|
|
ns = xmlSearchNs(n->doc, node, n->ns->prefix);
|
|
|
|
if (ns == NULL) {
|
|
|
|
ns = xmlSearchNs(n->doc, n, n->ns->prefix);
|
|
|
|
if (ns != NULL) {
|
|
|
|
xmlNodePtr root = node;
|
|
|
|
|
|
|
|
while (root->parent != NULL) {
|
|
|
|
root = root->parent;
|
|
|
|
}
|
|
|
|
node->ns = xmlNewNs(root, ns->href, ns->prefix);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
node->ns = ns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n->properties != NULL) {
|
|
|
|
node->properties = xmlCopyPropList(node, n->properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:06:52 +08:00
|
|
|
if (!node) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_RET_OBJ(rv, node, &ret, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_node_clone_node */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto dom_void dom_node_normalize();
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-normalize
|
|
|
|
Since:
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_normalize)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNode *nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
DOM_NO_ARGS();
|
|
|
|
|
|
|
|
dom_normalize(nodep TSRMLS_CC);
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_normalize */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_node_is_supported(string feature, string version);
|
2003-06-13 04:02:05 +08:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Level-2-Core-Node-supports
|
2003-06-06 01:06:52 +08:00
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_is_supported)
|
|
|
|
{
|
2003-06-13 04:02:05 +08:00
|
|
|
int feature_len, version_len;
|
|
|
|
char *feature, *version;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &feature, &feature_len, &version, &version_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dom_has_feature(feature, version)) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_node_is_supported */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_node_has_attributes();
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-NodeHasAttrs
|
|
|
|
Since: DOM Level 2
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_has_attributes)
|
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
xmlNode *nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
DOM_NO_ARGS();
|
|
|
|
|
|
|
|
if (nodep->type != XML_ELEMENT_NODE)
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
|
|
|
if (nodep->properties) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_has_attributes */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto unsigned short dom_node_compare_document_position(node other);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-compareDocumentPosition
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_compare_document_position)
|
|
|
|
{
|
|
|
|
DOM_NOT_IMPLEMENTED();
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_compare_document_position */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_node_is_same_node(node other);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-isSameNode
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_is_same_node)
|
|
|
|
{
|
|
|
|
zval *id, *node;
|
|
|
|
xmlNodePtr nodeotherp, nodep;
|
2003-06-10 04:20:55 +08:00
|
|
|
dom_object *intern, *nodeotherobj;
|
2003-06-06 01:06:52 +08:00
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-10 04:20:55 +08:00
|
|
|
DOM_GET_OBJ(nodeotherp, node, xmlNodePtr, nodeotherobj);
|
2003-06-06 01:06:52 +08:00
|
|
|
|
|
|
|
if (nodep == nodeotherp) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_is_same_node */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domstring dom_node_lookup_prefix(string namespaceURI);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-lookupNamespacePrefix
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_lookup_prefix)
|
|
|
|
{
|
2003-07-28 01:57:06 +08:00
|
|
|
zval *id;
|
|
|
|
xmlNodePtr nodep, lookupp = NULL;
|
|
|
|
dom_object *intern;
|
|
|
|
xmlNsPtr nsptr;
|
|
|
|
int uri_len = 0;
|
|
|
|
char *uri;
|
|
|
|
|
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uri, &uri_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri_len > 0) {
|
|
|
|
switch (nodep->type) {
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
lookupp = nodep;
|
|
|
|
break;
|
|
|
|
case XML_DOCUMENT_NODE:
|
|
|
|
case XML_HTML_DOCUMENT_NODE:
|
|
|
|
lookupp = xmlDocGetRootElement((xmlDocPtr) nodep);
|
|
|
|
break;
|
|
|
|
case XML_ENTITY_NODE :
|
|
|
|
case XML_NOTATION_NODE:
|
|
|
|
case XML_DOCUMENT_FRAG_NODE:
|
|
|
|
case XML_DOCUMENT_TYPE_NODE:
|
|
|
|
case XML_DTD_NODE:
|
|
|
|
RETURN_NULL();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lookupp = nodep->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookupp != NULL && (nsptr = xmlSearchNsByHref(lookupp->doc, lookupp, uri))) {
|
|
|
|
if (nsptr->prefix != NULL) {
|
|
|
|
RETURN_STRING((char *) nsptr->prefix, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_node_lookup_prefix */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_node_is_default_namespace(string namespaceURI);
|
2003-10-05 19:52:22 +08:00
|
|
|
URL: http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-isDefaultNamespace
|
2003-06-06 01:06:52 +08:00
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_is_default_namespace)
|
|
|
|
{
|
2003-10-05 19:52:22 +08:00
|
|
|
zval *id;
|
|
|
|
xmlNodePtr nodep;
|
|
|
|
dom_object *intern;
|
|
|
|
xmlNsPtr nsptr;
|
|
|
|
int uri_len = 0;
|
|
|
|
char *uri;
|
|
|
|
|
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uri, &uri_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri_len > 0) {
|
|
|
|
nsptr = xmlSearchNs(nodep->doc, nodep, NULL);
|
|
|
|
if (nsptr && xmlStrEqual(nsptr->href, uri)) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_node_is_default_namespace */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domstring dom_node_lookup_namespace_uri(string prefix);
|
2003-10-05 19:52:22 +08:00
|
|
|
URL: http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespaceURI
|
2003-06-06 01:06:52 +08:00
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_lookup_namespace_uri)
|
|
|
|
{
|
2003-07-28 01:57:06 +08:00
|
|
|
zval *id;
|
|
|
|
xmlNodePtr nodep;
|
|
|
|
dom_object *intern;
|
|
|
|
xmlNsPtr nsptr;
|
|
|
|
int prefix_len = 0;
|
|
|
|
char *prefix;
|
|
|
|
|
|
|
|
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &prefix, &prefix_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefix_len > 0) {
|
|
|
|
nsptr = xmlSearchNs(nodep->doc, nodep, prefix);
|
|
|
|
if (nsptr && nsptr->href != NULL) {
|
|
|
|
RETURN_STRING((char *) nsptr->href, 1);
|
|
|
|
}
|
|
|
|
}
|
2003-08-24 18:23:43 +08:00
|
|
|
|
2003-07-28 01:57:06 +08:00
|
|
|
RETURN_NULL();
|
2003-06-06 01:06:52 +08:00
|
|
|
}
|
|
|
|
/* }}} end dom_node_lookup_namespace_uri */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto boolean dom_node_is_equal_node(node arg);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-isEqualNode
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_is_equal_node)
|
|
|
|
{
|
|
|
|
DOM_NOT_IMPLEMENTED();
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_is_equal_node */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domnode dom_node_get_feature(string feature, string version);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-getFeature
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_get_feature)
|
|
|
|
{
|
|
|
|
DOM_NOT_IMPLEMENTED();
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_get_feature */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domuserdata dom_node_set_user_data(string key, domuserdata data, userdatahandler handler);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-setUserData
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_set_user_data)
|
|
|
|
{
|
|
|
|
DOM_NOT_IMPLEMENTED();
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_set_user_data */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto domuserdata dom_node_get_user_data(string key);
|
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-getUserData
|
|
|
|
Since: DOM Level 3
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(dom_node_get_user_data)
|
|
|
|
{
|
|
|
|
DOM_NOT_IMPLEMENTED();
|
|
|
|
}
|
|
|
|
/* }}} end dom_node_get_user_data */
|
2003-08-22 23:04:29 +08:00
|
|
|
#endif
|