summaryrefslogtreecommitdiff
path: root/ext/dom
diff options
context:
space:
mode:
Diffstat (limited to 'ext/dom')
-rw-r--r--ext/dom/TODO12
-rw-r--r--ext/dom/attr.c226
-rw-r--r--ext/dom/cdatasection.c73
-rw-r--r--ext/dom/characterdata.c190
-rw-r--r--ext/dom/comment.c72
-rw-r--r--ext/dom/config.m481
-rw-r--r--ext/dom/document.c1125
-rw-r--r--ext/dom/documentfragment.c66
-rw-r--r--ext/dom/documenttype.c267
-rw-r--r--ext/dom/dom.dsp246
-rw-r--r--ext/dom/dom_ce.h54
-rw-r--r--ext/dom/dom_fe.h237
-rw-r--r--ext/dom/dom_properties.h145
-rw-r--r--ext/dom/domconfiguration.c77
-rw-r--r--ext/dom/domerror.c137
-rw-r--r--ext/dom/domerrorhandler.c53
-rw-r--r--ext/dom/domexception.c112
-rw-r--r--ext/dom/domimplementation.c244
-rw-r--r--ext/dom/domimplementationlist.c69
-rw-r--r--ext/dom/domimplementationsource.c65
-rw-r--r--ext/dom/domlocator.c121
-rw-r--r--ext/dom/domstringlist.c69
-rw-r--r--ext/dom/element.c779
-rw-r--r--ext/dom/entity.c180
-rw-r--r--ext/dom/entityreference.c78
-rw-r--r--ext/dom/namednodemap.c141
-rw-r--r--ext/dom/namelist.c81
-rw-r--r--ext/dom/node.c1274
-rw-r--r--ext/dom/nodelist.c69
-rw-r--r--ext/dom/notation.c89
-rw-r--r--ext/dom/php_dom.c1144
-rw-r--r--ext/dom/php_dom.h89
-rw-r--r--ext/dom/processinginstruction.c138
-rw-r--r--ext/dom/string_extend.c65
-rw-r--r--ext/dom/tests/dom001.phpt275
-rw-r--r--ext/dom/tests/dom_test.inc43
-rw-r--r--ext/dom/tests/skipif.inc1
-rw-r--r--ext/dom/text.c124
-rw-r--r--ext/dom/typeinfo.c73
-rw-r--r--ext/dom/userdatahandler.c53
-rw-r--r--ext/dom/xml_common.h82
41 files changed, 8519 insertions, 0 deletions
diff --git a/ext/dom/TODO b/ext/dom/TODO
new file mode 100644
index 0000000000..f6b7fe2e61
--- /dev/null
+++ b/ext/dom/TODO
@@ -0,0 +1,12 @@
+1) Change _node_list_pointer to something faster than just a linked list.
+ Currently there to test that unlinked node tracking works
+2) Possible create new object type for documents as these are the only types which need to track nodes
+ - Would also require its own dtor functionality
+3) Define correct behavior. When certain types of nodes are destroyed,
+ do we unlink children (if referenced) or just destroy them. (Element/Attribute nodes)
+4) Find out where XPath goes (this extension or its own)
+5) What DOM object types are really needed (i.e. not currently using DOMString)
+6) Determine how to handle non speced functionality.
+ i.e validation (add method or implement as property for processing)
+
+
diff --git a/ext/dom/attr.c b/ext/dom/attr.c
new file mode 100644
index 0000000000..2136b2a651
--- /dev/null
+++ b/ext/dom/attr.c
@@ -0,0 +1,226 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domattr extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-637646024
+* Since:
+*/
+
+zend_function_entry php_dom_attr_class_functions[] = {
+ PHP_FALIAS(isId, dom_attr_is_id, NULL)
+ PHP_FALIAS(domattr, dom_attr_attr, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto domnode dom_attr_attr(string name, [string value]); */
+PHP_FUNCTION(dom_attr_attr)
+{
+
+ zval *id;
+ xmlAttrPtr nodep = NULL;
+ xmlNodePtr oldnode = NULL;
+ dom_object *intern;
+ char *name, *value = NULL;
+ int name_len, value_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ if (name_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name is required");
+ RETURN_FALSE;
+ }
+
+ nodep = xmlNewProp(NULL, (xmlChar *) name, value);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, (xmlNodePtr) nodep TSRMLS_CC);
+ }
+}
+
+/* }}} end dom_attr_attr */
+
+
+/* {{{ proto name string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1112119403
+Since:
+*/
+int dom_attr_name_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlAttrPtr attrp;
+
+ attrp = obj->ptr;
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, (char *) (attrp->name), 1);
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto specified boolean
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-862529273
+Since:
+*/
+int dom_attr_specified_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ /* TODO */
+ ALLOC_ZVAL(*retval);
+ ZVAL_TRUE(*retval);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto value string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-221662474
+Since:
+*/
+int dom_attr_value_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlAttrPtr attrp;
+ xmlChar *content;
+
+ attrp = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+
+ if ((content = xmlNodeGetContent((xmlNodePtr) attrp)) != NULL) {
+ ZVAL_STRING(*retval, content, 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+ xmlFree(content);
+
+ return SUCCESS;
+
+}
+
+int dom_attr_value_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlAttrPtr attrp;
+
+ attrp = obj->ptr;
+
+ if (attrp->children) {
+ node_list_unlink(attrp->children TSRMLS_CC);
+ }
+ xmlNodeSetContentLen((xmlNodePtr) attrp, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto ownerElement element
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Attr-ownerElement
+Since: DOM Level 2
+*/
+int dom_attr_owner_element_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+
+ zval *wrapper;
+ xmlNodePtr nodep, nodeparent;
+ int ret;
+
+ nodep = obj->ptr;
+
+ nodeparent = nodep->parent;
+ if (!nodeparent) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(nodeparent);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(nodeparent, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ return FAILURE;
+ }
+ return SUCCESS;
+
+}
+
+/* }}} */
+
+
+
+/* {{{ proto schemaTypeInfo typeinfo
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Attr-schemaTypeInfo
+Since: DOM Level 3
+*/
+int dom_attr_schema_type_info_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not yet implemented");
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto boolean dom_attr_is_id();
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Attr-isId
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_attr_is_id)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_attr_is_id */
diff --git a/ext/dom/cdatasection.c b/ext/dom/cdatasection.c
new file mode 100644
index 0000000000..21ccefea1f
--- /dev/null
+++ b/ext/dom/cdatasection.c
@@ -0,0 +1,73 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domcdatasection extends domtext
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-667469212
+* Since:
+*/
+
+zend_function_entry php_dom_cdatasection_class_functions[] = {
+ PHP_FALIAS("domcdatasection", dom_cdatasection_cdatasection, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto domnode dom_cdatasection_cdatasection([string value]); */
+PHP_FUNCTION(dom_cdatasection_cdatasection)
+{
+
+ zval *id;
+ xmlNodePtr nodep = NULL, oldnode = NULL;
+ dom_object *intern;
+ char *value = NULL;
+ int value_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
+ return;
+ }
+
+
+ nodep = xmlNewCDataBlock(NULL, (xmlChar *) value, value_len);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, nodep TSRMLS_CC);
+ }
+}
+/* }}} end dom_cdatasection_cdatasection */
diff --git a/ext/dom/characterdata.c b/ext/dom/characterdata.c
new file mode 100644
index 0000000000..4bc656a3bc
--- /dev/null
+++ b/ext/dom/characterdata.c
@@ -0,0 +1,190 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domcharacterdata extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-FF21A306
+* Since:
+*/
+
+zend_function_entry php_dom_characterdata_class_functions[] = {
+ PHP_FALIAS(substringData, dom_characterdata_substring_data, NULL)
+ PHP_FALIAS(appendData, dom_characterdata_append_data, NULL)
+ PHP_FALIAS(insertData, dom_characterdata_insert_data, NULL)
+ PHP_FALIAS(deleteData, dom_characterdata_delete_data, NULL)
+ PHP_FALIAS(replaceData, dom_characterdata_replace_data, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto data string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-72AB8359
+Since:
+*/
+int dom_characterdata_data_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNodePtr nodep;
+ xmlChar *content;
+
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+ if ((content = xmlNodeGetContent(nodep)) != NULL) {
+ ZVAL_STRING(*retval, content, 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+ xmlFree(content);
+
+ return SUCCESS;
+}
+
+int dom_characterdata_data_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlNode *nodep;
+
+ nodep = obj->ptr;
+ xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+long dom_utf16Length (xmlChar *utf8str) {
+ long len = 0L, i;
+ char c;
+
+ for (i = 0L; (c = utf8str[i]) != '\0'; i++)
+ if ((c & 0xf8) == 0xf0)
+ len += 2L;
+ else if ((c & 0xc0) != 0x80)
+ len++;
+
+ return len;
+}
+
+/* {{{ proto length unsigned long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-7D61178C
+Since:
+*/
+int dom_characterdata_length_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNodePtr nodep;
+ xmlChar *content;
+ long length;
+
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+ content = xmlNodeGetContent(nodep);
+ length = dom_utf16Length(content);
+ xmlFree(content);
+ ZVAL_LONG(*retval, length);
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domstring dom_characterdata_substring_data(unsigned long offset, unsigned long count);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-6531BCCF
+Since:
+*/
+PHP_FUNCTION(dom_characterdata_substring_data)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_characterdata_substring_data */
+
+
+/* {{{ proto dom_void dom_characterdata_append_data(string arg);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-32791A2F
+Since:
+*/
+PHP_FUNCTION(dom_characterdata_append_data)
+{
+ zval *id;
+ xmlNode *nodep;
+ char *arg;
+ int arg_len;
+
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
+ return;
+ }
+
+ xmlTextConcat(nodep, arg, arg_len);
+
+ RETURN_TRUE;
+}
+/* }}} end dom_characterdata_append_data */
+
+
+/* {{{ proto dom_void dom_characterdata_insert_data(unsigned long offset, string arg);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-3EDB695F
+Since:
+*/
+PHP_FUNCTION(dom_characterdata_insert_data)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_characterdata_insert_data */
+
+
+/* {{{ proto dom_void dom_characterdata_delete_data(unsigned long offset, unsigned long count);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-7C603781
+Since:
+*/
+PHP_FUNCTION(dom_characterdata_delete_data)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_characterdata_delete_data */
+
+
+/* {{{ proto dom_void dom_characterdata_replace_data(unsigned long offset, unsigned long count, string arg);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-E5CBA7FB
+Since:
+*/
+PHP_FUNCTION(dom_characterdata_replace_data)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_characterdata_replace_data */
diff --git a/ext/dom/comment.c b/ext/dom/comment.c
new file mode 100644
index 0000000000..7d6c6e9783
--- /dev/null
+++ b/ext/dom/comment.c
@@ -0,0 +1,72 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domcomment extends domcharacterdata
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1728279322
+* Since:
+*/
+
+zend_function_entry php_dom_comment_class_functions[] = {
+ PHP_FALIAS(domcomment, dom_comment_comment, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto dom_comment_comment([string value]); */
+PHP_FUNCTION(dom_comment_comment)
+{
+
+ zval *id;
+ xmlNodePtr nodep = NULL, oldnode = NULL;
+ dom_object *intern;
+ char *value = NULL;
+ int value_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ nodep = xmlNewComment((xmlChar *) value);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, nodep TSRMLS_CC);
+ }
+}
+/* }}} end dom_comment_comment */
diff --git a/ext/dom/config.m4 b/ext/dom/config.m4
new file mode 100644
index 0000000000..c214474391
--- /dev/null
+++ b/ext/dom/config.m4
@@ -0,0 +1,81 @@
+dnl
+dnl $Id$
+dnl
+
+AC_DEFUN(PHP_DOM_CHECK_VERSION,[
+ old_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS=-I$DOM_DIR/include$DOM_DIR_ADD
+ AC_MSG_CHECKING(for libxml version)
+ AC_EGREP_CPP(yes,[
+#include <libxml/xmlversion.h>
+#if LIBXML_VERSION >= 20414
+ yes
+#endif
+ ],[
+ AC_MSG_RESULT(>= 2.4.14)
+ ],[
+ AC_MSG_ERROR(libxml version 2.4.14 or greater required.)
+ ])
+ CPPFLAGS=$old_CPPFLAGS
+])
+
+PHP_ARG_WITH(dom5, for DOM support,
+[ --with-dom5[=DIR] Include new DOM support (requires libxml >= 2.4.14).
+ DIR is the libxml install directory.])
+
+if test -z "$PHP_ZLIB_DIR"; then
+ PHP_ARG_WITH(zlib-dir, for the location of libz,
+ [ --with-zlib-dir[=DIR] DOM: Set the path to libz install prefix.], no, no)
+fi
+
+if test "$PHP_DOM5" != "no"; then
+
+ DOM_DIR_ADD=""
+ if test -r $PHP_DOM5/include/libxml2/libxml/tree.h; then
+ DOM_DIR=$PHP_DOM5
+ DOM_DIR_ADD="/libxml2"
+ elif test -r $PHP_DOM5/include/libxml/tree.h; then
+ DOM_DIR=$PHP_DOM5
+ else
+ for i in /usr/local /usr; do
+ test -r $i/include/libxml/tree.h && DOM_DIR=$i
+ test -r $i/include/libxml2/libxml/tree.h && DOM_DIR=$i && DOM_DIR_ADD="/libxml2"
+ done
+ fi
+
+ if test -z "$DOM_DIR"; then
+ AC_MSG_RESULT(not found)
+ AC_MSG_ERROR(Please reinstall the libxml >= 2.4.14 distribution)
+ fi
+
+ PHP_DOM_CHECK_VERSION
+
+ if test -f $DOM_DIR/lib/libxml2.a -o -f $DOM_DIR/lib/libxml2.$SHLIB_SUFFIX_NAME ; then
+ DOM_LIBNAME=xml2
+ else
+ DOM_LIBNAME=xml
+ fi
+
+ XML2_CONFIG=$DOM_DIR/bin/xml2-config
+
+ if test -x $XML2_CONFIG; then
+ DOM_LIBS=`$XML2_CONFIG --libs`
+ PHP_EVAL_LIBLINE($DOM_LIBS, DOM_SHARED_LIBADD)
+ else
+ PHP_ADD_LIBRARY_WITH_PATH($DOM_LIBNAME, $DOM_DIR/lib, DOM_SHARED_LIBADD)
+ fi
+
+ PHP_ADD_INCLUDE($DOM_DIR/include$DOM_DIR_ADD)
+
+ if test "$PHP_ZLIB_DIR" = "no"; then
+ AC_MSG_ERROR(DOM requires ZLIB. Use --with-zlib-dir=<DIR>)
+ else
+ PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/lib, DOM_SHARED_LIBADD)
+ fi
+
+ AC_DEFINE(HAVE_DOM,1,[ ])
+ PHP_NEW_EXTENSION(dom, php_dom.c attr.c document.c domerrorhandler.c domstringlist.c domexception.c namelist.c processinginstruction.c cdatasection.c documentfragment.c domimplementation.c element.c node.c string_extend.c characterdata.c documenttype.c domimplementationlist.c entity.c nodelist.c text.c comment.c domconfiguration.c domimplementationsource.c entityreference.c notation.c typeinfo.c domerror.c domlocator.c namednodemap.c userdatahandler.c , $ext_shared)
+ PHP_SUBST(DOM_SHARED_LIBADD)
+fi
+
+
diff --git a/ext/dom/document.c b/ext/dom/document.c
new file mode 100644
index 0000000000..a323e73289
--- /dev/null
+++ b/ext/dom/document.c
@@ -0,0 +1,1125 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+typedef struct _idsIterator idsIterator;
+struct _idsIterator {
+ xmlChar *elementId;
+ xmlNode *element;
+};
+
+static void idsHashScanner(void *payload, void *data, xmlChar *name)
+{
+ idsIterator *priv = (idsIterator *) data;
+
+ if (priv->element == NULL && xmlStrEqual (name, priv->elementId)) {
+ priv->element = ((xmlNode *)((xmlID *)payload)->attr)->parent;
+ }
+}
+
+/*
+* class domdocument extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-i-Document
+* Since:
+*/
+
+zend_function_entry php_dom_document_class_functions[] = {
+ PHP_FALIAS(createElement, dom_document_create_element, NULL)
+ PHP_FALIAS(createDocumentFragment, dom_document_create_document_fragment, NULL)
+ PHP_FALIAS(createTextNode, dom_document_create_text_node, NULL)
+ PHP_FALIAS(createComment, dom_document_create_comment, NULL)
+ PHP_FALIAS(createCDATASection, dom_document_create_cdatasection, NULL)
+ PHP_FALIAS(createProcessingInstruction, dom_document_create_processing_instruction, NULL)
+ PHP_FALIAS(createAttribute, dom_document_create_attribute, NULL)
+ PHP_FALIAS(createEntityReference, dom_document_create_entity_reference, NULL)
+ PHP_FALIAS(getElementsByTagName, dom_document_get_elements_by_tag_name, NULL)
+ PHP_FALIAS(importNode, dom_document_import_node, NULL)
+ PHP_FALIAS(createElementNS, dom_document_create_element_ns, NULL)
+ PHP_FALIAS(createAttributeNS, dom_document_create_attribute_ns, NULL)
+ PHP_FALIAS(getElementsByTagNameNS, dom_document_get_elements_by_tag_name_ns, NULL)
+ PHP_FALIAS(getElementById, dom_document_get_element_by_id, NULL)
+ PHP_FALIAS(adoptNode, dom_document_adopt_node, NULL)
+ PHP_FALIAS(normalizeDocument, dom_document_normalize_document, NULL)
+ PHP_FALIAS(renameNode, dom_document_rename_node, NULL)
+ PHP_FALIAS(load, dom_document_load, NULL)
+ PHP_FALIAS(save, dom_document_save, NULL)
+ PHP_FALIAS(loadXML, dom_document_loadxml, NULL)
+ PHP_FALIAS(saveXML, dom_document_savexml, NULL)
+ PHP_FALIAS(domdocument, dom_document_document, NULL)
+ {NULL, NULL, NULL}
+};
+
+
+/* {{{ proto doctype documenttype
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-B63ED1A31
+Since:
+*/
+int dom_document_doctype_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ zval *wrapper;
+ xmlDoc *docp;
+ xmlDtdPtr dtdptr;
+ int ret;
+
+ docp = obj->ptr;
+
+
+ dtdptr = xmlGetIntSubset(docp);
+ if (!dtdptr) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data((xmlNodePtr) dtdptr);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object((xmlNodePtr) dtdptr, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ return FAILURE;
+ }
+ return SUCCESS;
+
+}
+
+/* }}} */
+
+
+
+/* {{{ proto implementation domimplementation
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1B793EBA
+Since:
+*/
+int dom_document_implementation_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ php_dom_create_implementation(retval TSRMLS_CC);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto domelement document_element documentElement
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-87CD092
+Since:
+*/
+int dom_document_document_element_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ zval *wrapper;
+ xmlDoc *docp;
+ xmlNode *root;
+ int ret;
+
+ docp = obj->ptr;
+
+ root = xmlDocGetRootElement(docp);
+ if (!root) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(root);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(root, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto actual_encoding string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-actualEncoding
+Since: DOM Level 3
+*/
+/* READ ONLY FOR NOW USING ENCODING PROPERTY
+int dom_document_actual_encoding_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+int dom_document_actual_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ return SUCCESS;
+}
+*/
+
+/* }}} */
+
+/* {{{ proto encoding string
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-encoding
+Since: DOM Level 3
+*/
+int dom_document_encoding_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDoc *docp;
+ char *encoding;
+
+ docp = obj->ptr;
+ encoding = (char *) docp->encoding;
+ ALLOC_ZVAL(*retval);
+
+ if (encoding != NULL) {
+ ZVAL_STRING(*retval, encoding, 1);
+ } else {
+ ZVAL_NULL(*retval);
+ }
+
+ return SUCCESS;
+}
+
+int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlDoc *docp;
+ int charset;
+
+ docp = (xmlDoc *) obj->ptr;
+ if (docp->encoding != NULL) {
+ xmlFree((xmlChar *)docp->encoding);
+ }
+
+ docp->encoding = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
+ charset = (int)xmlParseCharEncoding( (const char*)docp->encoding );
+ if ( charset > 0 ) {
+ docp->charset = charset;
+ return SUCCESS;
+ } else {
+ /* TODO: ERROR XML_CHAR_ENCODING_ERROR */
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto standalone boolean
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-standalone
+Since: DOM Level 3
+*/
+int dom_document_standalone_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDoc *docp;
+ int standalone;
+
+ docp = obj->ptr;
+ ALLOC_ZVAL(*retval);
+ standalone = docp->standalone;
+ ZVAL_BOOL(*retval, standalone);
+
+ return SUCCESS;
+}
+
+int dom_document_standalone_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlDoc *docp;
+ int standalone;
+
+ docp = obj->ptr;
+ standalone = Z_LVAL_P(newval);
+ if (standalone > 0) {
+ docp->standalone = 1;
+ }
+ else if (standalone < 0) {
+ docp->standalone = -1;
+ }
+ else {
+ docp->standalone = 0;
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto version string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-version
+Since: DOM Level 3
+*/
+int dom_document_version_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDoc *docp;
+ char *version;
+
+ docp = obj->ptr;
+ version = (char *) docp->version;
+ ALLOC_ZVAL(*retval);
+
+ if (version != NULL) {
+ ZVAL_STRING(*retval, version, 1);
+ } else {
+ ZVAL_NULL(*retval);
+ }
+
+ return SUCCESS;
+}
+
+int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlDoc *docp;
+
+ docp = obj->ptr;
+ if (docp->version != NULL) {
+ xmlFree((xmlChar *) docp->version );
+ }
+
+ docp->version = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto strict_error_checking boolean
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-strictErrorChecking
+Since: DOM Level 3
+*/
+int dom_document_strict_error_checking_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+int dom_document_strict_error_checking_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto document_uri string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-documentURI
+Since: DOM Level 3
+*/
+int dom_document_document_uri_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDoc *docp;
+ char *url;
+
+ docp = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ url = (char *) docp->URL;
+ if (url != NULL) {
+ ZVAL_STRING(*retval, url, 1);
+ } else {
+ ZVAL_NULL(*retval);
+ }
+
+ return SUCCESS;
+}
+
+int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlDoc *docp;
+
+ docp = obj->ptr;
+ if (docp->URL != NULL) {
+ xmlFree((xmlChar *) docp->URL);
+ }
+
+ docp->URL = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto config domconfiguration
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-config
+Since: DOM Level 3
+*/
+int dom_document_config_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto domelement dom_document_create_element(string tagName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-2141741547
+Since:
+*/
+PHP_FUNCTION(dom_document_create_element)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp;
+ int ret, name_len;
+ char *name;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ node = xmlNewDocNode(docp, NULL, name, NULL);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} end dom_document_create_element */
+
+
+/* {{{ proto domdocumentfragment dom_document_create_document_fragment();
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-35CB04B5
+Since:
+*/
+PHP_FUNCTION(dom_document_create_document_fragment)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp;
+ int ret;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ node = xmlNewDocFragment(docp);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} end dom_document_create_document_fragment */
+
+
+/* {{{ proto domtext dom_document_create_text_node(string data);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1975348127
+Since:
+*/
+PHP_FUNCTION(dom_document_create_text_node)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp;
+ int ret, value_len;
+ char *value;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ node = xmlNewDocText(docp, (xmlChar *) value);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} end dom_document_create_text_node */
+
+
+/* {{{ proto domcomment dom_document_create_comment(string data);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1334481328
+Since:
+*/
+PHP_FUNCTION(dom_document_create_comment)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp;
+ int ret, value_len;
+ char *value;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ node = xmlNewDocComment(docp, (xmlChar *) value);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} end dom_document_create_comment */
+
+
+/* {{{ proto domcdatasection dom_document_create_cdatasection(string data);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D26C0AF8
+Since:
+*/
+PHP_FUNCTION(dom_document_create_cdatasection)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp;
+ int ret, value_len;
+ char *value;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ node = xmlNewCDataBlock(docp, (xmlChar *) value, value_len);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} end dom_document_create_cdatasection */
+
+
+/* {{{ proto domprocessinginstruction dom_document_create_processing_instruction(string target, string data);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-135944439
+Since:
+*/
+PHP_FUNCTION(dom_document_create_processing_instruction)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp;
+ int ret, value_len, name_len;
+ char *name, *value = NULL;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ node->doc = docp;
+
+ dom_add_to_list(node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} end dom_document_create_processing_instruction */
+
+
+/* {{{ proto domattr dom_document_create_attribute(string name);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1084891198
+Since:
+*/
+PHP_FUNCTION(dom_document_create_attribute)
+{
+ zval *id, *rv = NULL;
+ xmlAttrPtr node;
+ xmlDocPtr docp;
+ int ret, name_len;
+ char *name;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ if (name_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name is required");
+ RETURN_FALSE;
+ }
+
+ node = xmlNewDocProp(docp, (xmlChar *) name, NULL);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list((xmlNodePtr) node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, (xmlNodePtr) node, &ret);
+
+}
+/* }}} end dom_document_create_attribute */
+
+
+/* {{{ proto domentityreference dom_document_create_entity_reference(string name);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-392B75AE
+Since:
+*/
+PHP_FUNCTION(dom_document_create_entity_reference)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlDocPtr docp = NULL;
+ int ret, name_len;
+ char *name;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ node = xmlNewReference(docp, name);
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list((xmlNodePtr) node, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, (xmlNodePtr) node, &ret);
+}
+/* }}} end dom_document_create_entity_reference */
+
+
+/* {{{ proto domnodelist dom_document_get_elements_by_tag_name(string tagname);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C9094
+Since:
+*/
+PHP_FUNCTION(dom_document_get_elements_by_tag_name)
+{
+ zval *id;
+ xmlXPathContextPtr ctxp;
+ xmlDocPtr docp;
+ xmlXPathObjectPtr xpathobjp;
+ int name_len, ret;
+ char *str,*name;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ ctxp = xmlXPathNewContext(docp);
+
+ ctxp->node = NULL;
+ str = (char*) emalloc((name_len+3) * sizeof(char)) ;
+ sprintf(str ,"//%s",name);
+
+ xpathobjp = xmlXPathEval(str, ctxp);
+ efree(str);
+ ctxp->node = NULL;
+
+ if (!xpathobjp) {
+ RETURN_FALSE;
+ }
+
+ if (xpathobjp->type == XPATH_NODESET) {
+ int i;
+ xmlNodeSetPtr nodesetp;
+
+ if (NULL == (nodesetp = xpathobjp->nodesetval)) {
+ xmlXPathFreeObject (xpathobjp);
+ xmlXPathFreeContext(ctxp);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+
+ for (i = 0; i < nodesetp->nodeNr; i++) {
+ xmlNodePtr node = nodesetp->nodeTab[i];
+ zval *child=NULL;
+ zval *wrapper;
+ wrapper = dom_object_get_data(node);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(child);
+ }
+
+ child = php_dom_create_object(node, &ret, wrapper, child TSRMLS_CC);
+ add_next_index_zval(return_value, child);
+ }
+ }
+
+ xmlXPathFreeObject(xpathobjp);
+ xmlXPathFreeContext(ctxp);
+}
+/* }}} end dom_document_get_elements_by_tag_name */
+
+
+/* {{{ proto domnode dom_document_import_node(node importedNode, boolean deep);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Core-Document-importNode
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_document_import_node)
+{
+ zval *rv = NULL;
+ zval *id, *node;
+ xmlDocPtr docp;
+ xmlNodePtr nodep, retnodep;
+ int ret;
+ long recursive = 0;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|l", &node, &recursive) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(nodep, node, xmlNodePtr);
+
+ if (nodep->type == XML_HTML_DOCUMENT_NODE || nodep->type == XML_DOCUMENT_NODE
+ || nodep->type == XML_DOCUMENT_TYPE_NODE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot import: Node Type Not Supported");
+ RETURN_FALSE;
+ }
+
+ if (nodep->doc == docp) {
+ retnodep = nodep;
+ } else {
+ retnodep = xmlDocCopyNode(nodep, docp, recursive);
+ if (!retnodep) {
+ RETURN_FALSE;
+ }
+ dom_add_to_list((xmlNodePtr) retnodep, docp TSRMLS_CC);
+ }
+
+ DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret);
+}
+/* }}} end dom_document_import_node */
+
+
+/* {{{ proto domelement dom_document_create_element_ns(string namespaceURI, string qualifiedName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrElNS
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_document_create_element_ns)
+{
+ zval *id, *rv = NULL;
+ xmlDocPtr docp;
+ xmlNodePtr nodep = NULL;
+ xmlNsPtr nsptr;
+ int ret, uri_len = 0, name_len = 0;
+ char *uri, *name;
+ xmlChar *localname = NULL;
+ int errorcode;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ nsptr = dom_get_ns(uri, name, uri_len, name_len, &errorcode, (char **) &localname);
+ if (errorcode == 0) {
+ if (nsptr != NULL) {
+ dom_set_old_ns(docp, nsptr);
+ nodep = xmlNewDocNode (docp, nsptr, localname, NULL);
+ } else {
+ nodep = xmlNewDocNode (docp, NULL, name, NULL);
+ }
+ }
+ if (localname != NULL) {
+ xmlFree(localname);
+ }
+
+ if (errorcode != 0) {
+ php_dom_throw_error(errorcode, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ RETURN_FALSE;
+ }
+
+ if (nodep == NULL) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(nodep, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, nodep, &ret);
+}
+/* }}} end dom_document_create_element_ns */
+
+
+/* {{{ proto domattr dom_document_create_attribute_ns(string namespaceURI, string qualifiedName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrAttrNS
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_document_create_attribute_ns)
+{
+ zval *id, *rv = NULL;
+ xmlDocPtr docp;
+ xmlNodePtr nodep = NULL;
+ xmlNsPtr nsptr;
+ int ret, uri_len = 0, name_len = 0;
+ char *uri, *name;
+ xmlChar *localname = NULL;
+ int errorcode;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ nsptr = dom_get_ns(uri, name, uri_len, name_len, &errorcode, (char **) &localname);
+ if (errorcode == 0) {
+ if (nsptr != NULL) {
+ nodep = (xmlNodePtr) xmlNewDocProp(docp, localname, NULL);
+ dom_set_old_ns(docp, nsptr);
+ if (nodep != NULL) {
+ xmlSetNs(nodep, nsptr);
+ }
+ } else {
+ nodep = (xmlNodePtr) xmlNewDocProp(docp, name, NULL);
+ }
+ }
+ if (localname != NULL) {
+ xmlFree(localname);
+ }
+
+ if (errorcode != 0) {
+ php_dom_throw_error(errorcode, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ RETURN_FALSE;
+ }
+
+ if (nodep == NULL) {
+ RETURN_FALSE;
+ }
+
+ dom_add_to_list(nodep, docp TSRMLS_CC);
+ DOM_RET_OBJ(rv, nodep, &ret);
+}
+/* }}} end dom_document_create_attribute_ns */
+
+
+/* {{{ proto domnodelist dom_document_get_elements_by_tag_name_ns(string namespaceURI, string localName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBTNNS
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns)
+{
+ zval *id;
+ xmlDocPtr docp;
+ xmlNodePtr elemp;
+ int uri_len, name_len;
+ char *uri, *name;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ array_init(return_value);
+ elemp = xmlDocGetRootElement(docp);
+
+ dom_get_elements_by_tag_name_ns_raw(elemp, uri, name, &return_value TSRMLS_CC);
+}
+/* }}} end dom_document_get_elements_by_tag_name_ns */
+
+
+/* {{{ proto domelement dom_document_get_element_by_id(string elementId);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBId
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_document_get_element_by_id)
+{
+ zval *id, *rv = NULL;
+ xmlDocPtr docp;
+ idsIterator iter;
+ xmlHashTable *ids = NULL;
+ int ret,idname_len;
+ char *idname;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &idname, &idname_len) == FAILURE) {
+ return;
+ }
+
+ ids = (xmlHashTable *) docp->ids;
+ if (ids) {
+ iter.elementId = (xmlChar *) idname;
+ iter.element = NULL;
+ xmlHashScan(ids, (void *)idsHashScanner, &iter);
+ DOM_RET_OBJ(rv, (xmlNodePtr) iter.element, &ret);
+ } else {
+ RETVAL_NULL();
+ }
+}
+/* }}} end dom_document_get_element_by_id */
+
+
+/* {{{ proto domnode dom_document_adopt_node(node source);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-adoptNode
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_document_adopt_node)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_document_adopt_node */
+
+
+/* {{{ proto dom_void dom_document_normalize_document();
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-normalizeDocument
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_document_normalize_document)
+{
+ zval *id;
+ xmlDocPtr docp;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ DOM_NO_ARGS();
+
+ dom_normalize((xmlNodePtr) docp TSRMLS_CC);
+}
+/* }}} end dom_document_normalize_document */
+
+
+/* {{{ proto domnode dom_document_rename_node(node n, string namespaceURI, string qualifiedName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-renameNode
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_document_rename_node)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_document_rename_node */
+
+/* {{{ proto domnode dom_document_document([string version], [string encoding]); */
+PHP_FUNCTION(dom_document_document)
+{
+
+ zval *id;
+ xmlDoc *docp = NULL, *olddoc;
+ dom_object *intern;
+ char *encoding, *version = NULL;
+ int encoding_len, version_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &version, &version_len, &encoding, &encoding_len) == FAILURE) {
+ return;
+ }
+
+ docp = xmlNewDoc(version);
+ if (!docp)
+ RETURN_FALSE;
+
+ if (encoding_len > 0) {
+ docp->encoding = (const xmlChar*)xmlStrdup(encoding);
+ }
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ olddoc = (xmlDocPtr)intern->ptr;
+ if (olddoc != NULL) {
+ node_free_resource((xmlNode *) olddoc TSRMLS_CC);
+ }
+ php_dom_set_object(id, docp TSRMLS_CC);
+ }
+
+}
+/* }}} end dom_document_document */
+
+/* {{{ proto boolean domnode dom_document_load(string source);
+URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_document_load)
+{
+ zval *id;
+ xmlDoc *docp = NULL, *newdoc;
+ dom_object *intern;
+ char *source;
+ int source_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ return;
+ }
+
+ newdoc = docp = xmlParseFile(source);
+
+ if (!newdoc)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ docp = (xmlDocPtr)intern->ptr;
+ if (docp != NULL) {
+ node_free_resource((xmlNode *) docp TSRMLS_CC);
+ }
+ }
+
+ php_dom_set_object(id, newdoc TSRMLS_CC);
+
+ RETURN_TRUE;
+}
+/* }}} end dom_document_load */
+
+/* {{{ proto boolean domnode dom_document_loadxml(string source);
+URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-loadXML
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_document_loadxml)
+{
+ zval *id;
+ xmlDoc *docp = NULL, *newdoc;
+ dom_object *intern;
+ char *buffer;
+ int buffer_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) {
+ return;
+ }
+
+ newdoc = xmlParseDoc(buffer);
+ if (!newdoc)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ docp = (xmlDocPtr)intern->ptr;
+ if (docp != NULL) {
+ node_free_resource((xmlNode *) docp TSRMLS_CC);
+ }
+ }
+
+ php_dom_set_object(id, newdoc TSRMLS_CC);
+
+ RETURN_TRUE;
+}
+/* }}} end dom_document_loadxml */
+
+/* {{{ proto long domnode dom_document_save(string file);
+Convenience method to save to file
+*/
+PHP_FUNCTION(dom_document_save)
+{
+ zval *id;
+ xmlDoc *docp;
+ int file_len, bytes;
+ char *file;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ return;
+ }
+
+ if ((PG(safe_mode) && (!php_checkuid(file, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(file TSRMLS_CC)) {
+ RETURN_FALSE;
+ }
+
+ bytes = xmlSaveFile(file, docp);
+
+ if (bytes == -1) {
+ RETURN_FALSE;
+ }
+ RETURN_LONG(bytes);
+}
+/* }}} end dom_document_save */
+
+/* {{{ proto string domnode dom_document_savexml([node n]);
+URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-saveXML
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_document_savexml)
+{
+ zval *id, *nodep = NULL;
+ xmlDoc *docp;
+ xmlNode *node;
+ xmlBufferPtr buf;
+ xmlChar *mem;
+ int size;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|o", &nodep) == FAILURE) {
+ return;
+ }
+
+ if (nodep != NULL) {
+ /* Dump contents of Node */
+ DOM_GET_OBJ(node, nodep, xmlNodePtr);
+ if (node->doc != docp) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Node not from same document");
+ RETURN_FALSE;
+ }
+ buf = xmlBufferCreate();
+ if (!buf) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch buffer");
+ RETURN_FALSE;
+ }
+ xmlNodeDump(buf, docp, node, 0, 0);
+ mem = (xmlChar*) xmlBufferContent(buf);
+ if (!mem) {
+ xmlBufferFree(buf);
+ RETURN_FALSE;
+ }
+ RETVAL_STRING(mem, 1);
+ xmlBufferFree(buf);
+ } else {
+ /* Dump Document Contents
+ Encoding is handled from the encoding property set on the document */
+ xmlDocDumpMemory(docp, &mem, &size);
+ if (!size) {
+ RETURN_FALSE;
+ }
+ RETVAL_STRINGL(mem, size, 1);
+ xmlFree(mem);
+ }
+}
+/* }}} end dom_document_savexml */
diff --git a/ext/dom/documentfragment.c b/ext/dom/documentfragment.c
new file mode 100644
index 0000000000..e9039d9385
--- /dev/null
+++ b/ext/dom/documentfragment.c
@@ -0,0 +1,66 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domdocumentfragment extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-B63ED1A3
+* Since:
+*/
+
+zend_function_entry php_dom_documentfragment_class_functions[] = {
+ PHP_FALIAS(domdocumentfragment, dom_documentfragment_documentfragment, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto dom_documentfragment_documentfragment(); */
+PHP_FUNCTION(dom_documentfragment_documentfragment)
+{
+
+ zval *id;
+ xmlNodePtr nodep = NULL, oldnode = NULL;
+ dom_object *intern;
+
+ id = getThis();
+
+ nodep = xmlNewDocFragment(NULL);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, nodep TSRMLS_CC);
+ }
+}
+/* }}} end dom_documentfragment_documentfragment */
diff --git a/ext/dom/documenttype.c b/ext/dom/documenttype.c
new file mode 100644
index 0000000000..a3715b85d5
--- /dev/null
+++ b/ext/dom/documenttype.c
@@ -0,0 +1,267 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+typedef struct _nodeIterator nodeIterator;
+struct _nodeIterator {
+ int cur;
+ int index;
+ xmlNode *node;
+};
+
+static void itemHashScanner (void *payload, void *data, xmlChar *name) {
+ nodeIterator *priv = (nodeIterator *)data;
+
+ if(priv->cur < priv->index) {
+ priv->cur++;
+ } else {
+ if(priv->node == NULL) {
+ priv->node = (xmlNode *)payload;
+ }
+ }
+}
+
+/*
+* class domdocumenttype extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-412266927
+* Since:
+*/
+
+zend_function_entry php_dom_documenttype_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto name string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1844763134
+Since:
+*/
+int dom_documenttype_name_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDtdPtr dtdptr;
+
+ dtdptr = obj->ptr;
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, (char *) (dtdptr->name), 1);
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto entities namednodemap
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1788794630
+Since:
+*/
+int dom_documenttype_entities_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDtdPtr doctypep;
+ xmlHashTable *entityht;
+ nodeIterator *iter;
+ xmlNode *nodep = NULL;
+ int ret, htsize, index = 0;
+
+ doctypep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ array_init(*retval);
+
+ entityht = (xmlHashTable *) doctypep->entities;
+ if (entityht) {
+ if ((htsize = xmlHashSize(entityht)) > 0) {
+ iter = emalloc(sizeof(nodeIterator));
+ while (index < htsize) {
+ iter->cur = 0;
+ iter->index = index;
+ iter->node = NULL;
+ xmlHashScan(entityht, itemHashScanner, iter);
+ index++;
+ nodep = iter->node;
+ if (nodep != NULL) {
+ zval *child = NULL;
+ zval *wrapper;
+ wrapper = dom_object_get_data(nodep);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(child);
+ }
+ child = php_dom_create_object(nodep, &ret, wrapper, child TSRMLS_CC);
+ add_assoc_zval(*retval, (char *) nodep->name, child);
+ }
+ }
+ efree(iter);
+ }
+ }
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto notations namednodemap
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D46829EF
+Since:
+*/
+int dom_documenttype_notations_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDtdPtr doctypep;
+ xmlHashTable *notationht;
+ nodeIterator *iter;
+ xmlNode *nodep = NULL;
+ int ret, htsize, index = 0;
+
+ doctypep = obj->ptr;
+
+ MAKE_STD_ZVAL(*retval);
+ array_init(*retval);
+
+ notationht = (xmlHashTable *) doctypep->notations;
+ if (notationht) {
+ if ((htsize = xmlHashSize(notationht)) > 0) {
+ iter = emalloc(sizeof(nodeIterator));
+ while (index < htsize) {
+ iter->cur = 0;
+ iter->index = index;
+ iter->node = NULL;
+ xmlHashScan(notationht, itemHashScanner, iter);
+ index++;
+ nodep = iter->node;
+ if (nodep != NULL) {
+ zval *child = NULL;
+ zval *wrapper;
+ wrapper = dom_object_get_data(nodep);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(child);
+ }
+ child = php_dom_create_object(nodep, &ret, wrapper, child TSRMLS_CC);
+ add_assoc_zval(*retval, (char *) nodep->name, child);
+ }
+ }
+ efree(iter);
+ }
+ }
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto public_id string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-publicId
+Since: DOM Level 2
+*/
+int dom_documenttype_public_id_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDtdPtr dtdptr;
+
+ dtdptr = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ if (dtdptr->ExternalID) {
+ ZVAL_STRING(*retval, (char *) (dtdptr->ExternalID), 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+ return SUCCESS;
+
+}
+
+/* }}} */
+
+
+
+/* {{{ proto system_id string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-systemId
+Since: DOM Level 2
+*/
+int dom_documenttype_system_id_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlDtdPtr dtdptr;
+
+ dtdptr = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ if (dtdptr->SystemID) {
+ ZVAL_STRING(*retval, (char *) (dtdptr->ExternalID), 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto internal_subset string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-internalSubset
+Since: DOM Level 2
+*/
+int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+
+ xmlDtdPtr dtdptr;
+ xmlDtd *intsubset;
+ xmlOutputBuffer *buff = NULL;
+ xmlChar *strintsubset;
+
+ dtdptr = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+ if (dtdptr->doc != NULL && ((intsubset = dtdptr->doc->intSubset) != NULL)) {
+ buff = xmlAllocOutputBuffer(NULL);
+ if (buff != NULL) {
+ xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
+ xmlOutputBufferFlush(buff);
+ strintsubset = xmlStrndup(buff->buffer->content, buff->buffer->use);
+ (void)xmlOutputBufferClose(buff);
+ ZVAL_STRING(*retval, (char *) strintsubset, 1);
+ return SUCCESS;
+ }
+ }
+
+ ZVAL_EMPTY_STRING(*retval);
+
+ return SUCCESS;
+
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/dom.dsp b/ext/dom/dom.dsp
new file mode 100644
index 0000000000..707da9e95e
--- /dev/null
+++ b/ext/dom/dom.dsp
@@ -0,0 +1,246 @@
+# Microsoft Developer Studio Project File - Name="dom" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=dom - Win32 Release_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "dom.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "dom.mak" CFG="dom - Win32 Release_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "dom - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "dom - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "dom - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_DOM" /D ZTS=1 /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DOM_EXPORTS" /D "COMPILE_DL_DOM" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DOM=1 /D HAVE_DOMXSLT=1 /D LIBXML_STATIC=1 /D LIBXSLT_STATIC=1 /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x406 /d "NDEBUG"
+# ADD RSC /l 0x406 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386
+# ADD LINK32 wsock32.lib php4ts.lib libxml2_a.lib libxslt_a.lib iconv.lib resolv.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_dom.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\bindlib_w32\Release" /libpath:"..\..\..\php_build\lib\libxslt"
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF "$(CFG)" == "dom - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "mssql-70" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_DOM" /D ZTS=1 /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DOM_EXPORTS" /D "COMPILE_DL_DOM" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DOM=1 /D LIBXML_STATIC=1 /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x406 /d "NDEBUG"
+# ADD RSC /l 0x406 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386
+# ADD LINK32 php4ts_debug.lib ws2_32.lib libxml2_a.lib iconv.lib resolv.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /nodefaultlib:"msvcrt" /out:"..\..\Debug_TS/php_dom.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\bindlib_w32\Release" /libpath:"..\..\..\php_build\lib\libxslt"
+
+!ENDIF
+
+# Begin Target
+
+# Name "dom - Win32 Release_TS"
+# Name "dom - Win32 Debug_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\attr.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\cdatasection.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\characterdata.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\comment.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\document.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\documentfragment.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\documenttype.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domconfiguration.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domerrorhandler.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domexception.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domimplementation.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domimplementationlist.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domimplementationsource.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domlocator.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\domstringlist.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\element.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\entity.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\entityreference.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\namednodemap.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\namelist.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\node.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\nodelist.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\notation.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\php_dom.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\processinginstruction.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\string_extend.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\text.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\typeinfo.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\userdatahandler.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\dom_ce.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dom_fe.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dom_properties.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\php_dom.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\xml_common.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/ext/dom/dom_ce.h b/ext/dom/dom_ce.h
new file mode 100644
index 0000000000..0089086639
--- /dev/null
+++ b/ext/dom/dom_ce.h
@@ -0,0 +1,54 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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$ */
+#ifndef DOM_CE_H
+#define DOM_CE_H
+
+zend_class_entry *dom_domexception_class_entry;
+zend_class_entry *dom_domstringlist_class_entry;
+zend_class_entry *dom_namelist_class_entry;
+zend_class_entry *dom_domimplementationlist_class_entry;
+zend_class_entry *dom_domimplementationsource_class_entry;
+zend_class_entry *dom_domimplementation_class_entry;
+zend_class_entry *dom_documentfragment_class_entry;
+zend_class_entry *dom_document_class_entry;
+zend_class_entry *dom_node_class_entry;
+zend_class_entry *dom_nodelist_class_entry;
+zend_class_entry *dom_namednodemap_class_entry;
+zend_class_entry *dom_characterdata_class_entry;
+zend_class_entry *dom_attr_class_entry;
+zend_class_entry *dom_element_class_entry;
+zend_class_entry *dom_text_class_entry;
+zend_class_entry *dom_comment_class_entry;
+zend_class_entry *dom_typeinfo_class_entry;
+zend_class_entry *dom_userdatahandler_class_entry;
+zend_class_entry *dom_domerror_class_entry;
+zend_class_entry *dom_domerrorhandler_class_entry;
+zend_class_entry *dom_domlocator_class_entry;
+zend_class_entry *dom_domconfiguration_class_entry;
+zend_class_entry *dom_cdatasection_class_entry;
+zend_class_entry *dom_documenttype_class_entry;
+zend_class_entry *dom_notation_class_entry;
+zend_class_entry *dom_entity_class_entry;
+zend_class_entry *dom_entityreference_class_entry;
+zend_class_entry *dom_processinginstruction_class_entry;
+zend_class_entry *dom_string_extend_class_entry;
+
+#endif /* DOM_CE_H */
diff --git a/ext/dom/dom_fe.h b/ext/dom/dom_fe.h
new file mode 100644
index 0000000000..d001bbda7a
--- /dev/null
+++ b/ext/dom/dom_fe.h
@@ -0,0 +1,237 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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$ */
+#ifndef DOM_FE_H
+#define DOM_FE_H
+
+extern zend_function_entry php_dom_domexception_class_functions[];
+extern zend_function_entry php_dom_domstringlist_class_functions[];
+extern zend_function_entry php_dom_namelist_class_functions[];
+extern zend_function_entry php_dom_domimplementationlist_class_functions[];
+extern zend_function_entry php_dom_domimplementationsource_class_functions[];
+extern zend_function_entry php_dom_domimplementation_class_functions[];
+extern zend_function_entry php_dom_documentfragment_class_functions[];
+extern zend_function_entry php_dom_document_class_functions[];
+extern zend_function_entry php_dom_node_class_functions[];
+extern zend_function_entry php_dom_nodelist_class_functions[];
+extern zend_function_entry php_dom_namednodemap_class_functions[];
+extern zend_function_entry php_dom_characterdata_class_functions[];
+extern zend_function_entry php_dom_attr_class_functions[];
+extern zend_function_entry php_dom_element_class_functions[];
+extern zend_function_entry php_dom_text_class_functions[];
+extern zend_function_entry php_dom_comment_class_functions[];
+extern zend_function_entry php_dom_typeinfo_class_functions[];
+extern zend_function_entry php_dom_userdatahandler_class_functions[];
+extern zend_function_entry php_dom_domerror_class_functions[];
+extern zend_function_entry php_dom_domerrorhandler_class_functions[];
+extern zend_function_entry php_dom_domlocator_class_functions[];
+extern zend_function_entry php_dom_domconfiguration_class_functions[];
+extern zend_function_entry php_dom_cdatasection_class_functions[];
+extern zend_function_entry php_dom_documenttype_class_functions[];
+extern zend_function_entry php_dom_notation_class_functions[];
+extern zend_function_entry php_dom_entity_class_functions[];
+extern zend_function_entry php_dom_entityreference_class_functions[];
+extern zend_function_entry php_dom_processinginstruction_class_functions[];
+extern zend_function_entry php_dom_string_extend_class_functions[];
+
+/* domexception errors */
+typedef enum {
+ INDEX_SIZE_ERR = 1,
+ DOMSTRING_SIZE_ERR = 2,
+ HIERARCHY_REQUEST_ERR = 3,
+ WRONG_DOCUMENT_ERR = 4,
+ INVALID_CHARACTER_ERR = 5,
+ NO_DATA_ALLOWED_ERR = 6,
+ NO_MODIFICATION_ALLOWED_ERR = 7,
+ NOT_FOUND_ERR = 8,
+ NOT_SUPPORTED_ERR = 9,
+ INUSE_ATTRIBUTE_ERR = 10,
+// Introduced in DOM Level 2:
+ INVALID_STATE_ERR = 11,
+// Introduced in DOM Level 2:
+ SYNTAX_ERR = 12,
+// Introduced in DOM Level 2:
+ INVALID_MODIFICATION_ERR = 13,
+// Introduced in DOM Level 2:
+ NAMESPACE_ERR = 14,
+// Introduced in DOM Level 2:
+ INVALID_ACCESS_ERR = 15,
+// Introduced in DOM Level 3:
+ VALIDATION_ERR = 16
+} dom_exception_code;
+
+/* domstringlist methods */
+PHP_FUNCTION(dom_domstringlist_item);
+
+/* domnamelist methods */
+PHP_FUNCTION(dom_namelist_get_name);
+PHP_FUNCTION(dom_namelist_get_namespace_uri);
+
+/* domimplementationlist methods */
+PHP_FUNCTION(dom_domimplementationlist_item);
+
+/* domimplementationsource methods */
+PHP_FUNCTION(dom_domimplementationsource_get_domimplementation);
+PHP_FUNCTION(dom_domimplementationsource_get_domimplementations);
+
+/* domimplementation methods */
+PHP_FUNCTION(dom_domimplementation_has_feature);
+PHP_FUNCTION(dom_domimplementation_create_document_type);
+PHP_FUNCTION(dom_domimplementation_create_document);
+PHP_FUNCTION(dom_domimplementation_get_feature);
+
+/* domdocumentfragment methods */
+PHP_FUNCTION(dom_documentfragment_documentfragment);
+
+/* domdocument methods */
+PHP_FUNCTION(dom_document_create_element);
+PHP_FUNCTION(dom_document_create_document_fragment);
+PHP_FUNCTION(dom_document_create_text_node);
+PHP_FUNCTION(dom_document_create_comment);
+PHP_FUNCTION(dom_document_create_cdatasection);
+PHP_FUNCTION(dom_document_create_processing_instruction);
+PHP_FUNCTION(dom_document_create_attribute);
+PHP_FUNCTION(dom_document_create_entity_reference);
+PHP_FUNCTION(dom_document_get_elements_by_tag_name);
+PHP_FUNCTION(dom_document_import_node);
+PHP_FUNCTION(dom_document_create_element_ns);
+PHP_FUNCTION(dom_document_create_attribute_ns);
+PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns);
+PHP_FUNCTION(dom_document_get_element_by_id);
+PHP_FUNCTION(dom_document_adopt_node);
+PHP_FUNCTION(dom_document_normalize_document);
+PHP_FUNCTION(dom_document_rename_node);
+PHP_FUNCTION(dom_document_document);
+ /* convienience methods */
+PHP_FUNCTION(dom_document_load);
+PHP_FUNCTION(dom_document_save);
+PHP_FUNCTION(dom_document_loadxml);
+PHP_FUNCTION(dom_document_savexml);
+
+/* domnode methods */
+PHP_FUNCTION(dom_node_insert_before);
+PHP_FUNCTION(dom_node_replace_child);
+PHP_FUNCTION(dom_node_remove_child);
+PHP_FUNCTION(dom_node_append_child);
+PHP_FUNCTION(dom_node_has_child_nodes);
+PHP_FUNCTION(dom_node_clone_node);
+PHP_FUNCTION(dom_node_normalize);
+PHP_FUNCTION(dom_node_is_supported);
+PHP_FUNCTION(dom_node_has_attributes);
+PHP_FUNCTION(dom_node_compare_document_position);
+PHP_FUNCTION(dom_node_is_same_node);
+PHP_FUNCTION(dom_node_lookup_prefix);
+PHP_FUNCTION(dom_node_is_default_namespace);
+PHP_FUNCTION(dom_node_lookup_namespace_uri);
+PHP_FUNCTION(dom_node_is_equal_node);
+PHP_FUNCTION(dom_node_get_feature);
+PHP_FUNCTION(dom_node_set_user_data);
+PHP_FUNCTION(dom_node_get_user_data);
+
+/* domnodelist methods */
+PHP_FUNCTION(dom_nodelist_item);
+
+/* domnamednodemap methods */
+PHP_FUNCTION(dom_namednodemap_get_named_item);
+PHP_FUNCTION(dom_namednodemap_set_named_item);
+PHP_FUNCTION(dom_namednodemap_remove_named_item);
+PHP_FUNCTION(dom_namednodemap_item);
+PHP_FUNCTION(dom_namednodemap_get_named_item_ns);
+PHP_FUNCTION(dom_namednodemap_set_named_item_ns);
+PHP_FUNCTION(dom_namednodemap_remove_named_item_ns);
+
+/* domcharacterdata methods */
+PHP_FUNCTION(dom_characterdata_substring_data);
+PHP_FUNCTION(dom_characterdata_append_data);
+PHP_FUNCTION(dom_characterdata_insert_data);
+PHP_FUNCTION(dom_characterdata_delete_data);
+PHP_FUNCTION(dom_characterdata_replace_data);
+
+/* domattr methods */
+PHP_FUNCTION(dom_attr_is_id);
+PHP_FUNCTION(dom_attr_attr);
+
+/* domelement methods */
+PHP_FUNCTION(dom_element_get_attribute);
+PHP_FUNCTION(dom_element_set_attribute);
+PHP_FUNCTION(dom_element_remove_attribute);
+PHP_FUNCTION(dom_element_get_attribute_node);
+PHP_FUNCTION(dom_element_set_attribute_node);
+PHP_FUNCTION(dom_element_remove_attribute_node);
+PHP_FUNCTION(dom_element_get_elements_by_tag_name);
+PHP_FUNCTION(dom_element_get_attribute_ns);
+PHP_FUNCTION(dom_element_set_attribute_ns);
+PHP_FUNCTION(dom_element_remove_attribute_ns);
+PHP_FUNCTION(dom_element_get_attribute_node_ns);
+PHP_FUNCTION(dom_element_set_attribute_node_ns);
+PHP_FUNCTION(dom_element_get_elements_by_tag_name_ns);
+PHP_FUNCTION(dom_element_has_attribute);
+PHP_FUNCTION(dom_element_has_attribute_ns);
+PHP_FUNCTION(dom_element_set_id_attribute);
+PHP_FUNCTION(dom_element_set_id_attribute_ns);
+PHP_FUNCTION(dom_element_set_id_attribute_node);
+PHP_FUNCTION(dom_element_element);
+
+/* domtext methods */
+PHP_FUNCTION(dom_text_split_text);
+PHP_FUNCTION(dom_text_is_whitespace_in_element_content);
+PHP_FUNCTION(dom_text_replace_whole_text);
+PHP_FUNCTION(dom_text_text);
+
+/* domcomment methods */
+PHP_FUNCTION(dom_comment_comment);
+
+/* domtypeinfo methods */
+
+/* domuserdatahandler methods */
+PHP_FUNCTION(dom_userdatahandler_handle);
+
+/* domdomerror methods */
+
+/* domerrorhandler methods */
+PHP_FUNCTION(dom_domerrorhandler_handle_error);
+
+/* domlocator methods */
+
+/* domconfiguration methods */
+PHP_FUNCTION(dom_domconfiguration_set_parameter);
+PHP_FUNCTION(dom_domconfiguration_get_parameter);
+PHP_FUNCTION(dom_domconfiguration_can_set_parameter);
+
+/* domcdatasection methods */
+PHP_FUNCTION(dom_cdatasection_cdatasection);
+
+/* domdocumenttype methods */
+
+/* domnotation methods */
+
+/* domentity methods */
+
+/* domentityreference methods */
+PHP_FUNCTION(dom_entityreference_entityreference);
+
+/* domprocessinginstruction methods */
+PHP_FUNCTION(dom_processinginstruction_processinginstruction);
+
+/* string_extend methods */
+PHP_FUNCTION(dom_string_extend_find_offset16);
+PHP_FUNCTION(dom_string_extend_find_offset32);
+
+#endif /* DOM_FE_H */
diff --git a/ext/dom/dom_properties.h b/ext/dom/dom_properties.h
new file mode 100644
index 0000000000..9ac2702660
--- /dev/null
+++ b/ext/dom/dom_properties.h
@@ -0,0 +1,145 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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$ */
+#ifndef DOM_PROPERTIES_H
+#define DOM_PROPERTIES_H
+
+/* attr properties */
+int dom_attr_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_attr_specified_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_attr_value_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_attr_value_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_attr_owner_element_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_attr_schema_type_info_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* characterdata properties */
+int dom_characterdata_data_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_characterdata_data_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_characterdata_length_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* document properties */
+int dom_document_doctype_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_implementation_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_document_element_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_actual_encoding_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_actual_encoding_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_encoding_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_standalone_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_standalone_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_version_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_strict_error_checking_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_strict_error_checking_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_document_uri_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_config_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* documenttype properties */
+int dom_documenttype_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_documenttype_entities_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_documenttype_notations_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_documenttype_public_id_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_documenttype_system_id_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* domerror properties */
+int dom_domerror_severity_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domerror_message_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domerror_type_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domerror_related_exception_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domerror_related_data_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domerror_location_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* domimplementationlist properties */
+int dom_domimplementationlist_length_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* domlocator properties */
+int dom_domlocator_line_number_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domlocator_column_number_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domlocator_offset_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domlocator_related_node_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_domlocator_uri_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* domstringlist properties */
+int dom_domstringlist_length_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* element properties */
+int dom_element_tag_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_element_schema_type_info_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* entity properties */
+int dom_entity_public_id_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_entity_system_id_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_entity_notation_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_entity_actual_encoding_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_entity_actual_encoding_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_entity_encoding_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_entity_encoding_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_entity_version_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_entity_version_write(dom_object *obj, zval *newval TSRMLS_DC);
+
+/* namednodemap properties */
+int dom_namednodemap_length_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* namelist properties */
+int dom_namelist_length_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* node properties */
+int dom_node_node_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_node_value_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_node_value_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_node_node_type_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_parent_node_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_child_nodes_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_first_child_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_last_child_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_previous_sibling_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_next_sibling_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_attributes_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_owner_document_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_namespace_uri_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_prefix_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_prefix_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_node_local_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_base_uri_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_text_content_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_node_text_content_write(dom_object *obj, zval *newval TSRMLS_DC);
+
+/* nodelist properties */
+int dom_nodelist_length_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* notation properties */
+int dom_notation_public_id_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_notation_system_id_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* processinginstruction properties */
+int dom_processinginstruction_target_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_processinginstruction_data_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_processinginstruction_data_write(dom_object *obj, zval *newval TSRMLS_DC);
+
+/* text properties */
+int dom_text_whole_text_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+/* typeinfo properties */
+int dom_typeinfo_type_name_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_typeinfo_type_namespace_read(dom_object *obj, zval **retval TSRMLS_DC);
+
+#endif /* DOM_PROPERTIERS_H */
diff --git a/ext/dom/domconfiguration.c b/ext/dom/domconfiguration.c
new file mode 100644
index 0000000000..0456e25620
--- /dev/null
+++ b/ext/dom/domconfiguration.c
@@ -0,0 +1,77 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domdomconfiguration
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMConfiguration
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domconfiguration_class_functions[] = {
+ PHP_FALIAS(setParameter, dom_domconfiguration_set_parameter, NULL)
+ PHP_FALIAS(getParameter, dom_domconfiguration_get_parameter, NULL)
+ PHP_FALIAS(canSetParameter, dom_domconfiguration_can_set_parameter, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+
+/* {{{ proto dom_void dom_domconfiguration_set_parameter(string name, domuserdata value);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMConfiguration-property
+Since:
+*/
+PHP_FUNCTION(dom_domconfiguration_set_parameter)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domconfiguration_set_parameter */
+
+
+/* {{{ proto domdomuserdata dom_domconfiguration_get_parameter(string name);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMConfiguration-getParameter
+Since:
+*/
+PHP_FUNCTION(dom_domconfiguration_get_parameter)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domconfiguration_get_parameter */
+
+
+/* {{{ proto boolean dom_domconfiguration_can_set_parameter(string name, domuserdata value);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMConfiguration-canSetParameter
+Since:
+*/
+PHP_FUNCTION(dom_domconfiguration_can_set_parameter)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domconfiguration_can_set_parameter */
diff --git a/ext/dom/domerror.c b/ext/dom/domerror.c
new file mode 100644
index 0000000000..f73d486ff9
--- /dev/null
+++ b/ext/dom/domerror.c
@@ -0,0 +1,137 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domerror
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-Interfaces-DOMError
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domerror_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto severity unsigned short
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-DOMError-severity
+Since:
+*/
+int dom_domerror_severity_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto message string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-DOMError-message
+Since:
+*/
+int dom_domerror_message_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto type string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-DOMError-type
+Since:
+*/
+int dom_domerror_type_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto relatedException object
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-DOMError-relatedException
+Since:
+*/
+int dom_domerror_related_exception_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto relatedData domobject
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-DOMError-relatedData
+Since:
+*/
+int dom_domerror_related_data_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto location domlocator
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-DOMError-location
+Since:
+*/
+int dom_domerror_location_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/domerrorhandler.c b/ext/dom/domerrorhandler.c
new file mode 100644
index 0000000000..0186567b7b
--- /dev/null
+++ b/ext/dom/domerrorhandler.c
@@ -0,0 +1,53 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domerrorhandler
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ERROR-Interfaces-DOMErrorHandler
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domerrorhandler_class_functions[] = {
+ PHP_FALIAS(handleError, dom_domerrorhandler_handle_error, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+
+/* {{{ proto dom_boolean dom_domerrorhandler_handle_error(domerror error);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-ERRORS-DOMErrorHandler-handleError
+Since:
+*/
+PHP_FUNCTION(dom_domerrorhandler_handle_error)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domerrorhandler_handle_error */
diff --git a/ext/dom/domexception.c b/ext/dom/domexception.c
new file mode 100644
index 0000000000..4f62eaac66
--- /dev/null
+++ b/ext/dom/domexception.c
@@ -0,0 +1,112 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domexception
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-17189187
+* Since:
+*/
+
+extern zend_class_entry *dom_domexception_class_entry;
+
+zend_function_entry php_dom_domexception_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ php_dom_throw_error */
+void php_dom_throw_error(int error_code, zval **retval TSRMLS_DC)
+{
+ zval *dom_exception;
+ char *error_message;
+
+ ALLOC_ZVAL(dom_exception);
+ Z_TYPE_P(dom_exception) = IS_OBJECT;
+ object_init_ex(dom_exception, dom_domexception_class_entry);
+ dom_exception->refcount = 1;
+ dom_exception->is_ref = 1;
+ switch (error_code)
+ {
+ case INDEX_SIZE_ERR:
+ error_message = "Index Size Error";
+ break;
+ case DOMSTRING_SIZE_ERR:
+ error_message = "DOM String Size Error";
+ break;
+ case HIERARCHY_REQUEST_ERR:
+ error_message = "Hierarchy Request Error";
+ break;
+ case WRONG_DOCUMENT_ERR:
+ error_message = "Wrong Document Error";
+ break;
+ case INVALID_CHARACTER_ERR:
+ error_message = "Invalid Character Error";
+ break;
+ case NO_DATA_ALLOWED_ERR:
+ error_message = "No Data Allowed Error";
+ break;
+ case NO_MODIFICATION_ALLOWED_ERR:
+ error_message = "No Modification Allowed Error";
+ break;
+ case NOT_FOUND_ERR:
+ error_message = "Not Found Error";
+ break;
+ case NOT_SUPPORTED_ERR:
+ error_message = "Not Supported Error";
+ break;
+ case INUSE_ATTRIBUTE_ERR:
+ error_message = "Inuse Attribute Error";
+ break;
+ case INVALID_STATE_ERR:
+ error_message = "Invalid State Error";
+ break;
+ case SYNTAX_ERR:
+ error_message = "Syntax Error";
+ break;
+ case INVALID_MODIFICATION_ERR:
+ error_message = "Invalid Modification Error";
+ break;
+ case NAMESPACE_ERR:
+ error_message = "Namespace Error";
+ break;
+ case INVALID_ACCESS_ERR:
+ error_message = "Invalid Access Error";
+ break;
+ case VALIDATION_ERR:
+ error_message = "Validation Error";
+ break;
+ default:
+ error_message = "Unhandled Error";
+ }
+
+ add_property_long(dom_exception, "code", error_code);
+ add_property_stringl(dom_exception, "message", error_message, strlen(error_message), 1);
+ EG(exception) = dom_exception;
+}
+/* }}} end php_dom_throw_error */
diff --git a/ext/dom/domimplementation.c b/ext/dom/domimplementation.c
new file mode 100644
index 0000000000..6654d6d82e
--- /dev/null
+++ b/ext/dom/domimplementation.c
@@ -0,0 +1,244 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+/*
+* class domimplementation
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-102161490
+* Since:
+*/
+
+zend_function_entry php_dom_domimplementation_class_functions[] = {
+ PHP_FALIAS(hasFeature, dom_domimplementation_has_feature, NULL)
+ PHP_FALIAS(createDocumentType, dom_domimplementation_create_document_type, NULL)
+ PHP_FALIAS(createDocument, dom_domimplementation_create_document, NULL)
+ PHP_FALIAS(getFeature, dom_domimplementation_get_feature, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+
+/* {{{ proto boolean dom_domimplementation_has_feature(string feature, string version);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-5CED94D7
+Since:
+*/
+PHP_FUNCTION(dom_domimplementation_has_feature)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domimplementation_has_feature */
+
+
+/* {{{ proto domdocumenttype dom_domimplementation_create_document_type(string qualifiedName, string publicId, string systemId);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocType
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_domimplementation_create_document_type)
+{
+ zval *rv = NULL;
+ xmlDtd *doctype;
+ int ret, name_len, publicid_len, systemid_len;
+ char *name, *publicid, *systemid;
+ xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
+ xmlURIPtr uri;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &name, &name_len, &publicid, &publicid_len, &systemid, &systemid_len) == FAILURE) {
+ return;
+ }
+
+ if (name_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "qualifiedName is required");
+ RETURN_FALSE;
+ }
+
+ if (publicid_len > 0)
+ pch1 = publicid;
+ if (systemid_len > 0)
+ pch2 = systemid;
+
+ uri = xmlParseURI(name);
+ if (uri->opaque != NULL) {
+ localname = xmlStrdup(uri->opaque);
+ if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ xmlFreeURI(uri);
+ xmlFree(localname);
+ RETURN_FALSE;
+ }
+ } else {
+ localname = xmlStrdup(name);
+ }
+
+ /* TODO: Test that localname has no invalid chars
+ php_dom_throw_error(INVALID_CHARACTER_ERR, TSRMLS_CC);
+ */
+
+ xmlFreeURI(uri);
+
+ doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2);
+ xmlFree(localname);
+
+ DOM_RET_OBJ(rv, (xmlNodePtr) doctype, &ret);
+}
+/* }}} end dom_domimplementation_create_document_type */
+
+
+/* {{{ proto domdocument dom_domimplementation_create_document(string namespaceURI, string qualifiedName, documenttype doctype);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocument
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_domimplementation_create_document)
+{
+ zval *node = NULL, *rv = NULL;
+ xmlDoc *docp;
+ xmlNode *nodep;
+ xmlDtdPtr doctype = NULL, dtd = NULL;
+ xmlNsPtr nsptr = NULL;
+ int ret, uri_len = 0, name_len = 0;
+ char *uri, *name;
+ xmlChar *prefix = NULL, *localname = NULL;
+ xmlURIPtr uristruct;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sso", &uri, &uri_len, &name, &name_len, &node) == FAILURE) {
+ return;
+ }
+
+ if (doctype != NULL) {
+ DOM_GET_OBJ(doctype, node, xmlDtdPtr);
+ if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid DocumentType object");
+ RETURN_FALSE;
+ }
+ if (doctype->doc != NULL) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "DocumentType: Wrong Document");
+ RETURN_FALSE;
+ }
+ }
+
+ if (uri_len > 0 || name_len > 0 || doctype != NULL) {
+ if (name_len == 0 && uri_len > 0) {
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ }
+ if (name_len > 0) {
+ uristruct = xmlParseURI(name);
+ if (uristruct->opaque != NULL) {
+ prefix = xmlStrdup(uristruct->scheme);
+ localname = xmlStrdup(uristruct->opaque);
+ if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ xmlFreeURI(uristruct);
+ xmlFree(prefix);
+ xmlFree(localname);
+ RETURN_FALSE;
+ }
+ if (!strcmp (prefix, "xml") && strcmp(uri, XML_XML_NAMESPACE)) {
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ xmlFreeURI(uristruct);
+ xmlFree(prefix);
+ xmlFree(localname);
+ RETURN_FALSE;
+ }
+ } else {
+ localname = xmlStrdup(name);
+ }
+
+ /* TODO: Test that localname has no invalid chars
+ php_dom_throw_error(INVALID_CHARACTER_ERR, TSRMLS_CC);
+ */
+
+ xmlFreeURI(uristruct);
+
+ if (uri_len > 0) {
+ if (prefix == NULL) {
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ xmlFree(localname);
+ RETURN_FALSE;
+ } else {
+ if ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL) {
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ xmlFree(prefix);
+ xmlFree(localname);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ RETURN_FALSE;
+ }
+ }
+ }
+ if (prefix != NULL) {
+ xmlFree(prefix);
+ }
+ }
+ }
+
+ /* currently letting libxml2 set the version string */
+ docp = xmlNewDoc(NULL);
+ if (!docp) {
+ if (localname != NULL) {
+ xmlFree(localname);
+ }
+ RETURN_FALSE;
+ }
+
+ if (doctype != NULL) {
+ dtd = xmlCreateIntSubset (docp, doctype->name,
+ doctype->ExternalID, doctype->SystemID);
+ }
+
+ if (localname != NULL) {
+ nodep = xmlNewDocNode (docp, nsptr, localname, NULL);
+ if (!nodep) {
+ xmlFreeDoc(docp);
+ xmlFree(localname);
+ /* Need some type of error here */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error");
+ RETURN_FALSE;
+ }
+ xmlDocSetRootElement(docp, nodep);
+ xmlFree(localname);
+ }
+
+ DOM_RET_OBJ(rv, (xmlNodePtr) docp, &ret);
+}
+/* }}} end dom_domimplementation_create_document */
+
+
+/* {{{ proto domnode dom_domimplementation_get_feature(string feature, string version);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementation3-getFeature
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_domimplementation_get_feature)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domimplementation_get_feature */
diff --git a/ext/dom/domimplementationlist.c b/ext/dom/domimplementationlist.c
new file mode 100644
index 0000000000..45f86f47eb
--- /dev/null
+++ b/ext/dom/domimplementationlist.c
@@ -0,0 +1,69 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domimplementationlist
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementationList
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domimplementationlist_class_functions[] = {
+ PHP_FALIAS(item, dom_domimplementationlist_item, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto length unsigned long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementationList-length
+Since:
+*/
+int dom_domimplementationlist_length_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domdomimplementation dom_domimplementationlist_item(unsigned long index);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementationList-item
+Since:
+*/
+PHP_FUNCTION(dom_domimplementationlist_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domimplementationlist_item */
diff --git a/ext/dom/domimplementationsource.c b/ext/dom/domimplementationsource.c
new file mode 100644
index 0000000000..e0fcaffa32
--- /dev/null
+++ b/ext/dom/domimplementationsource.c
@@ -0,0 +1,65 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domimplementationsource
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementationSource
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domimplementationsource_class_functions[] = {
+ PHP_FALIAS(getDomimplementation, dom_domimplementationsource_get_domimplementation, NULL)
+ PHP_FALIAS(getDomimplementations, dom_domimplementationsource_get_domimplementations, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+
+/* {{{ proto domdomimplementation dom_domimplementationsource_get_domimplementation(string features);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-getDOMImpl
+Since:
+*/
+PHP_FUNCTION(dom_domimplementationsource_get_domimplementation)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domimplementationsource_get_domimplementation */
+
+
+/* {{{ proto domimplementationlist dom_domimplementationsource_get_domimplementations(string features);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-getDOMImpls
+Since:
+*/
+PHP_FUNCTION(dom_domimplementationsource_get_domimplementations)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domimplementationsource_get_domimplementations */
diff --git a/ext/dom/domlocator.c b/ext/dom/domlocator.c
new file mode 100644
index 0000000000..d1d778d132
--- /dev/null
+++ b/ext/dom/domlocator.c
@@ -0,0 +1,121 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domlocator
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Interfaces-DOMLocator
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domlocator_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto line_number long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMLocator-line-number
+Since:
+*/
+int dom_domlocator_line_number_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto column_number long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMLocator-column-number
+Since:
+*/
+int dom_domlocator_column_number_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto offset long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMLocator-offset
+Since:
+*/
+int dom_domlocator_offset_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto related_node node
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMLocator-node
+Since:
+*/
+int dom_domlocator_related_node_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto uri string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMLocator-uri
+Since:
+*/
+int dom_domlocator_uri_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/domstringlist.c b/ext/dom/domstringlist.c
new file mode 100644
index 0000000000..b1079ea117
--- /dev/null
+++ b/ext/dom/domstringlist.c
@@ -0,0 +1,69 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domstringlist
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMStringList
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_domstringlist_class_functions[] = {
+ PHP_FALIAS(item, dom_domstringlist_item, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto length unsigned long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMStringList-length
+Since:
+*/
+int dom_domstringlist_length_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domstring dom_domstringlist_item(unsigned long index);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMStringList-item
+Since:
+*/
+PHP_FUNCTION(dom_domstringlist_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_domstringlist_item */
diff --git a/ext/dom/element.c b/ext/dom/element.c
new file mode 100644
index 0000000000..96ce2139d9
--- /dev/null
+++ b/ext/dom/element.c
@@ -0,0 +1,779 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domelement extends domnode
+*
+* 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)
+ PHP_FALIAS(domelement, dom_element_element, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto domnode dom_element_element(string name, [string value]); */
+PHP_FUNCTION(dom_element_element)
+{
+
+ zval *id;
+ xmlNodePtr nodep = NULL, oldnode = NULL;
+ dom_object *intern;
+ char *name, *value = NULL;
+ int name_len, value_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ if (name_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Element name is required");
+ RETURN_FALSE;
+ }
+
+ nodep = xmlNewNode(NULL, (xmlChar *) name);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ if (value_len > 0) {
+ xmlNodeSetContentLen(nodep, value, value_len);
+ }
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, nodep TSRMLS_CC);
+ }
+}
+/* }}} end dom_element_element */
+
+/* {{{ proto tagName string
+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;
+
+ nodep = obj->ptr;
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, (char *) (nodep->name), 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto schemaTypeInfo typeinfo
+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;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto domstring dom_element_get_attribute(string name);
+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;
+ char *name, *value;
+ int name_len;
+
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ value = xmlGetProp(nodep, name);
+ if (value == NULL) {
+ RETURN_EMPTY_STRING();
+ } else {
+ RETVAL_STRING(value, 1);
+ xmlFree(value);
+ }
+}
+/* }}} end dom_element_get_attribute */
+
+
+/* {{{ proto dom_void dom_element_set_attribute(string name, string value);
+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;
+ xmlAttr *attr;
+ int ret, name_len, value_len;
+ char *name, *value;
+
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ attr = xmlHasProp(nodep,name);
+ if (attr != NULL) {
+ node_list_unlink(attr->children TSRMLS_CC);
+ }
+ attr = xmlSetProp(nodep, name, value);
+ if (!attr) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such attribute '%s'", name);
+ RETURN_FALSE;
+ }
+
+ DOM_RET_OBJ(rv, (xmlNodePtr) attr, &ret);
+
+}
+/* }}} end dom_element_set_attribute */
+
+
+/* {{{ proto dom_void dom_element_remove_attribute(string name);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D6AC0F9
+Since:
+*/
+PHP_FUNCTION(dom_element_remove_attribute)
+{
+ zval *id;
+ xmlNode *nodep;
+ xmlAttr *attrp;
+ int name_len;
+ char *name;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ attrp = xmlHasProp(nodep,name);
+ if (attrp == NULL) {
+ RETURN_FALSE;
+ }
+
+ /* TODO: DTD defined attributes are handled special */
+ if (dom_object_get_data((xmlNodePtr) attrp) == NULL) {
+ node_list_unlink(attrp->children TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) attrp);
+ xmlFreeProp(attrp);
+ } else {
+ dom_add_to_list((xmlNodePtr) attrp, attrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) attrp);
+ }
+
+ RETURN_TRUE;
+}
+/* }}} end dom_element_remove_attribute */
+
+
+/* {{{ proto domattr dom_element_get_attribute_node(string name);
+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;
+ xmlNode *nodep;
+ xmlAttr *attrp;
+ int name_len, ret;
+ char *name;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ attrp = xmlHasProp(nodep,name);
+ if (attrp == NULL) {
+ RETURN_FALSE;
+ }
+ DOM_RET_OBJ(rv, (xmlNodePtr) attrp, &ret);
+}
+/* }}} end dom_element_get_attribute_node */
+
+
+/* {{{ proto domattr dom_element_set_attribute_node(attr newAttr);
+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)
+{
+ zval *id, *node, *oldzval, *rv = NULL;
+ xmlNode *nodep;
+ xmlAttr *attrp, *existattrp = NULL;
+ int ret;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(attrp, node, xmlAttrPtr);
+
+ if (attrp->type != XML_ATTRIBUTE_NODE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is required");
+ RETURN_FALSE;
+ }
+
+ existattrp = xmlHasProp(nodep,attrp->name);
+ if (existattrp != NULL) {
+ if ((oldzval = dom_object_get_data((xmlNodePtr) existattrp)) == NULL) {
+ dom_add_to_list((xmlNodePtr) existattrp, existattrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) existattrp);
+ } else {
+ if (oldzval == node) {
+ RETURN_NULL();
+ }
+ dom_add_to_list((xmlNodePtr) existattrp, existattrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) existattrp);
+ }
+ }
+
+ xmlAddChild(nodep, (xmlNodePtr) attrp);
+ dom_del_from_list((xmlNodePtr) attrp, attrp->doc TSRMLS_CC);
+
+ /* Returns old property if removed otherwise NULL */
+ if (existattrp != NULL) {
+ DOM_RET_OBJ(rv, (xmlNodePtr) existattrp, &ret);
+ } else {
+ RETVAL_NULL();
+ }
+
+}
+/* }}} end dom_element_set_attribute_node */
+
+
+/* {{{ proto domattr dom_element_remove_attribute_node(attr oldAttr);
+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)
+{
+ zval *id;
+ xmlNode *nodep;
+ xmlAttr *attrp;
+ int name_len;
+ char *name;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ attrp = xmlHasProp(nodep,name);
+ if (attrp == NULL) {
+ RETURN_FALSE;
+ }
+
+ /* Check for registered nodes within attributes tree when attribute is not referenced
+ Unlink dependant nodes and free attribute if not registered */
+ if (dom_object_get_data((xmlNodePtr) attrp) == NULL) {
+ node_list_unlink(attrp->children TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) attrp);
+ xmlFreeProp(attrp);
+ } else {
+ dom_add_to_list((xmlNodePtr) attrp, attrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) attrp);
+ }
+
+ RETURN_TRUE;
+
+}
+/* }}} end dom_element_remove_attribute_node */
+
+
+/* {{{ proto domnodelist dom_element_get_elements_by_tag_name(string name);
+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;
+ xmlXPathContextPtr ctxp;
+ xmlNodePtr nodep;
+ xmlDocPtr docp;
+ xmlXPathObjectPtr xpathobjp;
+ int name_len, ret;
+ char *str,*name;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ docp = nodep->doc;
+
+ ctxp = xmlXPathNewContext(docp);
+
+ ctxp->node = nodep;
+ str = (char*) emalloc((name_len+3) * sizeof(char)) ;
+ sprintf(str ,"//%s",name);
+
+ xpathobjp = xmlXPathEval(str, ctxp);
+ efree(str);
+
+ if (!xpathobjp) {
+ RETURN_FALSE;
+ }
+
+ if (xpathobjp->type == XPATH_NODESET) {
+ int i;
+ xmlNodeSetPtr nodesetp;
+
+ if (NULL == (nodesetp = xpathobjp->nodesetval)) {
+ xmlXPathFreeObject (xpathobjp);
+ xmlXPathFreeContext(ctxp);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+
+ for (i = 0; i < nodesetp->nodeNr; i++) {
+ xmlNodePtr node = nodesetp->nodeTab[i];
+ zval *child = NULL;
+ zval *wrapper;
+ wrapper = dom_object_get_data(node);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(child);
+ }
+
+ child = php_dom_create_object(node, &ret, wrapper, child TSRMLS_CC);
+ add_next_index_zval(return_value, child);
+ }
+ }
+
+ xmlXPathFreeObject(xpathobjp);
+ xmlXPathFreeContext(ctxp);
+}
+/* }}} end dom_element_get_elements_by_tag_name */
+
+
+/* {{{ proto domstring dom_element_get_attribute_ns(string namespaceURI, string localName);
+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;
+ int uri_len = 0, name_len = 0;
+ char *uri, *name, *strattr;
+
+ DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+ strattr = xmlGetNsProp(elemp, name, uri);
+
+ if (strattr != NULL) {
+ RETVAL_STRING(strattr, 1);
+ xmlFree(strattr);
+ } else {
+ if (xmlStrEqual(uri, DOM_XMLNS_NAMESPACE)) {
+ 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 */
+
+
+/* {{{ proto dom_void dom_element_set_attribute_ns(string namespaceURI, string qualifiedName, string value);
+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)
+{
+ zval *id, *rv = NULL;
+ xmlNodePtr elemp, nodep = NULL;
+ xmlNsPtr nsptr;
+ int ret, uri_len = 0, name_len = 0;
+ char *uri, *name;
+ xmlChar *localname = NULL;
+ int errorcode = 0;
+
+ DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+ nsptr = xmlSearchNsByHref (elemp->doc, elemp, uri);
+ if (nsptr == NULL) {
+ nsptr = dom_get_ns(uri, name, uri_len, name_len, &errorcode, (char **) &localname);
+ if (nsptr != NULL) {
+ dom_set_old_ns(elemp->doc, nsptr);
+ }
+ }
+ if (errorcode == 0) {
+ if (nsptr != NULL) {
+ nodep = (xmlNodePtr) xmlSetNsProp(elemp, nsptr, localname, NULL);
+ } else {
+ nodep = (xmlNodePtr) xmlSetProp(elemp, name, NULL);
+ }
+ }
+ if (localname != NULL) {
+ xmlFree(localname);
+ }
+
+ if (errorcode != 0) {
+ php_dom_throw_error(errorcode, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ RETURN_FALSE;
+ }
+
+ if (nodep == NULL) {
+ RETURN_FALSE;
+ }
+
+ DOM_RET_OBJ(rv, nodep, &ret);
+}
+/* }}} end dom_element_set_attribute_ns */
+
+
+/* {{{ proto dom_void dom_element_remove_attribute_ns(string namespaceURI, string localName);
+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;
+ int name_len, uri_len;
+ char *name, *uri;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ if (xmlStrEqual(uri, DOM_XMLNS_NAMESPACE)) {
+ DOM_NOT_IMPLEMENTED();
+ } else {
+ attrp = xmlHasNsProp(nodep, name, uri);
+ if (attrp == NULL) {
+ RETURN_FALSE;
+ }
+
+ if (dom_object_get_data((xmlNodePtr) attrp) == NULL) {
+ node_list_unlink(attrp->children TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) attrp);
+ xmlFreeProp(attrp);
+ } else {
+ dom_add_to_list((xmlNodePtr) attrp, attrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) attrp);
+ }
+ }
+
+ RETURN_TRUE;
+}
+/* }}} end dom_element_remove_attribute_ns */
+
+
+/* {{{ proto domattr dom_element_get_attribute_node_ns(string namespaceURI, string localName);
+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)
+{
+ zval *id;
+ xmlNodePtr elemp;
+ xmlNs *nsp;
+ int uri_len, name_len;
+ char *uri, *name, *value;
+
+ DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ value = xmlGetNsProp(elemp, name, uri);
+
+ if (value != NULL) {
+ RETVAL_STRING(value, 1);
+ xmlFree(value);
+ } else {
+ if (xmlStrEqual(name, DOM_XMLNS_NAMESPACE)) {
+ nsp = dom_get_nsdecl(elemp, name);
+ if (nsp != NULL) {
+ RETVAL_STRING((char *) nsp->href, 1);
+ } else {
+ RETVAL_EMPTY_STRING();
+ }
+ } else {
+ RETVAL_EMPTY_STRING();
+ }
+ }
+
+}
+/* }}} end dom_element_get_attribute_node_ns */
+
+
+/* {{{ proto domattr dom_element_set_attribute_node_ns(attr newAttr);
+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)
+{
+ zval *id, *node, *oldzval, *rv = NULL;
+ xmlNode *nodep;
+ xmlNs *nsp;
+ xmlAttr *attrp, *existattrp = NULL;
+ int ret;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(attrp, node, xmlAttrPtr);
+
+ if (attrp->type != XML_ATTRIBUTE_NODE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute node is required");
+ RETURN_FALSE;
+ }
+
+ nsp = attrp->ns;
+ if (nsp != NULL) {
+ existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name);
+ } else {
+ existattrp = xmlHasProp(nodep, attrp->name);
+ }
+
+ if (existattrp != NULL) {
+ if ((oldzval = dom_object_get_data((xmlNodePtr) existattrp)) == NULL) {
+ dom_add_to_list((xmlNodePtr) existattrp, existattrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) existattrp);
+ } else {
+ if (oldzval == node) {
+ RETURN_NULL();
+ }
+ dom_add_to_list((xmlNodePtr) existattrp, existattrp->doc TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) existattrp);
+ }
+ }
+
+ xmlAddChild(nodep, (xmlNodePtr) attrp);
+ if (existattrp == NULL) {
+ xmlReconciliateNs(nodep->doc, nodep);
+ }
+
+ dom_del_from_list((xmlNodePtr) attrp, attrp->doc TSRMLS_CC);
+
+ /* Returns old property if removed otherwise NULL */
+ if (existattrp != NULL) {
+ DOM_RET_OBJ(rv, (xmlNodePtr) existattrp, &ret);
+ } else {
+ RETVAL_NULL();
+ }
+
+}
+/* }}} end dom_element_set_attribute_node_ns */
+
+
+
+/* {{{ proto domnodelist dom_element_get_elements_by_tag_name_ns(string namespaceURI, string localName);
+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;
+ char *uri, *name;
+
+ DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ array_init(return_value);
+
+ dom_get_elements_by_tag_name_ns_raw(elemp->children, uri, name, &return_value TSRMLS_CC);
+}
+/* }}} 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;
+ char *name, *value;
+ int name_len;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ value = xmlGetProp(nodep, name);
+ if (value == NULL) {
+ RETURN_FALSE;
+ } else {
+ xmlFree(value);
+ 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;
+ int uri_len, name_len;
+ char *uri, *name, *value;
+
+ DOM_GET_THIS_OBJ(elemp, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ value = xmlGetNsProp(elemp, name, uri);
+
+ 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 */
+
+
+/* {{{ proto dom_void dom_element_set_id_attribute(string name, boolean isId);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttr
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_element_set_id_attribute)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_element_set_id_attribute */
+
+
+/* {{{ proto dom_void dom_element_set_id_attribute_ns(string namespaceURI, string localName, boolean isId);
+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)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_element_set_id_attribute_ns */
+
+
+/* {{{ proto dom_void dom_element_set_id_attribute_node(attr idAttr, boolean isId);
+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)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_element_set_id_attribute_node */
diff --git a/ext/dom/entity.c b/ext/dom/entity.c
new file mode 100644
index 0000000000..2b5051b85e
--- /dev/null
+++ b/ext/dom/entity.c
@@ -0,0 +1,180 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domentity extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-527DCFF2
+* Since:
+*/
+
+zend_function_entry php_dom_entity_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto public_id string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-D7303025
+Since:
+*/
+int dom_entity_public_id_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlEntity *nodep;
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
+ ZVAL_NULL(*retval);
+ } else {
+ ZVAL_STRING(*retval, (char *) (nodep->ExternalID), 1);
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto system_id string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-D7C29F3E
+Since:
+*/
+int dom_entity_system_id_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlEntity *nodep;
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
+ ZVAL_NULL(*retval);
+ } else {
+ ZVAL_STRING(*retval, (char *) (nodep->SystemID), 1);
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto notation_name string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-6ABAEB38
+Since:
+*/
+int dom_entity_notation_name_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlEntity *nodep;
+ char *content;
+
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
+ ZVAL_NULL(*retval);
+ } else {
+ content = xmlNodeGetContent((xmlNodePtr) nodep);
+ ZVAL_STRING(*retval, content, 1);
+ xmlFree(content);
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto actual_encoding string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-actualEncoding
+Since: DOM Level 3
+*/
+int dom_entity_actual_encoding_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+int dom_entity_actual_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto encoding string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-encoding
+Since: DOM Level 3
+*/
+int dom_entity_encoding_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+int dom_entity_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto version string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-version
+Since: DOM Level 3
+*/
+int dom_entity_version_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+int dom_entity_version_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ return SUCCESS;
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/entityreference.c b/ext/dom/entityreference.c
new file mode 100644
index 0000000000..d4927801ad
--- /dev/null
+++ b/ext/dom/entityreference.c
@@ -0,0 +1,78 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domentityreference extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-11C98490
+* Since:
+*/
+
+zend_function_entry php_dom_entityreference_class_functions[] = {
+ PHP_FALIAS(domentityreference, dom_entityreference_entityreference, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto domnode dom_entityreference_entityreference(string name); */
+PHP_FUNCTION(dom_entityreference_entityreference)
+{
+ zval *id;
+ xmlNode *node;
+ xmlNodePtr oldnode = NULL;
+ dom_object *intern;
+ char *name;
+ int name_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ return;
+ }
+
+ if (name_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entity Reference name is required");
+ RETURN_FALSE;
+ }
+
+ node = xmlNewReference(NULL, name);
+
+ if (!node)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, node TSRMLS_CC);
+ }
+}
+
+/* }}} end dom_entityreference_entityreference */
diff --git a/ext/dom/namednodemap.c b/ext/dom/namednodemap.c
new file mode 100644
index 0000000000..27aed13f4a
--- /dev/null
+++ b/ext/dom/namednodemap.c
@@ -0,0 +1,141 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domnamednodemap
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1780488922
+* Since:
+*/
+
+zend_function_entry php_dom_namednodemap_class_functions[] = {
+ PHP_FALIAS(getNamedItem, dom_namednodemap_get_named_item, NULL)
+ PHP_FALIAS(setNamedItem, dom_namednodemap_set_named_item, NULL)
+ PHP_FALIAS(removeNamedItem, dom_namednodemap_remove_named_item, NULL)
+ PHP_FALIAS(item, dom_namednodemap_item, NULL)
+ PHP_FALIAS(getNamedItemNS, dom_namednodemap_get_named_item_ns, NULL)
+ PHP_FALIAS(setNamedItemNS, dom_namednodemap_set_named_item_ns, NULL)
+ PHP_FALIAS(removeNamedItemNS, dom_namednodemap_remove_named_item_ns, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto length unsigned long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D0FB19E
+Since:
+*/
+int dom_namednodemap_length_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domnode dom_namednodemap_get_named_item(string name);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549
+Since:
+*/
+PHP_FUNCTION(dom_namednodemap_get_named_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_get_named_item */
+
+
+/* {{{ proto domnode dom_namednodemap_set_named_item(node arg);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1025163788
+Since:
+*/
+PHP_FUNCTION(dom_namednodemap_set_named_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_set_named_item */
+
+
+/* {{{ proto domnode dom_namednodemap_remove_named_item(string name);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D58B193
+Since:
+*/
+PHP_FUNCTION(dom_namednodemap_remove_named_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_remove_named_item */
+
+
+/* {{{ proto domnode dom_namednodemap_item(unsigned long index);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-349467F9
+Since:
+*/
+PHP_FUNCTION(dom_namednodemap_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_item */
+
+
+/* {{{ proto domnode dom_namednodemap_get_named_item_ns(string namespaceURI, string localName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getNamedItemNS
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_namednodemap_get_named_item_ns)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_get_named_item_ns */
+
+
+/* {{{ proto domnode dom_namednodemap_set_named_item_ns(node arg);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-setNamedItemNS
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_namednodemap_set_named_item_ns)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_set_named_item_ns */
+
+
+/* {{{ proto domnode dom_namednodemap_remove_named_item_ns(string namespaceURI, string localName);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-removeNamedItemNS
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namednodemap_remove_named_item_ns */
diff --git a/ext/dom/namelist.c b/ext/dom/namelist.c
new file mode 100644
index 0000000000..ece384c152
--- /dev/null
+++ b/ext/dom/namelist.c
@@ -0,0 +1,81 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domnamelist
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#NameList
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_namelist_class_functions[] = {
+ PHP_FALIAS(getName, dom_namelist_get_name, NULL)
+ PHP_FALIAS(getNamespaceURI, dom_namelist_get_namespace_uri, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto length unsigned long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#NameList-length
+Since:
+*/
+int dom_namelist_length_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domstring dom_namelist_get_name(unsigned long index);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#NameList-getName
+Since:
+*/
+PHP_FUNCTION(dom_namelist_get_name)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namelist_get_name */
+
+
+/* {{{ proto domstring dom_namelist_get_namespace_uri(unsigned long index);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#NameList-getNamespaceURI
+Since:
+*/
+PHP_FUNCTION(dom_namelist_get_namespace_uri)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_namelist_get_namespace_uri */
diff --git a/ext/dom/node.c b/ext/dom/node.c
new file mode 100644
index 0000000000..8b9ab306cf
--- /dev/null
+++ b/ext/dom/node.c
@@ -0,0 +1,1274 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#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;
+ char *str = NULL;
+
+ nodep = obj->ptr;
+
+ switch (nodep->type) {
+ case XML_ATTRIBUTE_NODE:
+ case XML_ELEMENT_NODE:
+ 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;
+ case XML_NAMESPACE_DECL:
+ if (nodep->ns != NULL) {
+ str = (char *) nodep->ns->prefix;
+ }
+ 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);
+ }
+
+ 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;
+
+ nodep = obj->ptr;
+/* TODO: Element node is invalid for this property -
+currently here as a convience method while developing */
+ 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;
+ default:
+ str = NULL;
+ break;
+ }
+
+ ALLOC_ZVAL(*retval);
+
+ if(str != NULL) {
+ ZVAL_STRING(*retval, str, 1);
+ xmlFree(str);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+
+ return SUCCESS;
+
+}
+
+int dom_node_node_value_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlNode *nodep;
+
+ nodep = obj->ptr;
+
+ switch (nodep->type) {
+ 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:
+ 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
+Since:
+*/
+int dom_node_node_type_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNode *nodep;
+
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ ZVAL_LONG(*retval, nodep->type);
+ 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)
+{
+ zval *wrapper;
+ xmlNode *nodep, *nodeparent;
+ int ret;
+
+ nodep = obj->ptr;
+
+ nodeparent = nodep->parent;
+ if (!nodeparent) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(nodeparent);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(nodeparent, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ 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)
+{
+ xmlNodePtr nodep, last;
+ int ret;
+ nodep = obj->ptr;
+
+ if ((nodep->type == XML_DOCUMENT_NODE) || (nodep->type == XML_HTML_DOCUMENT_NODE)) {
+ last = ((xmlDoc *) nodep)->children;
+ } else {
+ last = nodep->children;
+ }
+ MAKE_STD_ZVAL(*retval);
+ array_init(*retval);
+
+ if (last) {
+ while (last) {
+ zval *child = NULL;
+ zval *wrapper;
+ wrapper = dom_object_get_data(last);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(child);
+ }
+ child = php_dom_create_object(last, &ret, wrapper, child TSRMLS_CC);
+ add_next_index_zval(*retval, child);
+ last = last->next;
+ }
+ }
+ 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)
+{
+ zval *wrapper;
+ xmlNode *nodep, *first;
+ int ret;
+
+ nodep = obj->ptr;
+
+
+ first = nodep->children;
+ if (!first) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(first);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(first, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ 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)
+{
+ zval *wrapper;
+ xmlNode *nodep, *last;
+ int ret;
+
+ nodep = obj->ptr;
+
+ last = nodep->last;
+ if (!last) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(last);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(last, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ 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)
+{
+ zval *wrapper;
+ xmlNode *nodep, *prevsib;
+ int ret;
+
+ nodep = obj->ptr;
+
+ prevsib = nodep->prev;
+ if (!prevsib) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(prevsib);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(prevsib, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto nextSibling node
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6AC54C2F
+Since:
+*/
+int dom_node_next_sibling_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ zval *wrapper;
+ xmlNode *nodep, *nextsib;
+ int ret;
+
+ nodep = obj->ptr;
+
+ nextsib = nodep->next;
+ if (!nextsib) {
+ return FAILURE;
+ }
+
+ wrapper = dom_object_get_data(nextsib);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object(nextsib, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ 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)
+{
+ xmlNodePtr nodep;
+ xmlAttr *attr;
+
+ int ret;
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+ if (nodep->type == XML_ELEMENT_NODE) {
+ attr = nodep->properties;
+ array_init(*retval);
+
+ while (attr) {
+ zval *curattr = NULL;
+ zval *wrapper;
+ wrapper = dom_object_get_data((xmlNodePtr) attr);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(curattr);
+ }
+ curattr = php_dom_create_object((xmlNodePtr) attr, &ret, wrapper, curattr TSRMLS_CC);
+ add_assoc_zval(*retval, (char *) attr->name, curattr);
+ attr = attr->next;
+ }
+ } else {
+ ZVAL_NULL(*retval);
+ }
+
+ 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)
+{
+ zval *wrapper;
+ xmlNode *nodep;
+ xmlDocPtr docp;
+ int ret;
+
+ nodep = obj->ptr;
+
+ 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;
+ }
+
+ wrapper = dom_object_get_data((xmlNodePtr) docp);
+ if (wrapper == NULL) {
+ ALLOC_ZVAL(*retval);
+ }
+ if (NULL == (*retval = php_dom_create_object((xmlNodePtr) docp, &ret, wrapper, *retval TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
+ 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;
+
+ nodep = obj->ptr;
+
+ switch (nodep->type) {
+ case XML_ELEMENT_NODE:
+ case XML_ATTRIBUTE_NODE:
+ 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 {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+ 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;
+
+ nodep = obj->ptr;
+
+ switch (nodep->type) {
+ case XML_ELEMENT_NODE:
+ case XML_ATTRIBUTE_NODE:
+ ns = nodep->ns;
+ if (ns != NULL) {
+ if (ns->prefix) {
+ str = (char *) ns->prefix;
+ }
+ }
+ 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;
+
+ nodep = obj->ptr;
+
+ switch (nodep->type) {
+ case XML_ELEMENT_NODE:
+ case XML_ATTRIBUTE_NODE:
+ ns = nodep->ns;
+ strURI = NULL;
+ if (nodep->ns != NULL) {
+ strURI = (char *) nodep->ns->href;
+ }
+ prefix = Z_STRVAL_P(newval);
+ 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"))) {
+
+ /* TODO: throw error - find out how to without a return_value
+ php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC); */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ return FAILURE;
+ }
+ 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;
+ }
+
+ nodep->ns = curns;
+ 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;
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+ if (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE) {
+ ZVAL_STRING(*retval, (char *) (nodep->name), 1);
+ } else {
+ ZVAL_NULL(*retval);
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto baseURI string
+readonly=yes
+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)
+{
+ /* TODO: Implement this feature */
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ 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;
+
+ nodep = obj->ptr;
+
+ 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
+Since:
+*/
+PHP_FUNCTION(dom_node_insert_before)
+{
+ zval *id, *node, *ref, *rv = NULL;
+ xmlNodePtr child, new_child, parentp, refp;
+ int ret;
+
+ DOM_GET_THIS_OBJ(parentp, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo!", &node, &ref) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(child, node, xmlNodePtr);
+
+ new_child = NULL;
+
+ if (dom_hierarchy(parentp, child) == FAILURE) {
+ php_dom_throw_error(HIERARCHY_REQUEST_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hierarchy Request Error");
+ }
+
+ if (child->doc != parentp->doc && child->doc != NULL) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't add newnode as it was created from a different document");
+ RETURN_FALSE;
+ }
+
+ if (ref != NULL) {
+ DOM_GET_OBJ(refp, ref, xmlNodePtr);
+ if (refp->parent != parentp) {
+ php_dom_throw_error(NOT_FOUND_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't add newnode as refnode is not child of node");
+ 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);
+ node_free_resource(child TSRMLS_CC);
+ DOM_RET_OBJ(rv, refp, &ret);
+ return;
+ }
+ if ((refp->prev != NULL) && (refp->prev->type == XML_TEXT_NODE)
+ && (refp->name == refp->prev->name)) {
+ xmlNodeAddContent(refp->prev, child->content);
+ node_free_resource(child TSRMLS_CC);
+ DOM_RET_OBJ(rv, refp->prev, &ret);
+ 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);
+ node_free_resource((xmlNodePtr) lastattr TSRMLS_CC);
+ xmlFreeProp(lastattr);
+ } else {
+ DOM_RET_OBJ(rv, child, &ret);
+ 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);
+ node_free_resource(child TSRMLS_CC);
+ DOM_RET_OBJ(rv, parentp, &ret);
+ return;
+ }
+ if ((parentp->last != NULL) && (parentp->last->type == XML_TEXT_NODE) &&
+ (parentp->last->name == child->name) &&
+ (parentp->last != child)) {
+ xmlNodeAddContent(parentp->last, child->content);
+ node_free_resource(child TSRMLS_CC);
+ DOM_RET_OBJ(rv, parentp->last, &ret);
+ 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);
+ node_free_resource((xmlNodePtr) lastattr TSRMLS_CC);
+ xmlFreeProp(lastattr);
+ } else {
+ DOM_RET_OBJ(rv, child, &ret);
+ return;
+ }
+ }
+ } else if (child->type == XML_DOCUMENT_FRAG_NODE) {
+ new_child = xmlAddChildList(parentp, child->children);
+ if (new_child != NULL) {
+ child->children = NULL;
+ }
+ dom_add_to_list(child, (xmlDocPtr) child->doc TSRMLS_CC);
+ DOM_RET_OBJ(rv, new_child, &ret);
+ 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;
+ }
+
+ dom_del_from_list(child, (xmlDocPtr) child->doc TSRMLS_CC);
+
+ DOM_RET_OBJ(rv, new_child, &ret);
+
+}
+/* }}} 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;
+ int foundoldchild = 0;
+ int ret;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo", &newnode, &oldnode) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(newchild, newnode, xmlNodePtr);
+ DOM_GET_OBJ(oldchild, oldnode, xmlNodePtr);
+
+ children = nodep->children;
+ if (!children) {
+ RETURN_FALSE;
+ }
+
+ if (newchild->doc != nodep->doc && newchild->doc != NULL) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't add newnode as it was created from a different document");
+ RETURN_FALSE;
+ }
+
+ if (dom_hierarchy(nodep, newchild) == FAILURE) {
+ php_dom_throw_error(HIERARCHY_REQUEST_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hierarchy Request Error");
+ }
+
+ /* 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;
+ if (newchild->parent == NULL && newchild->doc != NULL) {
+ dom_del_from_list(newchild, (xmlDocPtr) newchild->doc TSRMLS_CC);
+ }
+ if((node = xmlReplaceNode(oldchild, newchild)) != NULL) {
+ dom_add_to_list(node, (xmlDocPtr) node->doc TSRMLS_CC);
+ }
+ }
+ DOM_RET_OBJ(rv, oldchild, &ret);
+ return;
+ } else {
+ php_dom_throw_error(NOT_FOUND_ERR, &return_value TSRMLS_CC);
+ 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;
+ int ret;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(child, node, xmlNodePtr);
+
+ children = nodep->children;
+ if (!children) {
+ php_dom_throw_error(NOT_FOUND_ERR, &return_value TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ while (children) {
+ if (children == child) {
+ zval *rv = NULL;
+ xmlUnlinkNode(child);
+ dom_add_to_list(child, (xmlDocPtr) child->doc TSRMLS_CC);
+ DOM_RET_OBJ(rv, child, &ret);
+ return;
+ }
+ children = children->next;
+ }
+
+ php_dom_throw_error(NOT_FOUND_ERR, &return_value TSRMLS_CC);
+ 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;
+ int ret;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(child, node, xmlNodePtr);
+
+ if (dom_hierarchy(nodep, child) == FAILURE) {
+ php_dom_throw_error(HIERARCHY_REQUEST_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hierarchy Request Error");
+ }
+
+ if (!(child->doc == NULL || child->doc == nodep->doc)) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't append node, which is in a different document than the parent node");
+ RETURN_FALSE;
+ }
+
+ 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);
+ node_free_resource(child TSRMLS_CC);
+ DOM_RET_OBJ(rv, nodep, &ret);
+ return;
+ }
+ if ((nodep->last != NULL) && (nodep->last->type == XML_TEXT_NODE) &&
+ (nodep->last->name == child->name)) {
+ xmlNodeAddContent(nodep->last, child->content);
+ node_free_resource(child TSRMLS_CC);
+ DOM_RET_OBJ(rv, nodep->last, &ret);
+ 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);
+ node_free_resource((xmlNodePtr) lastattr TSRMLS_CC);
+ xmlFreeProp(lastattr);
+ }
+ }
+ } else if (child->type == XML_DOCUMENT_FRAG_NODE) {
+ new_child = xmlAddChildList(nodep, child->children);
+ if (new_child != NULL) {
+ child->children = NULL;
+ }
+ dom_add_to_list(child, (xmlDocPtr) child->doc TSRMLS_CC);
+ DOM_RET_OBJ(rv, new_child, &ret);
+ return;
+ }
+
+ new_child = xmlAddChild(nodep, child);
+
+ if (new_child == NULL) {
+ dom_add_to_list(child, (xmlDocPtr) child->doc TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't append node");
+ RETURN_FALSE;
+ }
+
+ dom_del_from_list(child, (xmlDocPtr) child->doc TSRMLS_CC);
+
+ DOM_RET_OBJ(rv, new_child, &ret);
+}
+/* }}} 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;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ DOM_NO_ARGS();
+
+ 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;
+ int ret;
+ long recursive = 0;
+
+ DOM_GET_THIS_OBJ(n, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &recursive) == FAILURE) {
+ return;
+ }
+
+ node = xmlCopyNode(n, recursive);
+ if (!node) {
+ RETURN_FALSE;
+ }
+ dom_add_to_list(node, (xmlDocPtr) node->doc TSRMLS_CC);
+
+ DOM_RET_OBJ(rv, node, &ret);
+}
+/* }}} 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;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ DOM_NO_ARGS();
+
+ dom_normalize(nodep TSRMLS_CC);
+
+}
+/* }}} end dom_node_normalize */
+
+
+/* {{{ proto boolean dom_node_is_supported(string feature, string version);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-Node-supports
+Since: DOM Level 2
+*/
+PHP_FUNCTION(dom_node_is_supported)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} 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;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ 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;
+
+ DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(nodeotherp, node, xmlNodePtr);
+
+ 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)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_node_lookup_prefix */
+
+
+/* {{{ proto boolean dom_node_is_default_namespace(string namespaceURI);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-isDefaultNamespace
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_node_is_default_namespace)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_node_is_default_namespace */
+
+
+/* {{{ proto domstring dom_node_lookup_namespace_uri(string prefix);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Node3-lookupNamespaceURI
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_node_lookup_namespace_uri)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} 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 */
diff --git a/ext/dom/nodelist.c b/ext/dom/nodelist.c
new file mode 100644
index 0000000000..e4f1955fb7
--- /dev/null
+++ b/ext/dom/nodelist.c
@@ -0,0 +1,69 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domnodelist
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-536297177
+* Since:
+*/
+
+zend_function_entry php_dom_nodelist_class_functions[] = {
+ PHP_FALIAS(item, dom_nodelist_item, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto length unsigned long
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
+Since:
+*/
+int dom_nodelist_length_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, "TEST", 1);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domnode dom_nodelist_item(unsigned long index);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136
+Since:
+*/
+PHP_FUNCTION(dom_nodelist_item)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_nodelist_item */
diff --git a/ext/dom/notation.c b/ext/dom/notation.c
new file mode 100644
index 0000000000..4cd8fc9110
--- /dev/null
+++ b/ext/dom/notation.c
@@ -0,0 +1,89 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domnotation extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-5431D1B9
+* Since:
+*/
+
+zend_function_entry php_dom_notation_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto public_id string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-54F2B4D0
+Since:
+*/
+int dom_notation_public_id_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNotationPtr nodep;
+
+ nodep = obj->ptr;
+ ALLOC_ZVAL(*retval);
+ if (nodep->PublicID) {
+ ZVAL_STRING(*retval, (char *) (nodep->PublicID), 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto system_id string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-E8AAB1D0
+Since:
+*/
+int dom_notation_system_id_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNotationPtr nodep;
+
+ nodep = obj->ptr;
+ ALLOC_ZVAL(*retval);
+ if (nodep->SystemID) {
+ ZVAL_STRING(*retval, (char *) (nodep->PublicID), 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
new file mode 100644
index 0000000000..c78c6c2426
--- /dev/null
+++ b/ext/dom/php_dom.c
@@ -0,0 +1,1144 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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> |
+ | Marcus Borger <helly@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "ext/standard/php_rand.h"
+#include "php_dom.h"
+#include "dom_ce.h"
+#include "dom_properties.h"
+
+#if HAVE_DOM
+
+#include "zend_execute_locks.h"
+#include "ext/standard/info.h"
+#define PHP_XPATH 1
+#define PHP_XPTR 2
+
+zend_object_handlers dom_object_handlers;
+
+static HashTable classes;
+
+static HashTable dom_domstringlist_prop_handlers;
+static HashTable dom_namelist_prop_handlers;
+static HashTable dom_domimplementationlist_prop_handlers;
+static HashTable dom_document_prop_handlers;
+static HashTable dom_node_prop_handlers;
+static HashTable dom_nodelist_prop_handlers;
+static HashTable dom_namednodemap_prop_handlers;
+static HashTable dom_characterdata_prop_handlers;
+static HashTable dom_attr_prop_handlers;
+static HashTable dom_element_prop_handlers;
+static HashTable dom_text_prop_handlers;
+static HashTable dom_typeinfo_prop_handlers;
+static HashTable dom_domerror_prop_handlers;
+static HashTable dom_domlocator_prop_handlers;
+static HashTable dom_documenttype_prop_handlers;
+static HashTable dom_notation_prop_handlers;
+static HashTable dom_entity_prop_handlers;
+static HashTable dom_processinginstruction_prop_handlers;
+
+
+typedef int (*dom_read_t)(dom_object *obj, zval **retval TSRMLS_DC);
+typedef int (*dom_write_t)(dom_object *obj, zval *newval TSRMLS_DC);
+
+typedef struct _dom_prop_handler {
+ dom_read_t read_func;
+ dom_write_t write_func;
+} dom_prop_handler;
+
+static zend_function_entry dom_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ dom_object_set_data */
+static void dom_object_set_data(xmlNodePtr obj, zval *wrapper TSRMLS_DC)
+{
+
+ obj->_private = wrapper;
+}
+/* }}} */
+
+/* {{{ dom_object_get_data */
+zval *dom_object_get_data(xmlNodePtr obj)
+{
+ return (zval *) obj->_private;
+}
+/* }}} */
+
+/* {{{ php_dom_clear_object */
+static void php_dom_clear_object(zval *wrapper TSRMLS_DC)
+{
+ dom_object *object;
+
+ object = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
+ object->ptr = NULL;
+}
+/* }}} */
+
+/* {{{ php_dom_set_object */
+void php_dom_set_object(zval *wrapper, void *obj TSRMLS_DC)
+{
+ dom_object *object;
+
+ object = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
+ object->ptr = obj;
+ dom_object_set_data(obj, wrapper TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ dom_unregister_node */
+void dom_unregister_node(xmlNodePtr nodep TSRMLS_DC)
+{
+ zval *wrapper;
+
+ wrapper = dom_object_get_data(nodep);
+ if (wrapper != NULL ) {
+ if (nodep->parent == NULL && nodep->doc != NULL && (xmlNodePtr) nodep->doc != nodep) {
+ dom_del_from_list(nodep, (xmlDocPtr) nodep->doc TSRMLS_CC);
+ }
+ dom_object_set_data(nodep, NULL TSRMLS_CC);
+ php_dom_clear_object(wrapper TSRMLS_CC);
+ }
+}
+/* }}} */
+
+/* {{{ dom_del_from_list */
+void dom_del_from_list(xmlNodePtr nodep, xmlDocPtr docp TSRMLS_DC)
+{
+ zval *wrapper;
+ dom_object *object;
+ xmlNodePtr cur;
+ node_list_pointer *cur_element, *prev;
+
+ if (docp != NULL && nodep != NULL) {
+ wrapper = dom_object_get_data((xmlNodePtr) docp);
+
+ if (wrapper != NULL) {
+ object = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
+ cur_element = object->node_list;
+ prev = NULL;
+ while (cur_element != NULL) {
+ cur = cur_element->nodep;
+ if (cur == nodep) {
+ if (prev == NULL) {
+ object->node_list = cur_element->next;
+ } else {
+ prev->next = cur_element->next;
+ }
+ efree(cur_element);
+ return;
+ } else {
+ prev = cur_element;
+ cur_element = cur_element->next;
+ }
+ }
+ }
+ }
+}
+/* }}} */
+
+/* {{{ dom_add_to_list */
+void dom_add_to_list(xmlNodePtr nodep, xmlDocPtr docp TSRMLS_DC)
+{
+ zval *wrapper;
+ dom_object *object;
+ node_list_pointer *cur_element;
+
+ if (docp != NULL && nodep != NULL) {
+ if (nodep->parent == NULL) {
+ wrapper = dom_object_get_data((xmlNodePtr) docp);
+ if (wrapper != NULL) {
+ object = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
+ dom_del_from_list(nodep, docp TSRMLS_CC);
+ cur_element = emalloc(sizeof(node_list_pointer));
+ cur_element->nodep = nodep;
+ cur_element->next = NULL;
+ if (object->node_list != NULL) {
+ cur_element->next = object->node_list;
+ }
+ object->node_list = cur_element;
+ }
+ }
+ }
+}
+/* }}} */
+
+/* {{{ dom_read_na */
+static int dom_read_na(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ *retval = NULL;
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property");
+ return FAILURE;
+}
+/* }}} */
+
+/* {{{ dom_write_na */
+static int dom_write_na(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot write property");
+ return FAILURE;
+}
+/* }}} */
+
+/* {{{ dom_register_prop_handler */
+static void dom_register_prop_handler(HashTable *prop_handler, char *name, dom_read_t read_func, dom_write_t write_func TSRMLS_DC)
+{
+ dom_prop_handler hnd;
+
+ hnd.read_func = read_func ? read_func : dom_read_na;
+ hnd.write_func = write_func ? write_func : dom_write_na;
+ zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(dom_prop_handler), NULL);
+}
+/* }}} */
+
+/* {{{ dom_read_property */
+zval *dom_read_property(zval *object, zval *member TSRMLS_DC)
+{
+ dom_object *obj;
+ zval tmp_member;
+ zval *retval;
+ dom_prop_handler *hnd;
+ zend_object_handlers *std_hnd;
+ int ret;
+
+ if (member->type != IS_STRING) {
+ tmp_member = *member;
+ zval_copy_ctor(&tmp_member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
+ }
+
+ ret = FAILURE;
+ obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
+ if (obj->prop_handler != NULL) {
+ ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
+ }
+ if (ret == SUCCESS) {
+ hnd->read_func(obj, &retval TSRMLS_CC);
+ if (retval) {
+ /* ensure we're creating a temporary variable */
+ retval->refcount = 1;
+ PZVAL_UNLOCK(retval);
+ } else {
+ retval = EG(uninitialized_zval_ptr);
+ }
+ } else {
+ std_hnd = zend_get_std_object_handlers();
+ retval = std_hnd->read_property(object, member TSRMLS_CC);
+ }
+ if (member == &tmp_member) {
+ zval_dtor(member);
+ }
+ return retval;
+}
+/* }}} */
+
+/* {{{ dom_write_property */
+void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
+{
+ dom_object *obj;
+ zval tmp_member;
+ dom_prop_handler *hnd;
+ zend_object_handlers *std_hnd;
+ int ret;
+
+ if (member->type != IS_STRING) {
+ tmp_member = *member;
+ zval_copy_ctor(&tmp_member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
+ }
+
+ ret = FAILURE;
+ obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
+
+ if (obj->prop_handler != NULL) {
+ ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
+ }
+ if (ret == SUCCESS) {
+ hnd->write_func(obj, value TSRMLS_CC);
+ } else {
+ std_hnd = zend_get_std_object_handlers();
+ std_hnd->write_property(object, member, value TSRMLS_CC);
+ }
+ if (member == &tmp_member) {
+ zval_dtor(member);
+ }
+}
+/* }}} */
+
+zend_module_entry dom_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "dom",
+ dom_functions,
+ PHP_MINIT(dom),
+ PHP_MSHUTDOWN(dom),
+ NULL,
+ NULL,
+ PHP_MINFO(dom),
+ DOM_API_VERSION, /* Extension versionnumber */
+ STANDARD_MODULE_PROPERTIES
+};
+
+#ifdef COMPILE_DL_DOM
+ZEND_GET_MODULE(dom)
+#endif
+
+/* {{{ PHP_MINIT_FUNCTION(dom) */
+PHP_MINIT_FUNCTION(dom)
+{
+ zend_class_entry ce;
+
+ memcpy(&dom_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ dom_object_handlers.read_property = dom_read_property;
+ dom_object_handlers.write_property = dom_write_property;
+
+ zend_hash_init(&classes, 0, NULL, NULL, 1);
+
+ REGISTER_DOM_CLASS(ce, "domexception", NULL, php_dom_domexception_class_functions, dom_domexception_class_entry);
+ REGISTER_DOM_CLASS(ce, "domstringlist", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry);
+
+ zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", dom_domstringlist_length_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domstringlist_prop_handlers, sizeof(dom_domstringlist_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domnamelist", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry);
+
+ zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_namelist_prop_handlers, "length", dom_namelist_length_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namelist_prop_handlers, sizeof(dom_namelist_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domimplementationlist", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry);
+
+ zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", dom_domimplementationlist_length_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domimplementationlist_prop_handlers, sizeof(dom_domimplementationlist_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domimplementationsource", NULL, php_dom_domimplementationsource_class_functions, dom_domimplementationsource_class_entry);
+ REGISTER_DOM_CLASS(ce, "domimplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry);
+
+ REGISTER_DOM_CLASS(ce, "domnode", NULL, php_dom_node_class_functions, dom_node_class_entry);
+
+ zend_hash_init(&dom_node_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "nodeType", dom_node_node_type_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "childNodes", dom_node_child_nodes_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "firstChild", dom_node_first_child_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "lastChild", dom_node_last_child_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "previousSibling", dom_node_previous_sibling_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "nextSibling", dom_node_next_sibling_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "attributes", dom_node_attributes_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "namespaceURI", dom_node_namespace_uri_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "prefix", dom_node_prefix_read, dom_node_prefix_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "localName", dom_node_local_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "baseURI", dom_node_base_uri_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_node_prop_handlers, "textContent", dom_node_text_content_read, dom_node_text_content_write TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domdocumentfragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domdocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry);
+ zend_hash_init(&dom_document_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_document_prop_handlers, "doctype", dom_document_doctype_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "implementation", dom_document_implementation_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "documentElement", dom_document_document_element_read, NULL TSRMLS_CC);
+/* actualEncoding currently set as read only alias to encoding
+ dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", dom_document_actual_encoding_read, dom_document_actual_encoding_write TSRMLS_CC); */
+ dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", dom_document_encoding_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "encoding", dom_document_encoding_read, dom_document_encoding_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "standalone", dom_document_standalone_read, dom_document_standalone_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "version", dom_document_version_read, dom_document_version_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "strictErrorChecking", dom_document_strict_error_checking_read, dom_document_strict_error_checking_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "documentURI", dom_document_document_uri_read, dom_document_document_uri_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "config", dom_document_config_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_document_prop_handlers, sizeof(dom_document_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domnodelist", NULL, php_dom_nodelist_class_functions, dom_nodelist_class_entry);
+
+ zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", dom_nodelist_length_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_nodelist_prop_handlers, sizeof(dom_nodelist_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domnamednodemap", NULL, php_dom_namednodemap_class_functions, dom_namednodemap_class_entry);
+
+ zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", dom_namednodemap_length_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namednodemap_prop_handlers, sizeof(dom_namednodemap_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domcharacterdata", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry);
+
+ zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", dom_characterdata_data_read, dom_characterdata_data_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", dom_characterdata_length_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domattr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry);
+
+ zend_hash_init(&dom_attr_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_attr_prop_handlers, "name", dom_attr_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_attr_prop_handlers, "specified", dom_attr_specified_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_attr_prop_handlers, "value", dom_attr_value_read, dom_attr_value_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_attr_prop_handlers, "ownerElement", dom_attr_owner_element_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_attr_prop_handlers, "schemaTypeInfo", dom_attr_schema_type_info_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_attr_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_attr_prop_handlers, sizeof(dom_attr_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domelement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry);
+
+ zend_hash_init(&dom_element_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_element_prop_handlers, "tagName", dom_element_tag_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", dom_element_schema_type_info_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_element_prop_handlers, sizeof(dom_element_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domtext", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry);
+
+ zend_hash_init(&dom_text_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_text_prop_handlers, "whole_text", dom_text_whole_text_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domcomment", dom_characterdata_class_entry, php_dom_comment_class_functions, dom_comment_class_entry);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domtypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
+
+ zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", dom_typeinfo_type_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", dom_typeinfo_type_namespace_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_typeinfo_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domuserdatahandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry);
+ REGISTER_DOM_CLASS(ce, "domdomerror", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry);
+
+ zend_hash_init(&dom_domerror_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_domerror_prop_handlers, "severity", dom_domerror_severity_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domerror_prop_handlers, "message", dom_domerror_message_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domerror_prop_handlers, "type", dom_domerror_type_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domerror_prop_handlers, "relatedException", dom_domerror_related_exception_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domerror_prop_handlers, "related_data", dom_domerror_related_data_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domerror_prop_handlers, "location", dom_domerror_location_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domerror_prop_handlers, sizeof(dom_domerror_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domdomerrorhandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry);
+ REGISTER_DOM_CLASS(ce, "domdomlocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry);
+
+ zend_hash_init(&dom_domlocator_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_domlocator_prop_handlers, "lineNumber", dom_domlocator_line_number_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domlocator_prop_handlers, "columnNumber", dom_domlocator_column_number_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domlocator_prop_handlers, "offset", dom_domlocator_offset_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domlocator_prop_handlers, "relatedNode", dom_domlocator_related_node_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_domlocator_prop_handlers, "uri", dom_domlocator_uri_read, NULL TSRMLS_CC);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domlocator_prop_handlers, sizeof(dom_domlocator_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domdomconfiguration", NULL, php_dom_domconfiguration_class_functions, dom_domconfiguration_class_entry);
+ REGISTER_DOM_CLASS(ce, "domcdatasection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domdocumenttype", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
+
+ zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", dom_documenttype_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_documenttype_prop_handlers, "entities", dom_documenttype_entities_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_documenttype_prop_handlers, "notations", dom_documenttype_notations_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_documenttype_prop_handlers, "publicId", dom_documenttype_public_id_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_documenttype_prop_handlers, "systemId", dom_documenttype_system_id_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_documenttype_prop_handlers, "internalSubset", dom_documenttype_internal_subset_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domnotation", dom_node_class_entry, php_dom_notation_class_functions, dom_notation_class_entry);
+
+ zend_hash_init(&dom_notation_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", dom_notation_public_id_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", dom_notation_system_id_read, NULL TSRMLS_CC);
+ zend_hash_merge(&dom_notation_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domentity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry);
+
+ zend_hash_init(&dom_entity_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", dom_entity_public_id_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", dom_entity_system_id_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_entity_prop_handlers, "notationName", dom_entity_notation_name_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", dom_entity_actual_encoding_read, dom_entity_actual_encoding_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", dom_entity_encoding_read, dom_entity_encoding_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_entity_prop_handlers, "version", dom_entity_version_read, dom_entity_version_write TSRMLS_CC);
+ zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domentityreference", dom_node_class_entry, php_dom_entityreference_class_functions, dom_entityreference_class_entry);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domprocessinginstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry);
+
+ zend_hash_init(&dom_processinginstruction_prop_handlers, 0, NULL, NULL, 1);
+ dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "target", dom_processinginstruction_target_read, NULL TSRMLS_CC);
+ dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "data", dom_processinginstruction_data_read, dom_processinginstruction_data_write TSRMLS_CC);
+ zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
+ zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_processinginstruction_prop_handlers, sizeof(dom_processinginstruction_prop_handlers), NULL);
+
+ REGISTER_DOM_CLASS(ce, "domstring_extend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry);
+
+ REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE", XML_ELEMENT_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NODE", XML_ATTRIBUTE_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_TEXT_NODE", XML_TEXT_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_CDATA_SECTION_NODE", XML_CDATA_SECTION_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ENTITY_REF_NODE", XML_ENTITY_REF_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ENTITY_NODE", XML_ENTITY_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_PI_NODE", XML_PI_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_COMMENT_NODE", XML_COMMENT_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_DOCUMENT_NODE", XML_DOCUMENT_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_DOCUMENT_TYPE_NODE", XML_DOCUMENT_TYPE_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_DOCUMENT_FRAG_NODE", XML_DOCUMENT_FRAG_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_NOTATION_NODE", XML_NOTATION_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_HTML_DOCUMENT_NODE", XML_HTML_DOCUMENT_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_DTD_NODE", XML_DTD_NODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ELEMENT_DECL_NODE", XML_ELEMENT_DECL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_DECL_NODE", XML_ATTRIBUTE_DECL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ENTITY_DECL_NODE", XML_ENTITY_DECL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_NAMESPACE_DECL_NODE", XML_NAMESPACE_DECL, CONST_CS | CONST_PERSISTENT);
+#ifdef XML_GLOBAL_NAMESPACE
+ REGISTER_LONG_CONSTANT("XML_GLOBAL_NAMESPACE", XML_GLOBAL_NAMESPACE, CONST_CS | CONST_PERSISTENT);
+#endif
+ REGISTER_LONG_CONSTANT("XML_LOCAL_NAMESPACE", XML_LOCAL_NAMESPACE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_CDATA", XML_ATTRIBUTE_CDATA, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ID", XML_ATTRIBUTE_ID, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREF", XML_ATTRIBUTE_IDREF, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREFS", XML_ATTRIBUTE_IDREFS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENTITY", XML_ATTRIBUTE_ENTITIES, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKEN", XML_ATTRIBUTE_NMTOKEN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKENS", XML_ATTRIBUTE_NMTOKENS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENUMERATION", XML_ATTRIBUTE_ENUMERATION, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NOTATION", XML_ATTRIBUTE_NOTATION, CONST_CS | CONST_PERSISTENT);
+
+
+ xmlInitParser();
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ */
+PHP_MINFO_FUNCTION(dom)
+{
+ php_info_print_table_start();
+ php_info_print_table_row(2, "DOM/XML", "enabled");
+ php_info_print_table_row(2, "DOM/XML API Version", DOM_API_VERSION);
+ php_info_print_table_row(2, "libxml Version", xmlParserVersion);
+#if defined(LIBXML_HTML_ENABLED)
+ php_info_print_table_row(2, "HTML Support", "enabled");
+#endif
+#if defined(LIBXML_XPATH_ENABLED)
+ php_info_print_table_row(2, "XPath Support", "enabled");
+#endif
+#if defined(LIBXML_XPTR_ENABLED)
+ php_info_print_table_row(2, "XPointer Support", "enabled");
+#endif
+ php_info_print_table_end();
+}
+/* }}} */
+
+PHP_MSHUTDOWN_FUNCTION(dom)
+{
+ xmlCleanupParser();
+
+ zend_hash_destroy(&dom_domstringlist_prop_handlers);
+ zend_hash_destroy(&dom_namelist_prop_handlers);
+ zend_hash_destroy(&dom_domimplementationlist_prop_handlers);
+ zend_hash_destroy(&dom_document_prop_handlers);
+ zend_hash_destroy(&dom_node_prop_handlers);
+ zend_hash_destroy(&dom_nodelist_prop_handlers);
+ zend_hash_destroy(&dom_namednodemap_prop_handlers);
+ zend_hash_destroy(&dom_characterdata_prop_handlers);
+ zend_hash_destroy(&dom_attr_prop_handlers);
+ zend_hash_destroy(&dom_element_prop_handlers);
+ zend_hash_destroy(&dom_text_prop_handlers);
+ zend_hash_destroy(&dom_typeinfo_prop_handlers);
+ zend_hash_destroy(&dom_domerror_prop_handlers);
+ zend_hash_destroy(&dom_domlocator_prop_handlers);
+ zend_hash_destroy(&dom_documenttype_prop_handlers);
+ zend_hash_destroy(&dom_notation_prop_handlers);
+ zend_hash_destroy(&dom_entity_prop_handlers);
+ zend_hash_destroy(&dom_processinginstruction_prop_handlers);
+ zend_hash_destroy(&classes);
+
+/* If you want do find memleaks in this module, compile libxml2 with --with-mem-debug and
+ uncomment the following line, this will tell you the amount of not freed memory
+ and the total used memory into apaches error_log */
+/* xmlMemoryDump();*/
+
+ return SUCCESS;
+}
+
+/* {{{ dom_clean_nodes */
+void dom_clean_nodes(xmlNodePtr nodep TSRMLS_DC)
+{
+ node_list_pointer *l;
+ zval *wrapper;
+ dom_object *object;
+
+ if (nodep != NULL) {
+ wrapper = dom_object_get_data(nodep);
+ if (wrapper != NULL) {
+ object = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
+ l = object->node_list;
+ while (l != NULL) {
+ node_free_resource(l->nodep TSRMLS_CC);
+ l = object->node_list;
+ }
+ }
+ }
+}
+/* }}} */
+
+/* {{{ node_list_unlink */
+void node_list_unlink(xmlNodePtr node TSRMLS_DC)
+{
+ zval *wrapper;
+
+ while (node != NULL) {
+
+ wrapper = dom_object_get_data(node);
+
+ if (wrapper != NULL ) {
+ dom_add_to_list(node, node->doc TSRMLS_CC);
+ xmlUnlinkNode(node);
+ } else {
+ node_list_unlink(node->children TSRMLS_CC);
+
+ switch (node->type) {
+ case XML_ATTRIBUTE_DECL:
+ case XML_DTD_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
+ case XML_ENTITY_DECL:
+ case XML_ATTRIBUTE_NODE:
+ break;
+ default:
+ node_list_unlink((xmlNodePtr) node->properties TSRMLS_CC);
+ }
+
+ }
+
+ node = node->next;
+ }
+}
+/* }}} end node_list_unlink */
+
+/* {{{ node_free_list */
+void node_free_list(xmlNodePtr node TSRMLS_DC)
+{
+ xmlNodePtr curnode;
+
+ if (node != NULL) {
+ curnode = node->last;
+ while (curnode != NULL) {
+ node = curnode;
+ node_free_list(node->children TSRMLS_CC);
+ switch (node->type) {
+ /* Skip property freeing for the following types */
+ case XML_ATTRIBUTE_DECL:
+ case XML_DTD_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
+ case XML_ENTITY_DECL:
+ case XML_ATTRIBUTE_NODE:
+ break;
+ default:
+ node_free_list((xmlNodePtr) node->properties TSRMLS_CC);
+ }
+
+ dom_unregister_node(node TSRMLS_CC);
+ curnode = node->prev;
+ xmlUnlinkNode(node);
+ xmlFreeNode(node);
+ }
+ }
+}
+/* }}} end node_free_list */
+
+/* {{{ node_free_resource */
+void node_free_resource(xmlNodePtr node TSRMLS_DC)
+{
+ xmlDtdPtr extSubset, intSubset;
+ xmlDocPtr docp;
+ if (!node) {
+ return;
+ }
+ switch (node->type) {
+ case XML_DOCUMENT_NODE:
+ case XML_HTML_DOCUMENT_NODE:
+ {
+ docp = (xmlDocPtr) node;
+ dom_clean_nodes(node TSRMLS_CC);
+ if (docp->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) docp->ids);
+ docp->ids = NULL;
+ if (docp->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) docp->refs);
+ docp->refs = NULL;
+ extSubset = docp->extSubset;
+ intSubset = docp->intSubset;
+ if (intSubset == extSubset)
+ extSubset = NULL;
+ if (extSubset != NULL) {
+ node_free_list((xmlNodePtr) extSubset->children TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) docp->extSubset);
+ docp->extSubset = NULL;
+ xmlFreeDtd(extSubset);
+ }
+ if (intSubset != NULL) {
+ node_free_list((xmlNodePtr) intSubset->children TSRMLS_CC);
+ xmlUnlinkNode((xmlNodePtr) docp->intSubset);
+ docp->intSubset = NULL;
+ xmlFreeDtd(intSubset);
+ }
+
+ node_free_list(node->children TSRMLS_CC);
+ node_free_list((xmlNodePtr) node->properties TSRMLS_CC);
+ xmlFreeDoc((xmlDoc *) node);
+ break;
+ }
+ default:
+ if (node->parent == NULL) {
+ node_free_list((xmlNodePtr) node->children TSRMLS_CC);
+ switch (node->type) {
+ /* Skip property freeing for the following types */
+ case XML_ATTRIBUTE_DECL:
+ case XML_DTD_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
+ case XML_ENTITY_DECL:
+ case XML_ATTRIBUTE_NODE:
+ break;
+ default:
+ node_free_list((xmlNodePtr) node->properties TSRMLS_CC);
+ }
+ dom_unregister_node(node TSRMLS_CC);
+ switch (node->type) {
+ case XML_ATTRIBUTE_NODE:
+ xmlFreeProp((xmlAttrPtr) node);
+ break;
+ default:
+ xmlFreeNode((xmlNode *) node);
+ }
+ } else {
+ dom_object_set_data(node, NULL TSRMLS_CC);
+ }
+ }
+}
+/* }}} */
+
+/* {{{ dom_objects_clone */
+void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
+{
+ /* TODO */
+}
+/* }}} */
+
+/* {{{ dom_objects_dtor */
+void dom_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC)
+{
+ dom_object *intern = (dom_object *)object;
+
+ zend_hash_destroy(intern->std.properties);
+ FREE_HASHTABLE(intern->std.properties);
+
+ if (intern->ptr) {
+ node_free_resource(intern->ptr TSRMLS_CC);
+ intern->ptr = NULL;
+ }
+ efree(object);
+}
+/* }}} */
+
+/* {{{ dom_objects_new */
+zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
+{
+ zend_object_value retval;
+ dom_object *intern;
+ zend_class_entry *base_class;
+ zval *tmp;
+
+ intern = emalloc(sizeof(dom_object));
+ intern->std.ce = class_type;
+ intern->std.in_get = 0;
+ intern->std.in_set = 0;
+ intern->ptr = NULL;
+ intern->node_list = NULL;
+ intern->prop_handler = NULL;
+
+ base_class = class_type;
+ while(base_class->type != ZEND_INTERNAL_CLASS && base_class->parent != NULL) {
+ base_class = base_class->parent;
+ }
+
+ zend_hash_find(&classes, base_class->name , base_class->name_length + 1, (void **) &intern->prop_handler);
+
+ ALLOC_HASHTABLE(intern->std.properties);
+ zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+
+ retval.handle = zend_objects_store_put(intern, dom_objects_dtor, dom_objects_clone TSRMLS_CC);
+ retval.handlers = &dom_object_handlers;
+
+ return retval;
+}
+/* }}} */
+
+/* {{{ php_domobject_new */
+zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *wrapper_in, zval *return_value TSRMLS_DC)
+{
+ zval *wrapper;
+ zend_class_entry *ce;
+
+ *found = 0;
+
+ if (!obj) {
+ if(!wrapper_in) {
+ ALLOC_ZVAL(wrapper);
+ } else {
+ wrapper = wrapper_in;
+ }
+ ZVAL_NULL(wrapper);
+ return wrapper;
+ }
+
+ if ((wrapper = (zval *) dom_object_get_data((void *) obj))) {
+ if (wrapper_in) {
+ zval_add_ref(&wrapper);
+ *found = 1;
+ return wrapper;
+ } else {
+ *return_value = *wrapper;
+ zval_copy_ctor(return_value);
+ *found = 1;
+ return return_value;
+ }
+ }
+
+ if(!wrapper_in) {
+ wrapper = return_value;
+ } else {
+ wrapper = wrapper_in;
+ }
+
+ switch (obj->type) {
+ case XML_DOCUMENT_NODE:
+ case XML_HTML_DOCUMENT_NODE:
+ {
+ ce = dom_document_class_entry;
+ break;
+ }
+ case XML_DTD_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
+ {
+ ce = dom_documenttype_class_entry;
+ break;
+ }
+ case XML_ELEMENT_NODE:
+ {
+ ce = dom_element_class_entry;
+ break;
+ }
+ case XML_ATTRIBUTE_NODE:
+ {
+ ce = dom_attr_class_entry;
+ break;
+ }
+ case XML_TEXT_NODE:
+ {
+ ce = dom_text_class_entry;
+ break;
+ }
+ case XML_COMMENT_NODE:
+ {
+ ce = dom_comment_class_entry;
+ break;
+ }
+ case XML_PI_NODE:
+ {
+ ce = dom_processinginstruction_class_entry;
+ break;
+ }
+ case XML_ENTITY_REF_NODE:
+ {
+ ce = dom_entityreference_class_entry;
+ break;
+ }
+ case XML_ENTITY_DECL:
+ case XML_ELEMENT_DECL:
+ {
+ ce = dom_entity_class_entry;
+ break;
+ }
+ case XML_CDATA_SECTION_NODE:
+ {
+ ce = dom_cdatasection_class_entry;
+ break;
+ }
+ case XML_DOCUMENT_FRAG_NODE:
+ {
+ ce = dom_documentfragment_class_entry;
+ break;
+ }
+ case XML_NOTATION_NODE:
+ {
+ ce = dom_notation_class_entry;
+ break;
+ }
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d\n", Z_TYPE_P(obj));
+ ZVAL_NULL(wrapper);
+ return wrapper;
+ }
+
+ if(!wrapper_in) {
+ object_init_ex(wrapper, ce);
+ }
+
+ php_dom_set_object(wrapper, (void *) obj TSRMLS_CC);
+ return (wrapper);
+}
+/* }}} end php_domobject_new */
+
+
+void php_dom_create_implementation(zval **retval TSRMLS_DC) {
+ object_init_ex(*retval, dom_domimplementation_class_entry);
+}
+
+/* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */
+int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
+{
+ xmlNodePtr nodep;
+
+ if (parent == NULL || child == NULL || child->doc != parent->doc) {
+ return SUCCESS;
+ }
+
+ nodep = parent;
+
+ while (nodep) {
+ if (nodep == child) {
+ return FAILURE;
+ }
+ nodep = nodep->parent;
+ }
+
+ return SUCCESS;
+}
+/* }}} end dom_hierarchy */
+
+/* {{{ void dom_element_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, zval **retval TSRMLS_DC) */
+void dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, zval **retval TSRMLS_DC)
+{
+ zval *wrapper;
+ int ret;
+
+ while (nodep != NULL) {
+ if (nodep->type == XML_ELEMENT_NODE && xmlStrEqual(nodep->name, local)) {
+ if (ns == NULL || (nodep->ns != NULL && xmlStrEqual(nodep->ns->href, ns))) {
+ zval *child = NULL;
+ wrapper = dom_object_get_data(nodep);
+ if (wrapper == NULL) {
+ MAKE_STD_ZVAL(child);
+ }
+
+ child = php_dom_create_object(nodep, &ret, wrapper, child TSRMLS_CC);
+ add_next_index_zval(*retval, child);
+ }
+ }
+ dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, retval TSRMLS_CC);
+ nodep = nodep->next;
+ }
+}
+/* }}} end dom_element_get_elements_by_tag_name_ns_raw */
+
+
+/* {{{ void dom_normalize (xmlNodePtr nodep TSRMLS_DC) */
+void dom_normalize (xmlNodePtr nodep TSRMLS_DC)
+{
+ xmlNodePtr child, nextp;
+ xmlAttrPtr attr;
+ xmlChar *strContent;
+
+ child = nodep->children;
+ while(child != NULL) {
+ switch (child->type) {
+ case XML_TEXT_NODE:
+ nextp = child->next;
+ while (nextp != NULL) {
+ if (nextp->type == XML_TEXT_NODE) {
+ strContent = xmlNodeGetContent(nextp);
+ xmlNodeAddContent(child, strContent);
+ xmlFree(strContent);
+ xmlUnlinkNode(nextp);
+ node_free_resource(nextp TSRMLS_CC);
+ nextp = child->next;
+ }
+ }
+ break;
+ case XML_ELEMENT_NODE:
+ dom_normalize (child TSRMLS_CC);
+ attr = child->properties;
+ while (attr != NULL) {
+ dom_normalize((xmlNodePtr) attr TSRMLS_CC);
+ attr = attr->next;
+ }
+ break;
+ case XML_ATTRIBUTE_NODE:
+ dom_normalize (child TSRMLS_CC);
+ break;
+ default:
+ break;
+ }
+ child = child->next;
+ }
+}
+/* }}} end dom_normalize */
+
+
+/* {{{ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) */
+void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) {
+ xmlNs *cur;
+
+ if (doc == NULL)
+ return;
+
+ if (doc->oldNs == NULL) {
+ doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
+ if (doc->oldNs == NULL) {
+ return;
+ }
+ 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");
+ }
+
+ cur = doc->oldNs;
+ while (cur->next != NULL) {
+ cur = cur->next;
+ }
+ cur->next = ns;
+}
+/* }}} end dom_set_old_ns */
+
+
+/* {{{ xmlNsPtr dom_get_ns(char *uri, char *qName, int uri_len, int qName_len, int *errorcode, char *localname) */
+xmlNsPtr dom_get_ns(char *uri, char *qName, int uri_len, int qName_len, int *errorcode, char **localname) {
+ xmlNsPtr nsptr = NULL;
+ xmlURIPtr uristruct;
+ char *prefix = NULL;
+
+ *localname = NULL;
+ *errorcode = 0;
+
+ if (uri_len > 0 || qName_len > 0) {
+ if (qName_len == 0 && uri_len > 0) {
+ *errorcode = NAMESPACE_ERR;
+ return nsptr;
+ }
+ if (qName_len > 0 && *errorcode == 0) {
+ uristruct = xmlParseURI(qName);
+ if (uristruct->opaque != NULL) {
+ prefix = xmlStrdup(uristruct->scheme);
+ *localname = xmlStrdup(uristruct->opaque);
+ if (xmlStrchr(*localname, (xmlChar) ':') != NULL) {
+ *errorcode = NAMESPACE_ERR;
+ } else if (!strcmp (prefix, "xml") && strcmp(uri, XML_XML_NAMESPACE)) {
+ *errorcode = NAMESPACE_ERR;
+ }
+ }
+
+ /* TODO: Test that localname has no invalid chars
+ php_dom_throw_error(INVALID_CHARACTER_ERR, TSRMLS_CC);
+ */
+
+ xmlFreeURI(uristruct);
+
+ if (*errorcode == 0) {
+ if (uri_len > 0 && prefix == NULL) {
+ *errorcode = NAMESPACE_ERR;
+ } else if (*localname != NULL) {
+ nsptr = xmlNewNs(NULL, uri, prefix);
+ }
+ }
+ }
+ }
+
+ if (prefix != NULL) {
+ xmlFree(prefix);
+ }
+
+ return nsptr;
+
+}
+/* }}} end dom_get_ns */
+
+/* {{{ xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) */
+xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) {
+ xmlNsPtr cur;
+ xmlNs *ret = NULL;
+ if (node == NULL)
+ return NULL;
+
+ if (localName == NULL || xmlStrEqual(localName, "")) {
+ cur = node->nsDef;
+ while (cur != NULL) {
+ if (cur->prefix == NULL) {
+ ret = cur;
+ break;
+ }
+ cur = cur->next;
+ }
+ } else {
+ cur = node->nsDef;
+ while (cur != NULL) {
+ if (cur->prefix != NULL && xmlStrEqual(localName, cur->prefix)) {
+ ret = cur;
+ break;
+ }
+ cur = cur->next;
+ }
+ }
+ return ret;
+}
+/* }}} end dom_get_nsdecl */
+
+#endif /* HAVE_DOM */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
diff --git a/ext/dom/php_dom.h b/ext/dom/php_dom.h
new file mode 100644
index 0000000000..17fe94a5ad
--- /dev/null
+++ b/ext/dom/php_dom.h
@@ -0,0 +1,89 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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> |
+ | Marcus Borger <helly@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_DOM_H
+#define PHP_DOM_H
+
+#if HAVE_DOM
+#include <libxml/parser.h>
+#include <libxml/parserInternals.h>
+#include <libxml/tree.h>
+#include <libxml/uri.h>
+#include <libxml/xmlerror.h>
+#include <libxml/xinclude.h>
+#if defined(LIBXML_HTML_ENABLED)
+#include <libxml/HTMLparser.h>
+#include <libxml/HTMLtree.h>
+#endif
+#if defined(LIBXML_XPATH_ENABLED)
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+#endif
+#if defined(LIBXML_XPTR_ENABLED)
+#include <libxml/xpointer.h>
+#endif
+
+#include "xml_common.h"
+
+/* DOM API_VERSION, please bump it up, if you change anything in the API
+ therefore it's easier for the script-programmers to check, what's working how
+ Can be checked with phpversion("dom");
+*/
+#define DOM_API_VERSION "20030413"
+
+extern zend_module_entry dom_module_entry;
+
+#define dom_module_ptr &dom_module_entry
+
+#include "dom_fe.h"
+
+void php_dom_set_object(zval *wrapper, void *obj TSRMLS_DC);
+zval *dom_object_get_data(xmlNodePtr obj);
+void php_dom_throw_error(int error_code, zval **retval TSRMLS_DC);
+void node_free_resource(xmlNodePtr node TSRMLS_DC);
+void node_list_unlink(xmlNodePtr node TSRMLS_DC);
+void dom_del_from_list(xmlNodePtr nodep, xmlDocPtr docp TSRMLS_DC);
+void dom_add_to_list(xmlNodePtr nodep, xmlDocPtr docp TSRMLS_DC);
+xmlNsPtr dom_get_ns(char *uri, char *qName, int uri_len, int qName_len, int *errorcode, char **localname);
+void dom_set_old_ns(xmlDoc *doc, xmlNs *ns);
+xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName);
+void dom_normalize (xmlNodePtr nodep TSRMLS_DC);
+void dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, zval **retval TSRMLS_DC);
+void php_dom_create_implementation(zval **retval TSRMLS_DC);
+int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child);
+
+#define DOM_NO_ARGS() \
+ if (ZEND_NUM_ARGS() != 0) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expects exactly 0 parameters, %d given", ZEND_NUM_ARGS()); \
+ return; \
+ }
+
+PHP_MINIT_FUNCTION(dom);
+PHP_MSHUTDOWN_FUNCTION(dom);
+PHP_MINFO_FUNCTION(dom);
+#else
+#define dom_module_ptr NULL
+
+#endif /* HAVE_DOM */
+#define phpext_dom_ptr dom_module_ptr
+
+#endif /* _PHP_DIR_H */
diff --git a/ext/dom/processinginstruction.c b/ext/dom/processinginstruction.c
new file mode 100644
index 0000000000..7e83a37ae6
--- /dev/null
+++ b/ext/dom/processinginstruction.c
@@ -0,0 +1,138 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domprocessinginstruction extends domnode
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
+* Since:
+*/
+
+zend_function_entry php_dom_processinginstruction_class_functions[] = {
+ PHP_FALIAS("domprocessinginstruction", dom_processinginstruction_processinginstruction, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto domnode dom_processinginstruction_processinginstruction(string name, [string value]); */
+PHP_FUNCTION(dom_processinginstruction_processinginstruction)
+{
+
+ zval *id;
+ xmlNodePtr nodep = NULL, oldnode = NULL;
+ dom_object *intern;
+ char *name, *value = NULL;
+ int name_len, value_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ if (name_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "PI name is required");
+ RETURN_FALSE;
+ }
+
+ nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, nodep TSRMLS_CC);
+ }
+}
+/* }}} end dom_processinginstruction_processinginstruction */
+
+/* {{{ proto target string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
+Since:
+*/
+int dom_processinginstruction_target_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNodePtr nodep;
+
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, (char *) (nodep->name), 1);
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto data string
+readonly=no
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
+Since:
+*/
+int dom_processinginstruction_data_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ xmlNodePtr nodep;
+ xmlChar *content;
+
+ nodep = obj->ptr;
+
+ ALLOC_ZVAL(*retval);
+
+
+ if ((content = xmlNodeGetContent(nodep)) != NULL) {
+ ZVAL_STRING(*retval, content, 1);
+ } else {
+ ZVAL_EMPTY_STRING(*retval);
+ }
+
+ xmlFree(content);
+
+ return SUCCESS;
+}
+
+int dom_processinginstruction_data_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ xmlNode *nodep;
+
+ nodep = obj->ptr;
+ xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
+
+ return SUCCESS;
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/string_extend.c b/ext/dom/string_extend.c
new file mode 100644
index 0000000000..c71262ed25
--- /dev/null
+++ b/ext/dom/string_extend.c
@@ -0,0 +1,65 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domstringextend
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#i18n-methods-StringExtend
+* Since:
+*/
+
+zend_function_entry php_dom_string_extend_class_functions[] = {
+ PHP_FALIAS(findOffset16, dom_string_extend_find_offset16, NULL)
+ PHP_FALIAS(findOffset32, dom_string_extend_find_offset32, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+
+/* {{{ proto int dom_string_extend_find_offset16(int offset32);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#i18n-methods-StringExtend-findOffset16
+Since:
+*/
+PHP_FUNCTION(dom_string_extend_find_offset16)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_string_extend_find_offset16 */
+
+
+/* {{{ proto int dom_string_extend_find_offset32(int offset16);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#i18n-methods-StringExtend-findOffset32
+Since:
+*/
+PHP_FUNCTION(dom_string_extend_find_offset32)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_string_extend_find_offset32 */
diff --git a/ext/dom/tests/dom001.phpt b/ext/dom/tests/dom001.phpt
new file mode 100644
index 0000000000..cf3298db6d
--- /dev/null
+++ b/ext/dom/tests/dom001.phpt
@@ -0,0 +1,275 @@
+--TEST--
+Test 1: Accessing single node
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require_once("dom_test.inc");
+
+echo "Test 1: accessing single nodes from php\n";
+$dom = new domDocument;
+$dom->loadxml($xmlstr);
+if(!$dom) {
+ echo "Error while parsing the document\n";
+ exit;
+}
+
+// children() of of document would result in a memleak
+//$children = $dom->children();
+//print_node_list($children);
+
+echo "--------- root\n";
+$rootnode = $dom->documentElement;
+print_node($rootnode);
+
+echo "--------- children of root\n";
+$children = $rootnode->childNodes;
+print_node_list($children);
+
+// The last node should be identical with the last entry in the children array
+echo "--------- last\n";
+$last = $rootnode->lastChild;
+print_node($last);
+
+// The parent of this last node is the root again
+echo "--------- parent\n";
+$parent = $last->parentNode;
+print_node($parent);
+
+// The children of this parent are the same children as one above
+echo "--------- children of parent\n";
+$children = $parent->childNodes;
+print_node_list($children);
+
+echo "--------- creating a new attribute\n";
+//This is worthless
+//$attr = $dom->createAttribute("src", "picture.gif");
+//print_r($attr);
+
+//$rootnode->set_attributeNode($attr);
+$attr = $rootnode->setAttribute("src", "picture.gif");
+$attr = $rootnode->getAttribute("src");
+print_r($attr);
+print "\n";
+
+echo "--------- Get Attribute Node\n";
+$attr = $rootnode->getAttributeNode("src");
+print_node($attr);
+
+echo "--------- Remove Attribute Node\n";
+$attr = $rootnode->removeAttribute("src");
+print "Removed " . $attr . " attributes.\n";
+
+echo "--------- attributes of rootnode\n";
+$attrs = $rootnode->attributes;
+print_node_list($attrs);
+
+echo "--------- children of an attribute\n";
+$children = current($attrs)->childNodes;
+print_node_list($children);
+
+echo "--------- Add child to root\n";
+$myelement = new domElement("Silly", "Symphony");
+$newchild = $rootnode->appendChild($myelement);
+print_node($newchild);
+print $dom->saveXML();
+print "\n";
+
+echo "--------- Find element by tagname\n";
+echo " Using dom\n";
+$children = $dom->getElementsByTagname("Silly");
+print_node_list($children);
+
+echo " Using elem\n";
+$children = $rootnode->getElementsByTagName("Silly");
+print_node_list($children);
+
+echo "--------- Unlink Node\n";
+print_node($children[0]);
+$rootnode->removeChild($children[0]);
+print_node_list($rootnode->childNodes);
+print $dom->savexml();
+
+echo "--------- Find element by id\n";
+print ("Not implemented\n");
+
+echo "--------- Check various node_name return values\n";
+print ("Not needed\n");
+
+?>
+--EXPECT--
+Test 1: accessing single nodes from php
+--------- root
+Node Name: chapter
+Node Type: 1
+Num Children: 4
+
+--------- children of root
+Node Name: title
+Node Type: 1
+Num Children: 1
+Node Content: Title
+
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+Node Name: para
+Node Type: 1
+Num Children: 7
+
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+--------- last
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+--------- parent
+Node Name: chapter
+Node Type: 1
+Num Children: 4
+
+--------- children of parent
+Node Name: title
+Node Type: 1
+Num Children: 1
+Node Content: Title
+
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+Node Name: para
+Node Type: 1
+Num Children: 7
+
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+--------- creating a new attribute
+picture.gif
+--------- Get Attribute Node
+Node Name: src
+Node Type: 2
+Num Children: 1
+Node Content: picture.gif
+
+--------- Remove Attribute Node
+Removed 1 attributes.
+--------- attributes of rootnode
+Node Name: language
+Node Type: 2
+Num Children: 1
+Node Content: en
+
+--------- children of an attribute
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content: en
+
+--------- Add child to root
+Node Name: Silly
+Node Type: 1
+Num Children: 1
+Node Content: Symphony
+
+<?xml version="1.0" standalone="yes"?>
+<!DOCTYPE chapter SYSTEM "/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd" [
+<!ENTITY sp "spanish">
+]>
+<!-- lsfj -->
+<chapter language="en"><title language="en">Title</title>
+<para language="ge">
+&sp;
+<!-- comment -->
+<informaltable language="&sp;kkk">
+<tgroup cols="3">
+<tbody>
+<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
+<row><entry>a2</entry><entry>c2</entry></row>
+<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+</para>
+<Silly>Symphony</Silly></chapter>
+
+--------- Find element by tagname
+ Using dom
+Node Name: Silly
+Node Type: 1
+Num Children: 1
+Node Content: Symphony
+
+ Using elem
+Node Name: Silly
+Node Type: 1
+Num Children: 1
+Node Content: Symphony
+
+--------- Unlink Node
+Node Name: Silly
+Node Type: 1
+Num Children: 1
+Node Content: Symphony
+
+Node Name: title
+Node Type: 1
+Num Children: 1
+Node Content: Title
+
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+Node Name: para
+Node Type: 1
+Num Children: 7
+
+Node Name: #text
+Node Type: 3
+Num Children: 0
+Node Content:
+
+
+<?xml version="1.0" standalone="yes"?>
+<!DOCTYPE chapter SYSTEM "/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd" [
+<!ENTITY sp "spanish">
+]>
+<!-- lsfj -->
+<chapter language="en"><title language="en">Title</title>
+<para language="ge">
+&sp;
+<!-- comment -->
+<informaltable language="&sp;kkk">
+<tgroup cols="3">
+<tbody>
+<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
+<row><entry>a2</entry><entry>c2</entry></row>
+<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+</para>
+</chapter>
+--------- Find element by id
+Not implemented
+--------- Check various node_name return values
+Not needed
diff --git a/ext/dom/tests/dom_test.inc b/ext/dom/tests/dom_test.inc
new file mode 100644
index 0000000000..96acddc669
--- /dev/null
+++ b/ext/dom/tests/dom_test.inc
@@ -0,0 +1,43 @@
+<?PHP
+$xmlstr = "<?xml version='1.0' standalone='yes'?>
+<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
+[ <!ENTITY sp \"spanish\">
+]>
+<!-- lsfj -->
+<chapter language='en'><title language='en'>Title</title>
+<para language='ge'>
+&sp;
+<!-- comment -->
+<informaltable language='&sp;kkk'>
+<tgroup cols='3'>
+<tbody>
+<row><entry>a1</entry><entry morerows='1'>b1</entry><entry>c1</entry></row>
+<row><entry>a2</entry><entry>c2</entry></row>
+<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+</para>
+</chapter> ";
+
+function print_node($node)
+{
+ print "Node Name: " . $node->nodeName;
+ print "\nNode Type: " . $node->nodeType;
+ $child_count = count($node->childNodes);
+ print "\nNum Children: " . $child_count;
+ if($child_count <= 1){
+ print "\nNode Content: " . $node->nodeValue;
+ }
+ print "\n\n";
+}
+
+function print_node_list($nodelist)
+{
+ foreach($nodelist as $node)
+ {
+ print_node($node);
+ }
+}
+
+?>
diff --git a/ext/dom/tests/skipif.inc b/ext/dom/tests/skipif.inc
new file mode 100644
index 0000000000..08fd695d97
--- /dev/null
+++ b/ext/dom/tests/skipif.inc
@@ -0,0 +1 @@
+<?php if (!extension_loaded('dom')) die('skip dom extension not available');?> \ No newline at end of file
diff --git a/ext/dom/text.c b/ext/dom/text.c
new file mode 100644
index 0000000000..ddbbb73559
--- /dev/null
+++ b/ext/dom/text.c
@@ -0,0 +1,124 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domtext extends domcharacterdata
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1312295772
+* Since:
+*/
+
+zend_function_entry php_dom_text_class_functions[] = {
+ PHP_FALIAS(splitText, dom_text_split_text, NULL)
+ PHP_FALIAS(isWhitespaceInElementContent, dom_text_is_whitespace_in_element_content, NULL)
+ PHP_FALIAS(replaceWholeText, dom_text_replace_whole_text, NULL)
+ PHP_FALIAS(domtext, dom_text_text, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ proto domtext_text([string value]); */
+PHP_FUNCTION(dom_text_text)
+{
+
+ zval *id;
+ xmlNodePtr nodep = NULL, oldnode = NULL;
+ dom_object *intern;
+ char *value = NULL;
+ int value_len;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &value, &value_len) == FAILURE) {
+ return;
+ }
+
+ nodep = xmlNewText((xmlChar *) value);
+
+ if (!nodep)
+ RETURN_FALSE;
+
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ oldnode = (xmlNodePtr)intern->ptr;
+ if (oldnode != NULL) {
+ node_free_resource(oldnode TSRMLS_CC);
+ }
+ php_dom_set_object(id, nodep TSRMLS_CC);
+ }
+}
+/* }}} end dom_text_text */
+
+/* {{{ proto wholeText string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Text3-wholeText
+Since: DOM Level 3
+*/
+int dom_text_whole_text_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+
+/* {{{ proto domtext dom_text_split_text(unsigned long offset);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-38853C1D
+Since:
+*/
+PHP_FUNCTION(dom_text_split_text)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_text_split_text */
+
+
+/* {{{ proto boolean dom_text_is_whitespace_in_element_content();
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Text3-isWhitespaceInElementContent
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_text_is_whitespace_in_element_content)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_text_is_whitespace_in_element_content */
+
+
+/* {{{ proto domtext dom_text_replace_whole_text(string content);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Text3-replaceWholeText
+Since: DOM Level 3
+*/
+PHP_FUNCTION(dom_text_replace_whole_text)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_text_replace_whole_text */
diff --git a/ext/dom/typeinfo.c b/ext/dom/typeinfo.c
new file mode 100644
index 0000000000..0b0f21aaea
--- /dev/null
+++ b/ext/dom/typeinfo.c
@@ -0,0 +1,73 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domtypeinfo
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#TypeInfo
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_typeinfo_class_functions[] = {
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+/* {{{ proto type_name string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#TypeInfo-typeName
+Since:
+*/
+int dom_typeinfo_type_name_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
+
+/* {{{ proto type_namespace string
+readonly=yes
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#TypeInfo-typeNamespace
+Since:
+*/
+int dom_typeinfo_type_namespace_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_NULL(*retval);
+ return SUCCESS;
+}
+
+/* }}} */
+
+
diff --git a/ext/dom/userdatahandler.c b/ext/dom/userdatahandler.c
new file mode 100644
index 0000000000..6f96679bdc
--- /dev/null
+++ b/ext/dom/userdatahandler.c
@@ -0,0 +1,53 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | 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"
+#include "php_dom.h"
+
+
+/*
+* class domuserdatahandler
+*
+* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#UserDataHandler
+* Since: DOM Level 3
+*/
+
+zend_function_entry php_dom_userdatahandler_class_functions[] = {
+ PHP_FALIAS(handle, dom_userdatahandler_handle, NULL)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ attribute protos, not implemented yet */
+
+
+/* {{{ proto dom_void dom_userdatahandler_handle(unsigned short operation, string key, domobject data, node src, node dst);
+URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-handleUserDataEvent
+Since:
+*/
+PHP_FUNCTION(dom_userdatahandler_handle)
+{
+ DOM_NOT_IMPLEMENTED();
+}
+/* }}} end dom_userdatahandler_handle */
diff --git a/ext/dom/xml_common.h b/ext/dom/xml_common.h
new file mode 100644
index 0000000000..e3b7b18688
--- /dev/null
+++ b/ext/dom/xml_common.h
@@ -0,0 +1,82 @@
+#ifndef PHP_XML_COMMON_H
+#define PHP_XML_COMMON_H
+
+typedef struct _node_list_pointer {
+ xmlNodePtr nodep;
+ void *next;
+} node_list_pointer;
+
+typedef struct _dom_object {
+ zend_object std;
+ void *ptr;
+ HashTable *prop_handler;
+ node_list_pointer *node_list;
+} dom_object;
+
+#ifdef PHP_WIN32
+#ifdef PHPAPI
+#undef PHPAPI
+#endif
+#ifdef DOM_EXPORTS
+#define PHPAPI __declspec(dllexport)
+#else
+#define PHPAPI __declspec(dllimport)
+#endif /* DOM_EXPORTS */
+#endif /* PHP_WIN32 */
+
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+
+#define PHP_DOM_EXPORT(__type) PHPAPI __type
+
+PHP_DOM_EXPORT(zval *) php_dom_create_object(xmlNodePtr obj, int *found, zval* in, zval* return_value TSRMLS_DC);
+PHP_DOM_EXPORT(void) dom_objects_clone(void *object, void **object_clone TSRMLS_DC);
+void dom_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC);
+PHP_DOM_EXPORT(zval *) dom_read_property(zval *object, zval *member TSRMLS_DC);
+PHP_DOM_EXPORT(void) dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC);
+zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC);
+void dom_unregister_node(xmlNodePtr nodep TSRMLS_DC);
+zend_object_handlers dom_object_handlers;
+
+#define DOM_XMLNS_NAMESPACE \
+ (const xmlChar *) "http://www.w3.org/2000/xmlns/"
+
+#define DOM_NOT_IMPLEMENTED() \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not yet implemented"); \
+ return;
+
+#define REGISTER_DOM_CLASS(ce, name, parent_ce, funcs, entry) \
+INIT_CLASS_ENTRY(ce, name, funcs); \
+ce.create_object = dom_objects_new; \
+entry = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC);
+/* entry = zend_register_internal_ns_class(&ce, parent_ce, ns, NULL TSRMLS_CC); */
+
+#define DOM_GET_OBJ(__ptr, __id, __prtype) { \
+ dom_object *intern = (dom_object *)zend_object_store_get_object(__id TSRMLS_CC); \
+ if (!(__ptr = (__prtype)intern->ptr)) { \
+ php_error(E_WARNING, "Couldn't fetch %s", intern->std.ce->name);\
+ RETURN_NULL();\
+ } \
+}
+
+#define DOM_DOMOBJ_NEW(zval, obj, ret) \
+ if (NULL == (zval = php_dom_create_object(obj, ret, zval, return_value TSRMLS_CC))) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object"); \
+ RETURN_FALSE; \
+ }
+
+#define DOM_RET_OBJ(zval, obj, ret) \
+ DOM_DOMOBJ_NEW(zval, obj, ret);
+
+#define DOM_GET_THIS(zval) \
+ if (NULL == (zval = getThis())) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Underlying object missing"); \
+ RETURN_FALSE; \
+ }
+
+#define DOM_GET_THIS_OBJ(__ptr, __id, __prtype) \
+ DOM_GET_THIS(__id); \
+ DOM_GET_OBJ(__ptr, __id, __prtype);
+
+#endif