summaryrefslogtreecommitdiff
path: root/ext/dom
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:34:59 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:34:59 -0400
commitce7edc9b3c7370f32fec0bc7a8ec3e29ed9a5f61 (patch)
treeacdb9a8816483652a9db1a47db71df5df43707c5 /ext/dom
parent10f5b47dc7c1cf2b9a00991629f43652710322d3 (diff)
downloadphp-ce7edc9b3c7370f32fec0bc7a8ec3e29ed9a5f61.tar.gz
Imported Upstream version 5.1.1upstream/5.1.1
Diffstat (limited to 'ext/dom')
-rw-r--r--ext/dom/attr.c6
-rw-r--r--ext/dom/cdatasection.c4
-rw-r--r--ext/dom/characterdata.c4
-rw-r--r--ext/dom/comment.c4
-rw-r--r--ext/dom/config.m48
-rw-r--r--ext/dom/document.c193
-rw-r--r--ext/dom/documentfragment.c75
-rw-r--r--ext/dom/documenttype.c4
-rw-r--r--ext/dom/dom_ce.h4
-rw-r--r--ext/dom/dom_fe.h6
-rw-r--r--ext/dom/dom_iterators.c4
-rw-r--r--ext/dom/dom_properties.h6
-rw-r--r--ext/dom/domconfiguration.c4
-rw-r--r--ext/dom/domerror.c4
-rw-r--r--ext/dom/domerrorhandler.c4
-rw-r--r--ext/dom/domexception.c20
-rw-r--r--ext/dom/domimplementation.c6
-rw-r--r--ext/dom/domimplementationlist.c4
-rw-r--r--ext/dom/domimplementationsource.c4
-rw-r--r--ext/dom/domlocator.c4
-rw-r--r--ext/dom/domstringlist.c4
-rw-r--r--ext/dom/element.c69
-rw-r--r--ext/dom/entity.c4
-rw-r--r--ext/dom/entityreference.c4
-rw-r--r--ext/dom/namednodemap.c7
-rw-r--r--ext/dom/namelist.c4
-rw-r--r--ext/dom/node.c18
-rw-r--r--ext/dom/nodelist.c7
-rw-r--r--ext/dom/notation.c4
-rw-r--r--ext/dom/php_dom.c74
-rw-r--r--ext/dom/php_dom.h7
-rw-r--r--ext/dom/processinginstruction.c4
-rw-r--r--ext/dom/string_extend.c4
-rw-r--r--ext/dom/tests/bug34276.phpt43
-rw-r--r--ext/dom/tests/bug35342.phpt17
-rw-r--r--ext/dom/tests/dom002.phpt2
-rw-r--r--ext/dom/tests/dom003.phpt2
-rw-r--r--ext/dom/tests/dom005.phpt10
-rw-r--r--ext/dom/tests/dom_set_attr_node.phpt67
-rw-r--r--ext/dom/tests/dom_xinclude.phpt15
-rw-r--r--ext/dom/text.c5
-rw-r--r--ext/dom/typeinfo.c4
-rw-r--r--ext/dom/userdatahandler.c4
-rw-r--r--ext/dom/xml_common.h13
-rw-r--r--ext/dom/xpath.c135
45 files changed, 667 insertions, 228 deletions
diff --git a/ext/dom/attr.c b/ext/dom/attr.c
index 530c99f24..129da423d 100644
--- a/ext/dom/attr.c
+++ b/ext/dom/attr.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: attr.c,v 1.15.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: attr.c,v 1.18 2005/08/03 14:06:58 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -225,7 +225,7 @@ int dom_attr_owner_element_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(nodeparent, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
diff --git a/ext/dom/cdatasection.c b/ext/dom/cdatasection.c
index 0429e7638..2410dbc57 100644
--- a/ext/dom/cdatasection.c
+++ b/ext/dom/cdatasection.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cdatasection.c,v 1.10 2004/05/31 12:50:28 rrichards Exp $ */
+/* $Id: cdatasection.c,v 1.11 2005/08/03 14:06:59 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/characterdata.c b/ext/dom/characterdata.c
index 8ebec1c06..afb46e302 100644
--- a/ext/dom/characterdata.c
+++ b/ext/dom/characterdata.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: characterdata.c,v 1.13.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: characterdata.c,v 1.15 2005/08/03 14:06:59 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/comment.c b/ext/dom/comment.c
index c3ba1cb97..884527be6 100644
--- a/ext/dom/comment.c
+++ b/ext/dom/comment.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: comment.c,v 1.10 2004/05/31 12:50:28 rrichards Exp $ */
+/* $Id: comment.c,v 1.11 2005/08/03 14:06:59 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/config.m4 b/ext/dom/config.m4
index 3be333ef6..74af8d037 100644
--- a/ext/dom/config.m4
+++ b/ext/dom/config.m4
@@ -1,13 +1,13 @@
dnl
-dnl $Id: config.m4,v 1.15.2.1 2005/04/27 13:13:37 sniper Exp $
+dnl $Id: config.m4,v 1.20 2005/05/29 23:16:40 sniper Exp $
dnl
PHP_ARG_ENABLE(dom, whether to enable DOM support,
-[ --disable-dom Disable new DOM support.], yes)
+[ --disable-dom Disable new DOM support], yes)
if test -z "$PHP_LIBXML_DIR"; then
PHP_ARG_WITH(libxml-dir, libxml2 install dir,
- [ --with-libxml-dir[=DIR] DOM: libxml2 install prefix.], no, no)
+ [ --with-libxml-dir[=DIR] DOM: libxml2 install prefix], no, no)
fi
if test "$PHP_DOM" != "no"; then
@@ -30,6 +30,8 @@ if test "$PHP_DOM" != "no"; then
typeinfo.c domerror.c domlocator.c namednodemap.c userdatahandler.c],
$ext_shared)
PHP_SUBST(DOM_SHARED_LIBADD)
+ PHP_INSTALL_HEADERS([ext/dom/xml_common.h])
+ PHP_ADD_EXTENSION_DEP(dom, libxml)
], [
AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.])
])
diff --git a/ext/dom/document.c b/ext/dom/document.c
index aa81e16ce..42b6e3f1e 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: document.c,v 1.55.2.3 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: document.c,v 1.68.2.2 2005/09/08 10:39:30 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -113,7 +113,7 @@ int dom_document_doctype_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object((xmlNodePtr) dtdptr, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -165,7 +165,7 @@ int dom_document_document_element_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(root, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -173,28 +173,6 @@ int dom_document_document_element_read(dom_object *obj, zval **retval TSRMLS_DC)
/* }}} */
-
-/* {{{ actualEncoding 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;
-}
-*/
-
-/* }}} */
-
/* {{{ 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
@@ -614,6 +592,48 @@ int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval TSRMLS_
}
/* }}} */
+/* {{{ recover boolean
+readonly=no
+*/
+int dom_document_recover_read(dom_object *obj, zval **retval TSRMLS_DC)
+{
+ dom_doc_props *doc_prop;
+
+ ALLOC_ZVAL(*retval);
+ if (obj->document) {
+ doc_prop = dom_get_doc_props(obj->document);
+ ZVAL_BOOL(*retval, doc_prop->recover);
+ } else {
+ ZVAL_FALSE(*retval);
+ }
+ return SUCCESS;
+}
+
+int dom_document_recover_write(dom_object *obj, zval *newval TSRMLS_DC)
+{
+ zval value_copy;
+ dom_doc_props *doc_prop;
+
+ if(newval->refcount > 1) {
+ value_copy = *newval;
+ zval_copy_ctor(&value_copy);
+ newval = &value_copy;
+ }
+ convert_to_boolean(newval);
+
+ if (obj->document) {
+ doc_prop = dom_get_doc_props(obj->document);
+ doc_prop->recover = Z_LVAL_P(newval);
+ }
+
+ if (newval == &value_copy) {
+ zval_dtor(newval);
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ substituteEntities boolean
readonly=no
@@ -1056,6 +1076,7 @@ PHP_FUNCTION(dom_document_import_node)
if (!retnodep) {
RETURN_FALSE;
}
+
}
DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret, intern);
@@ -1386,14 +1407,15 @@ char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_p
/* {{{ */
-static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC) {
+static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int options TSRMLS_DC) {
xmlDocPtr ret;
xmlParserCtxtPtr ctxt = NULL;
dom_doc_props *doc_props;
dom_object *intern;
php_libxml_ref_obj *document = NULL;
- int validate, resolve_externals, keep_blanks, substitute_ent;
+ int validate, recover, resolve_externals, keep_blanks, substitute_ent;
int resolved_path_len;
+ int old_error_reporting;
char *directory=NULL, resolved_path[MAXPATHLEN];
if (id != NULL) {
@@ -1406,6 +1428,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
resolve_externals = doc_props->resolveexternals;
keep_blanks = doc_props->preservewhitespace;
substitute_ent = doc_props->substituteentities;
+ recover = doc_props->recover;
if (document == NULL) {
efree(doc_props);
@@ -1413,7 +1436,9 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
xmlInitParser();
+#if LIBXML_VERSION < 20600
keep_blanks = xmlKeepBlanksDefault(keep_blanks);
+#endif
if (mode == DOM_LOAD_FILE) {
char *file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
@@ -1425,11 +1450,13 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
ctxt = xmlCreateDocParserCtxt(source);
}
+#if LIBXML_VERSION < 20600
xmlKeepBlanksDefault(keep_blanks);
/* xmlIndentTreeOutput default is changed in xmlKeepBlanksDefault
reset back to 1 which is default value */
xmlIndentTreeOutput = 1;
+#endif
if (ctxt == NULL) {
return(NULL);
@@ -1455,11 +1482,6 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
}
}
- ctxt->recovery = 0;
- ctxt->validate = validate;
- ctxt->loadsubset = (resolve_externals * XML_COMPLETE_ATTRS);
- ctxt->replaceEntities = substitute_ent;
-
ctxt->vctxt.error = php_libxml_ctx_error;
ctxt->vctxt.warning = php_libxml_ctx_warning;
@@ -1468,10 +1490,40 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
ctxt->sax->warning = php_libxml_ctx_warning;
}
+#if LIBXML_VERSION >= 20600
+ if (validate && ! (options & XML_PARSE_DTDVALID)) {
+ options |= XML_PARSE_DTDVALID;
+ }
+ if (resolve_externals && ! (options & XML_PARSE_DTDATTR)) {
+ options |= XML_PARSE_DTDATTR;
+ }
+ if (substitute_ent && ! (options & XML_PARSE_NOENT)) {
+ options |= XML_PARSE_NOENT;
+ }
+ if (keep_blanks == 0 && ! (options & XML_PARSE_NOBLANKS)) {
+ options |= XML_PARSE_NOBLANKS;
+ }
+
+ xmlCtxtUseOptions(ctxt, options);
+#else
+ ctxt->validate = validate;
+ ctxt->loadsubset = (resolve_externals * XML_COMPLETE_ATTRS);
+ ctxt->replaceEntities = substitute_ent;
+#endif
+
+ ctxt->recovery = recover;
+ if (recover) {
+ old_error_reporting = EG(error_reporting);
+ EG(error_reporting) = old_error_reporting | E_WARNING;
+ }
+
xmlParseDocument(ctxt);
- if (ctxt->wellFormed) {
+ if (ctxt->wellFormed || recover) {
ret = ctxt->myDoc;
+ if (ctxt->recovery) {
+ EG(error_reporting) = old_error_reporting;
+ }
/* If loading from memory, set the base reference uri for the document */
if (ret->URL == NULL && ctxt->directory != NULL) {
ret->URL = xmlStrdup(ctxt->directory);
@@ -1496,13 +1548,14 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
dom_object *intern;
char *source;
int source_len, refcount, ret;
+ long options = 0;
id = getThis();
if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), dom_document_class_entry TSRMLS_CC)) {
id = NULL;
}
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &options) == FAILURE) {
return;
}
@@ -1511,7 +1564,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
RETURN_FALSE;
}
- newdoc = dom_document_parser(id, mode, source TSRMLS_CC);
+ newdoc = dom_document_parser(id, mode, source, options TSRMLS_CC);
if (!newdoc)
RETURN_FALSE;
@@ -1544,7 +1597,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
}
/* }}} end dom_parser_document */
-/* {{{ proto DOMNode dom_document_load(string source);
+/* {{{ proto DOMNode dom_document_load(string source [, int options]);
URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
Since: DOM Level 3
*/
@@ -1554,7 +1607,7 @@ PHP_METHOD(domdocument, load)
}
/* }}} end dom_document_load */
-/* {{{ proto DOMNode dom_document_loadxml(string source);
+/* {{{ proto DOMNode dom_document_loadxml(string source [, int options]);
URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-loadXML
Since: DOM Level 3
*/
@@ -1571,17 +1624,18 @@ PHP_FUNCTION(dom_document_save)
{
zval *id;
xmlDoc *docp;
- int file_len = 0, bytes, format;
+ int file_len = 0, bytes, format, saveempty;
dom_object *intern;
dom_doc_props *doc_props;
char *file;
+ long options = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l", &id, dom_document_class_entry, &file, &file_len, &options) == FAILURE) {
return;
}
if (file_len == 0) {
- php_error(E_WARNING, "Invalid Filename");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Filename");
RETURN_FALSE;
}
@@ -1591,8 +1645,14 @@ PHP_FUNCTION(dom_document_save)
doc_props = dom_get_doc_props(intern->document);
format = doc_props->formatoutput;
+ if (options & LIBXML_SAVE_NOEMPTYTAG) {
+ saveempty = xmlSaveNoEmptyTags;
+ xmlSaveNoEmptyTags = 1;
+ }
bytes = xmlSaveFormatFileEnc(file, docp, NULL, format);
-
+ if (options & LIBXML_SAVE_NOEMPTYTAG) {
+ xmlSaveNoEmptyTags = saveempty;
+ }
if (bytes == -1) {
RETURN_FALSE;
}
@@ -1613,9 +1673,10 @@ PHP_FUNCTION(dom_document_savexml)
xmlChar *mem;
dom_object *intern, *nodeobj;
dom_doc_props *doc_props;
- int size, format;
+ int size, format, saveempty;
+ long options = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O", &id, dom_document_class_entry, &nodep, dom_node_class_entry) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
return;
}
@@ -1633,21 +1694,34 @@ PHP_FUNCTION(dom_document_savexml)
}
buf = xmlBufferCreate();
if (!buf) {
- php_error(E_WARNING, "Could not fetch buffer");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch buffer");
RETURN_FALSE;
}
-
+ if (options & LIBXML_SAVE_NOEMPTYTAG) {
+ saveempty = xmlSaveNoEmptyTags;
+ xmlSaveNoEmptyTags = 1;
+ }
xmlNodeDump(buf, docp, node, 0, format);
+ if (options & LIBXML_SAVE_NOEMPTYTAG) {
+ xmlSaveNoEmptyTags = saveempty;
+ }
mem = (xmlChar*) xmlBufferContent(buf);
if (!mem) {
xmlBufferFree(buf);
RETURN_FALSE;
}
- RETVAL_STRING(mem, 1);
+ RETVAL_STRING(mem, 1);
xmlBufferFree(buf);
} else {
+ if (options & LIBXML_SAVE_NOEMPTYTAG) {
+ saveempty = xmlSaveNoEmptyTags;
+ xmlSaveNoEmptyTags = 1;
+ }
/* Encoding is handled from the encoding property set on the document */
xmlDocDumpFormatMemory(docp, &mem, &size, format);
+ if (options & LIBXML_SAVE_NOEMPTYTAG) {
+ xmlSaveNoEmptyTags = saveempty;
+ }
if (!size) {
RETURN_FALSE;
}
@@ -1690,23 +1764,28 @@ static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) {
}
}
-/* {{{ proto int dom_document_xinclude()
+/* {{{ proto int dom_document_xinclude([int options])
Substitutues xincludes in a DomDocument */
PHP_FUNCTION(dom_document_xinclude)
{
zval *id;
xmlDoc *docp;
xmlNodePtr root;
- int err;
+ long flags = 0;
+ int err;
dom_object *intern;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &id, dom_document_class_entry, &flags) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
+#if LIBXML_VERSION >= 20607
+ err = xmlXIncludeProcessFlags(docp, flags);
+#else
err = xmlXIncludeProcess (docp);
+#endif
/* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
@@ -1786,7 +1865,7 @@ _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
}
if (source_len == 0) {
- php_error(E_WARNING, "Invalid Schema source");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema source");
RETURN_FALSE;
}
@@ -1796,7 +1875,7 @@ _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
case DOM_LOAD_FILE:
valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
if (!valid_file) {
- php_error(E_WARNING, "Invalid Schema file source");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema file source");
RETURN_FALSE;
}
parser = xmlSchemaNewParserCtxt(valid_file);
@@ -1817,7 +1896,7 @@ _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
sptr = xmlSchemaParse(parser);
xmlSchemaFreeParserCtxt(parser);
if (!sptr) {
- php_error(E_WARNING, "Invalid Schema");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema");
RETURN_FALSE;
}
@@ -1876,7 +1955,7 @@ _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
}
if (source_len == 0) {
- php_error(E_WARNING, "Invalid Schema source");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema source");
RETURN_FALSE;
}
@@ -1886,7 +1965,7 @@ _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
case DOM_LOAD_FILE:
valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
if (!valid_file) {
- php_error(E_WARNING, "Invalid RelaxNG file source");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid RelaxNG file source");
RETURN_FALSE;
}
parser = xmlRelaxNGNewParserCtxt(valid_file);
@@ -1907,7 +1986,7 @@ _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
sptr = xmlRelaxNGParse(parser);
xmlRelaxNGFreeParserCtxt(parser);
if (!sptr) {
- php_error(E_WARNING, "Invalid RelaxNG");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid RelaxNG");
RETURN_FALSE;
}
@@ -2057,7 +2136,7 @@ PHP_FUNCTION(dom_document_save_html_file)
}
if (file_len == 0) {
- php_error(E_WARNING, "Invalid Filename");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Filename");
RETURN_FALSE;
}
diff --git a/ext/dom/documentfragment.c b/ext/dom/documentfragment.c
index b7ce96890..4c57c69f1 100644
--- a/ext/dom/documentfragment.c
+++ b/ext/dom/documentfragment.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: documentfragment.c,v 1.11 2004/05/31 12:50:28 rrichards Exp $ */
+/* $Id: documentfragment.c,v 1.15 2005/08/03 14:07:00 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -37,6 +37,7 @@
zend_function_entry php_dom_documentfragment_class_functions[] = {
PHP_ME(domdocumentfragment, __construct, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(domdocumentfragment, appendXML, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
@@ -73,4 +74,74 @@ PHP_METHOD(domdocumentfragment, __construct)
}
}
/* }}} end DOMDocumentFragment::__construct */
+
+/* php_dom_xmlSetTreeDoc is a custom implementation of xmlSetTreeDoc
+ needed for hack in appendXML due to libxml bug - no need to share this function */
+static void php_dom_xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) {
+ xmlAttrPtr prop;
+ xmlNodePtr cur;
+
+ if (tree) {
+ if(tree->type == XML_ELEMENT_NODE) {
+ prop = tree->properties;
+ while (prop != NULL) {
+ prop->doc = doc;
+ if (prop->children) {
+ cur = prop->children;
+ while (cur != NULL) {
+ php_dom_xmlSetTreeDoc(cur, doc);
+ cur = cur->next;
+ }
+ }
+ prop = prop->next;
+ }
+ }
+ if (tree->children != NULL) {
+ cur = tree->children;
+ while (cur != NULL) {
+ php_dom_xmlSetTreeDoc(cur, doc);
+ cur = cur->next;
+ }
+ }
+ tree->doc = doc;
+ }
+}
+
+/* {{{ proto void DOMDocumentFragment::appendXML(string data); */
+PHP_METHOD(domdocumentfragment, appendXML) {
+ zval *id;
+ xmlNode *nodep;
+ dom_object *intern;
+ char *data = NULL;
+ int data_len = 0;
+ int err;
+ xmlNodePtr lst;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_documentfragment_class_entry, &data, &data_len) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
+
+ if (dom_node_is_read_only(nodep) == SUCCESS) {
+ php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ if (data) {
+ err = xmlParseBalancedChunkMemory(nodep->doc, NULL, NULL, 0, data, &lst);
+ if (err != 0) {
+ RETURN_FALSE;
+ }
+ /* Following needed due to bug in libxml2 <= 2.6.14
+ ifdef after next libxml release as bug is fixed in their cvs */
+ php_dom_xmlSetTreeDoc(lst, nodep->doc);
+ /* End stupid hack */
+
+ xmlAddChildList(nodep,lst);
+ }
+
+ RETURN_TRUE;
+}
+
#endif
diff --git a/ext/dom/documenttype.c b/ext/dom/documenttype.c
index 8363cb950..51b4453c4 100644
--- a/ext/dom/documenttype.c
+++ b/ext/dom/documenttype.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: documenttype.c,v 1.12.2.2 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: documenttype.c,v 1.15 2005/08/03 14:07:00 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/dom_ce.h b/ext/dom/dom_ce.h
index 2d3e93e26..6af4b19b4 100644
--- a/ext/dom/dom_ce.h
+++ b/ext/dom/dom_ce.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dom_ce.h,v 1.6.2.1 2005/06/22 19:58:33 rrichards Exp $ */
+/* $Id: dom_ce.h,v 1.8 2005/08/03 14:07:01 sniper Exp $ */
#ifndef DOM_CE_H
#define DOM_CE_H
diff --git a/ext/dom/dom_fe.h b/ext/dom/dom_fe.h
index 8ee8204cc..7d62b638a 100644
--- a/ext/dom/dom_fe.h
+++ b/ext/dom/dom_fe.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dom_fe.h,v 1.11 2004/05/16 10:30:16 rrichards Exp $ */
+/* $Id: dom_fe.h,v 1.14 2005/08/03 14:07:01 sniper Exp $ */
#ifndef DOM_FE_H
#define DOM_FE_H
@@ -102,6 +102,7 @@ PHP_METHOD(domimplementation, getFeature);
/* domdocumentfragment methods */
PHP_METHOD(domdocumentfragment, __construct);
+PHP_METHOD(domdocumentfragment, appendXML);
/* domdocument methods */
PHP_FUNCTION(dom_document_create_element);
@@ -258,6 +259,7 @@ PHP_FUNCTION(dom_string_extend_find_offset32);
PHP_METHOD(domxpath, __construct);
PHP_FUNCTION(dom_xpath_register_ns);
PHP_FUNCTION(dom_xpath_query);
+PHP_FUNCTION(dom_xpath_evaluate);
#endif
#endif /* DOM_FE_H */
diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c
index 596f7dfd3..694392e99 100644
--- a/ext/dom/dom_iterators.c
+++ b/ext/dom/dom_iterators.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dom_iterators.c,v 1.8 2004/03/08 21:15:39 helly Exp $ */
+/* $Id: dom_iterators.c,v 1.9 2005/08/03 14:07:01 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/dom_properties.h b/ext/dom/dom_properties.h
index 8af5a8b0e..d0fbcd159 100644
--- a/ext/dom/dom_properties.h
+++ b/ext/dom/dom_properties.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dom_properties.h,v 1.5 2004/01/08 17:32:03 sniper Exp $ */
+/* $Id: dom_properties.h,v 1.7 2005/08/03 14:07:01 sniper Exp $ */
#ifndef DOM_PROPERTIES_H
#define DOM_PROPERTIES_H
@@ -59,6 +59,8 @@ int dom_document_resolve_externals_read(dom_object *obj, zval **retval TSRMLS_DC
int dom_document_resolve_externals_write(dom_object *obj, zval *newval TSRMLS_DC);
int dom_document_preserve_whitespace_read(dom_object *obj, zval **retval TSRMLS_DC);
int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval TSRMLS_DC);
+int dom_document_recover_read(dom_object *obj, zval **retval TSRMLS_DC);
+int dom_document_recover_write(dom_object *obj, zval *newval TSRMLS_DC);
int dom_document_substitue_entities_read(dom_object *obj, zval **retval TSRMLS_DC);
int dom_document_substitue_entities_write(dom_object *obj, zval *newval TSRMLS_DC);
diff --git a/ext/dom/domconfiguration.c b/ext/dom/domconfiguration.c
index 1c80aa804..7a4bd7f04 100644
--- a/ext/dom/domconfiguration.c
+++ b/ext/dom/domconfiguration.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domconfiguration.c,v 1.4 2004/01/08 08:15:16 andi Exp $ */
+/* $Id: domconfiguration.c,v 1.5 2005/08/03 14:07:02 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/domerror.c b/ext/dom/domerror.c
index c4fd80b61..57c62d788 100644
--- a/ext/dom/domerror.c
+++ b/ext/dom/domerror.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domerror.c,v 1.4.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: domerror.c,v 1.6 2005/08/03 14:07:02 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/domerrorhandler.c b/ext/dom/domerrorhandler.c
index f2a84013f..d670d6ed9 100644
--- a/ext/dom/domerrorhandler.c
+++ b/ext/dom/domerrorhandler.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domerrorhandler.c,v 1.4 2004/01/08 08:15:16 andi Exp $ */
+/* $Id: domerrorhandler.c,v 1.5 2005/08/03 14:07:02 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/domexception.c b/ext/dom/domexception.c
index 7e5b8c6bf..a48953d39 100644
--- a/ext/dom/domexception.c
+++ b/ext/dom/domexception.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domexception.c,v 1.9 2004/05/31 12:50:28 rrichards Exp $ */
+/* $Id: domexception.c,v 1.11 2005/08/03 14:07:02 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -41,6 +41,16 @@ zend_function_entry php_dom_domexception_class_functions[] = {
{NULL, NULL, NULL}
};
+/* {{{ php_dom_throw_error_with_message */
+void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error TSRMLS_DC)
+{
+ if (strict_error == 1) {
+ zend_throw_exception(dom_domexception_class_entry, error_message, error_code TSRMLS_CC);
+ } else {
+ php_libxml_issue_error(E_WARNING, error_message TSRMLS_CC);
+ }
+}
+
/* {{{ php_dom_throw_error */
void php_dom_throw_error(int error_code, int strict_error TSRMLS_DC)
{
@@ -100,11 +110,7 @@ void php_dom_throw_error(int error_code, int strict_error TSRMLS_DC)
error_message = "Unhandled Error";
}
- if (strict_error == 1) {
- zend_throw_exception(dom_domexception_class_entry, error_message, error_code TSRMLS_CC);
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error_message);
- }
+ php_dom_throw_error_with_message(error_code, error_message, strict_error TSRMLS_CC);
}
/* }}} end php_dom_throw_error */
diff --git a/ext/dom/domimplementation.c b/ext/dom/domimplementation.c
index 7c01b77af..970c5e5a9 100644
--- a/ext/dom/domimplementation.c
+++ b/ext/dom/domimplementation.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domimplementation.c,v 1.13 2004/05/31 12:50:28 rrichards Exp $ */
+/* $Id: domimplementation.c,v 1.15 2005/08/03 14:07:02 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -201,7 +201,7 @@ PHP_METHOD(domimplementation, createDocument)
xmlFreeDoc(docp);
xmlFree(localname);
/* Need some type of error here */
- php_error(E_WARNING, "Unexpected Error");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error");
RETURN_FALSE;
}
diff --git a/ext/dom/domimplementationlist.c b/ext/dom/domimplementationlist.c
index 6463216c3..f0c25f9cb 100644
--- a/ext/dom/domimplementationlist.c
+++ b/ext/dom/domimplementationlist.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domimplementationlist.c,v 1.4.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: domimplementationlist.c,v 1.6 2005/08/03 14:07:03 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/domimplementationsource.c b/ext/dom/domimplementationsource.c
index 1db0e41bd..bdd3cc34f 100644
--- a/ext/dom/domimplementationsource.c
+++ b/ext/dom/domimplementationsource.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domimplementationsource.c,v 1.4 2004/01/08 08:15:16 andi Exp $ */
+/* $Id: domimplementationsource.c,v 1.5 2005/08/03 14:07:03 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/domlocator.c b/ext/dom/domlocator.c
index b6779d4e1..8793ac443 100644
--- a/ext/dom/domlocator.c
+++ b/ext/dom/domlocator.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domlocator.c,v 1.4.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: domlocator.c,v 1.6 2005/08/03 14:07:03 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/domstringlist.c b/ext/dom/domstringlist.c
index 158e8a34a..a8c2b23f0 100644
--- a/ext/dom/domstringlist.c
+++ b/ext/dom/domstringlist.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domstringlist.c,v 1.4.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: domstringlist.c,v 1.6 2005/08/03 14:07:03 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/element.c b/ext/dom/element.c
index 3a43a32a7..d2a06c7d5 100644
--- a/ext/dom/element.c
+++ b/ext/dom/element.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: element.c,v 1.30.2.4 2005/05/20 15:02:48 rrichards Exp $ */
+/* $Id: element.c,v 1.36.2.2 2005/10/27 23:51:22 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -368,6 +368,11 @@ PHP_FUNCTION(dom_element_set_attribute_node)
RETURN_FALSE;
}
+ if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
existattrp = xmlHasProp(nodep, attrp->name);
if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL &&
@@ -501,6 +506,42 @@ PHP_FUNCTION(dom_element_get_attribute_ns)
}
/* }}} end dom_element_get_attribute_ns */
+static xmlNsPtr _dom_new_reconNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
+ xmlNsPtr def;
+ xmlChar prefix[50];
+ int counter = 1;
+
+ if ((tree == NULL) || (ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
+ return NULL;
+ }
+
+ /* Code taken from libxml2 (2.6.20) xmlNewReconciliedNs
+ *
+ * Find a close prefix which is not already in use.
+ * Let's strip namespace prefixes longer than 20 chars !
+ */
+ if (ns->prefix == NULL)
+ snprintf((char *) prefix, sizeof(prefix), "default");
+ else
+ snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix);
+
+ def = xmlSearchNs(doc, tree, prefix);
+ while (def != NULL) {
+ if (counter > 1000) return(NULL);
+ if (ns->prefix == NULL)
+ snprintf((char *) prefix, sizeof(prefix), "default%d", counter++);
+ else
+ snprintf((char *) prefix, sizeof(prefix), "%.20s%d",
+ (char *)ns->prefix, counter++);
+ def = xmlSearchNs(doc, tree, prefix);
+ }
+
+ /*
+ * OK, now we are ready to create a new one.
+ */
+ def = xmlNewNs(tree, ns->href, prefix);
+ return(def);
+}
/* {{{ proto 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
@@ -550,8 +591,21 @@ PHP_FUNCTION(dom_element_set_attribute_ns)
nsptr = dom_get_nsdecl(elemp, localname);
} else {
nsptr = xmlSearchNsByHref(elemp->doc, elemp, uri);
- while (nsptr && nsptr->prefix == NULL) {
- nsptr = nsptr->next;
+ if (nsptr && nsptr->prefix == NULL) {
+ xmlNsPtr tmpnsptr;
+
+ tmpnsptr = nsptr->next;
+ while (tmpnsptr) {
+ if ((tmpnsptr->prefix != NULL) && (tmpnsptr->href != NULL) &&
+ (xmlStrEqual(tmpnsptr->href, (xmlChar *) uri))) {
+ nsptr = tmpnsptr;
+ break;
+ }
+ tmpnsptr = tmpnsptr->next;
+ }
+ if (tmpnsptr == NULL) {
+ nsptr = _dom_new_reconNs(elemp->doc, elemp, nsptr);
+ }
}
}
@@ -671,7 +725,7 @@ PHP_FUNCTION(dom_element_get_attribute_node_ns)
int uri_len, name_len, ret;
char *uri, *name;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_element_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
return;
}
@@ -720,6 +774,11 @@ PHP_FUNCTION(dom_element_set_attribute_node_ns)
RETURN_FALSE;
}
+ if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
+ php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
nsp = attrp->ns;
if (nsp != NULL) {
existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name);
diff --git a/ext/dom/entity.c b/ext/dom/entity.c
index bc625a2c0..74be14930 100644
--- a/ext/dom/entity.c
+++ b/ext/dom/entity.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: entity.c,v 1.7.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: entity.c,v 1.9 2005/08/03 14:07:03 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/entityreference.c b/ext/dom/entityreference.c
index 1d19470d1..7ac0c8b8f 100644
--- a/ext/dom/entityreference.c
+++ b/ext/dom/entityreference.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: entityreference.c,v 1.11 2004/05/31 12:50:28 rrichards Exp $ */
+/* $Id: entityreference.c,v 1.12 2005/08/03 14:07:04 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/namednodemap.c b/ext/dom/namednodemap.c
index 0754e3fb2..8e11042d6 100644
--- a/ext/dom/namednodemap.c
+++ b/ext/dom/namednodemap.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: namednodemap.c,v 1.12.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: namednodemap.c,v 1.15 2005/08/03 14:07:04 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -167,7 +167,8 @@ Since:
PHP_FUNCTION(dom_namednodemap_item)
{
zval *id, *rv = NULL;
- int index, ret;
+ long index;
+ int ret;
dom_object *intern;
xmlNodePtr itemnode = NULL;
diff --git a/ext/dom/namelist.c b/ext/dom/namelist.c
index 5698401ed..897065b89 100644
--- a/ext/dom/namelist.c
+++ b/ext/dom/namelist.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: namelist.c,v 1.5.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: namelist.c,v 1.7 2005/08/03 14:07:04 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/node.c b/ext/dom/node.c
index 154067db4..fa8df8520 100644
--- a/ext/dom/node.c
+++ b/ext/dom/node.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: node.c,v 1.29.2.6 2005/05/20 15:02:48 rrichards Exp $ */
+/* $Id: node.c,v 1.37 2005/08/03 14:07:04 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -317,7 +317,7 @@ int dom_node_parent_node_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(nodeparent, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -389,7 +389,7 @@ int dom_node_first_child_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(first, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -427,7 +427,7 @@ int dom_node_last_child_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(last, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -462,7 +462,7 @@ int dom_node_previous_sibling_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(prevsib, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -497,7 +497,7 @@ int dom_node_next_sibling_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object(nextsib, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -573,7 +573,7 @@ int dom_node_owner_document_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object((xmlNodePtr) docp, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -1299,7 +1299,7 @@ PHP_FUNCTION(dom_node_append_child)
if (new_child == NULL) {
new_child = xmlAddChild(nodep, child);
if (new_child == NULL) {
- php_error(E_WARNING, "Couldn't append node");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't append node");
RETURN_FALSE;
}
}
diff --git a/ext/dom/nodelist.c b/ext/dom/nodelist.c
index 457774a3b..7ba7da012 100644
--- a/ext/dom/nodelist.c
+++ b/ext/dom/nodelist.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: nodelist.c,v 1.14.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: nodelist.c,v 1.17 2005/08/03 14:07:04 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -100,7 +100,8 @@ Since:
PHP_FUNCTION(dom_nodelist_item)
{
zval *id, *rv = NULL;
- int index, ret;
+ long index;
+ int ret;
dom_object *intern;
xmlNodePtr itemnode = NULL;
diff --git a/ext/dom/notation.c b/ext/dom/notation.c
index ae2c57302..ce502c858 100644
--- a/ext/dom/notation.c
+++ b/ext/dom/notation.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: notation.c,v 1.7.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: notation.c,v 1.9 2005/08/03 14:07:05 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index 95a7f7602..fec631871 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_dom.c,v 1.60.2.8 2005/06/22 19:58:33 rrichards Exp $ */
+/* $Id: php_dom.c,v 1.73.2.6 2005/11/23 03:12:45 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -161,6 +161,7 @@ dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
doc_props->preservewhitespace = 1;
doc_props->substituteentities = 0;
doc_props->stricterror = 1;
+ doc_props->recover = 0;
if (document) {
document->doc_props = doc_props;
}
@@ -294,6 +295,7 @@ zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC)
if (ret == SUCCESS) {
/* ensure we're creating a temporary variable */
retval->refcount = 0;
+ retval->is_ref = 0;
} else {
retval = EG(uninitialized_zval_ptr);
}
@@ -344,6 +346,41 @@ void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
}
/* }}} */
+/* {{{ dom_property_exists */
+static int dom_property_exists(zval *object, zval *member, int check_empty TSRMLS_DC)
+{
+ dom_object *obj;
+ zval tmp_member;
+ dom_prop_handler *hnd;
+ zend_object_handlers *std_hnd;
+ int ret, retval=0;
+
+ 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) {
+ retval = 1;
+ } else {
+ std_hnd = zend_get_std_object_handlers();
+ retval = std_hnd->has_property(object, member, check_empty TSRMLS_CC);
+ }
+
+ if (member == &tmp_member) {
+ zval_dtor(member);
+ }
+ return retval;
+}
+/* }}} */
void *php_dom_export_node(zval *object TSRMLS_DC)
{
@@ -362,7 +399,6 @@ void *php_dom_export_node(zval *object TSRMLS_DC)
Get a simplexml_element object from dom to allow for processing */
PHP_FUNCTION(dom_import_simplexml)
{
-#ifdef HAVE_SIMPLEXML
zval *rv = NULL;
zval *node;
xmlNodePtr nodep = NULL;
@@ -379,13 +415,9 @@ PHP_FUNCTION(dom_import_simplexml)
if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) {
DOM_RET_OBJ(rv, (xmlNodePtr) nodep, &ret, (dom_object *)nodeobj);
} else {
- php_error(E_WARNING, "Invalid Nodetype to import");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Nodetype to import");
RETURN_NULL();
}
-#else
- php_error(E_WARNING, "SimpleXML support is not enabled");
- return;
-#endif
}
/* }}} */
@@ -437,8 +469,15 @@ static zend_object_handlers* dom_get_obj_handlers(TSRMLS_D) {
}
}
+static zend_module_dep dom_deps[] = {
+ ZEND_MOD_REQUIRED("libxml")
+ ZEND_MOD_CONFLICTS("domxml")
+ {NULL, NULL, NULL}
+};
+
zend_module_entry dom_module_entry = {
- STANDARD_MODULE_HEADER,
+ STANDARD_MODULE_HEADER_EX, NULL,
+ dom_deps,
"dom",
dom_functions,
PHP_MINIT(dom),
@@ -464,12 +503,14 @@ PHP_MINIT_FUNCTION(dom)
dom_object_handlers.write_property = dom_write_property;
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
+ dom_object_handlers.has_property = dom_property_exists;
memcpy(&dom_ze1_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
dom_ze1_object_handlers.read_property = dom_read_property;
dom_ze1_object_handlers.write_property = dom_write_property;
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
dom_ze1_object_handlers.clone_obj = dom_objects_ze1_clone_obj;
+ dom_ze1_object_handlers.has_property = dom_property_exists;
zend_hash_init(&classes, 0, NULL, NULL, 1);
@@ -541,12 +582,13 @@ PHP_MINIT_FUNCTION(dom)
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, "xmlEncoding", dom_document_encoding_read, NULL 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, "xmlStandalone", 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, "xmlVersion", 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);
@@ -554,6 +596,7 @@ PHP_MINIT_FUNCTION(dom)
dom_register_prop_handler(&dom_document_prop_handlers, "validateOnParse", dom_document_validate_on_parse_read, dom_document_validate_on_parse_write TSRMLS_CC);
dom_register_prop_handler(&dom_document_prop_handlers, "resolveExternals", dom_document_resolve_externals_read, dom_document_resolve_externals_write TSRMLS_CC);
dom_register_prop_handler(&dom_document_prop_handlers, "preserveWhiteSpace", dom_document_preserve_whitespace_read, dom_document_preserve_whitespace_write TSRMLS_CC);
+ dom_register_prop_handler(&dom_document_prop_handlers, "recover", dom_document_recover_read, dom_document_recover_write TSRMLS_CC);
dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", dom_document_substitue_entities_read, dom_document_substitue_entities_write TSRMLS_CC);
zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
@@ -928,8 +971,7 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool
intern = emalloc(sizeof(dom_object));
intern->std.ce = class_type;
- intern->std.in_get = 0;
- intern->std.in_set = 0;
+ intern->std.guards = NULL;
intern->ptr = NULL;
intern->prop_handler = NULL;
intern->document = NULL;
@@ -988,7 +1030,7 @@ zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
- retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t)dom_objects_free_storage, dom_objects_clone TSRMLS_CC);
+ retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)dom_objects_free_storage, dom_objects_clone TSRMLS_CC);
intern->handle = retval.handle;
retval.handlers = dom_get_obj_handlers(TSRMLS_C);
@@ -1005,7 +1047,7 @@ zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC)
intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
- retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t)dom_xpath_objects_free_storage, dom_objects_clone TSRMLS_CC);
+ retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)dom_xpath_objects_free_storage, dom_objects_clone TSRMLS_CC);
intern->handle = retval.handle;
retval.handlers = dom_get_obj_handlers(TSRMLS_C);
@@ -1186,7 +1228,7 @@ zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *wrapper_in, zval *
break;
}
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d\n", Z_TYPE_P(obj));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d", Z_TYPE_P(obj));
ZVAL_NULL(wrapper);
return wrapper;
}
diff --git a/ext/dom/php_dom.h b/ext/dom/php_dom.h
index c78a7c3c3..47c3147c3 100644
--- a/ext/dom/php_dom.h
+++ b/ext/dom/php_dom.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_dom.h,v 1.24.2.1 2004/08/30 15:09:07 rrichards Exp $ */
+/* $Id: php_dom.h,v 1.28 2005/08/03 14:07:05 sniper Exp $ */
#ifndef PHP_DOM_H
#define PHP_DOM_H
@@ -91,6 +91,7 @@ zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC);
#endif
int dom_get_strict_error(php_libxml_ref_obj *document);
void php_dom_throw_error(int error_code, int strict_error TSRMLS_DC);
+void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error TSRMLS_DC);
void node_list_unlink(xmlNodePtr node TSRMLS_DC);
int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len);
xmlNsPtr dom_get_ns(xmlNodePtr node, char *uri, int *errorcode, char *prefix);
@@ -118,7 +119,7 @@ entry = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC);
#define DOM_GET_OBJ(__ptr, __id, __prtype, __intern) { \
__intern = (dom_object *)zend_object_store_get_object(__id TSRMLS_CC); \
if (__intern->ptr == NULL || !(__ptr = (__prtype)((php_libxml_node_ptr *)__intern->ptr)->node)) { \
- php_error(E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
RETURN_NULL();\
} \
}
diff --git a/ext/dom/processinginstruction.c b/ext/dom/processinginstruction.c
index e7975d48b..69794f373 100644
--- a/ext/dom/processinginstruction.c
+++ b/ext/dom/processinginstruction.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: processinginstruction.c,v 1.15.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: processinginstruction.c,v 1.17 2005/08/03 14:07:05 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/string_extend.c b/ext/dom/string_extend.c
index e79ebbec6..fb91b64a1 100644
--- a/ext/dom/string_extend.c
+++ b/ext/dom/string_extend.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string_extend.c,v 1.4 2004/01/08 08:15:17 andi Exp $ */
+/* $Id: string_extend.c,v 1.5 2005/08/03 14:07:06 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/tests/bug34276.phpt b/ext/dom/tests/bug34276.phpt
new file mode 100644
index 000000000..e1083364a
--- /dev/null
+++ b/ext/dom/tests/bug34276.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Bug # 34276: setAttributeNS and default namespace
+--SKIPIF--
+<?php require_once('skipif.php'); ?>
+--FILE--
+<?php
+$xml = <<<HERE
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<foo xmlns="http://www.example.com/ns/foo"
+ xmlns:fubar="http://www.example.com/ns/fubar" attra="attra" />
+HERE;
+
+function dump($elems) {
+ foreach ($elems as $elem) {
+ var_dump($elem->nodeName);
+ dump($elem->childNodes);
+ }
+}
+
+$dom = new DOMDocument();
+$dom->loadXML($xml);
+$foo = $dom->documentElement;
+var_dump($foo->hasAttributeNS('http://www.example.com/ns/foo', 'attra'));
+var_dump($foo->getAttributeNS('http://www.example.com/ns/foo', 'attra'));
+
+$foo->setAttributeNS('http://www.example.com/ns/foo', 'attra', 'attranew');
+$foo->setAttributeNS('http://www.example.com/ns/fubar', 'attrb', 'attrbnew');
+$foo->setAttributeNS('http://www.example.com/ns/foo', 'attrc', 'attrc');
+
+var_dump($foo->getAttributeNS('http://www.example.com/ns/foo', 'attra'));
+var_dump($foo->getAttributeNS('http://www.example.com/ns/fubar', 'attrb'));
+var_dump($foo->getAttributeNS('http://www.example.com/ns/foo', 'attrc'));
+
+print $dom->saveXML();
+?>
+--EXPECT--
+bool(false)
+string(0) ""
+string(8) "attranew"
+string(8) "attrbnew"
+string(5) "attrc"
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<foo xmlns="http://www.example.com/ns/foo" xmlns:fubar="http://www.example.com/ns/fubar" xmlns:default="http://www.example.com/ns/foo" attra="attra" default:attra="attranew" fubar:attrb="attrbnew" default:attrc="attrc"/>
diff --git a/ext/dom/tests/bug35342.phpt b/ext/dom/tests/bug35342.phpt
new file mode 100644
index 000000000..2aab3852b
--- /dev/null
+++ b/ext/dom/tests/bug35342.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug # 35342: isset(DOMNodeList->length) returns false
+--SKIPIF--
+<?php require_once('skipif.php'); ?>
+--FILE--
+<?php
+$dom = new DOMDocument();
+$dom->loadXML("<root><foo>foobar</foo><foo>foobar#2</foo></root>");
+
+$nodelist = $dom->getElementsByTagName("foo");
+
+var_dump($nodelist->length, isset($nodelist->length), isset($nodelist->foo));
+?>
+--EXPECT--
+int(2)
+bool(true)
+bool(false)
diff --git a/ext/dom/tests/dom002.phpt b/ext/dom/tests/dom002.phpt
index 3343a1774..2bc0717d6 100644
--- a/ext/dom/tests/dom002.phpt
+++ b/ext/dom/tests/dom002.phpt
@@ -1,7 +1,7 @@
--TEST--
Test 2: getElementsByTagName() / getElementsByTagNameNS()
--SKIPIF--
-<?php require_once('skipif.inc'); ?>
+<?php require_once('skipif.php'); ?>
--FILE--
<?php
$xml = <<<HERE
diff --git a/ext/dom/tests/dom003.phpt b/ext/dom/tests/dom003.phpt
index 3c4e243c4..1eb6d4a4f 100644
--- a/ext/dom/tests/dom003.phpt
+++ b/ext/dom/tests/dom003.phpt
@@ -59,6 +59,6 @@ object(DOMException)#%d (6) {
Fatal error: Uncaught exception 'DOMException' with message 'Hierarchy Request Error' in %sdom003.php:%d
Stack trace:
-#0 %sdom003.php(%d): DOMNode->appendChild(Object(DOMElement))
+#0 %sdom003.php(13): DOMNode->appendChild(Object(DOMElement))
#1 {main}
thrown in %sdom003.php on line %d
diff --git a/ext/dom/tests/dom005.phpt b/ext/dom/tests/dom005.phpt
index c0f4bb714..249869eff 100644
--- a/ext/dom/tests/dom005.phpt
+++ b/ext/dom/tests/dom005.phpt
@@ -14,23 +14,23 @@ print "--- save as HTML\n";
print adjustDoctype($dom->saveHTML());
function adjustDoctype($xml) {
- return str_replace("DOCTYPE HTML","DOCTYPE html",$xml);
+ return str_replace(array("DOCTYPE HTML",'<p>','</p>'),array("DOCTYPE html",'',''),$xml);
}
--EXPECT--
--- save as XML
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
-<html><head><title>Hello world</title></head><body><p>
+<html><head><title>Hello world</title></head><body>
This is a not well-formed<br/>
html files with undeclared entities&#xA0;
-</p></body></html>
+</body></html>
--- save as HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>Hello world</title></head>
-<body><p>
+<body>
This is a not well-formed<br>
html files with undeclared entities&nbsp;
-</p></body>
+</body>
</html>
diff --git a/ext/dom/tests/dom_set_attr_node.phpt b/ext/dom/tests/dom_set_attr_node.phpt
new file mode 100644
index 000000000..e87a96011
--- /dev/null
+++ b/ext/dom/tests/dom_set_attr_node.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Test: setAttributeNode()
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$xml = <<<HERE
+<?xml version="1.0" ?>
+<root a="b" />
+HERE;
+
+$xml2 = <<<HERE
+<?xml version="1.0" ?>
+<doc2 />
+HERE;
+
+$dom = new DOMDocument();
+$dom->loadXML($xml);
+$root = $dom->documentElement;
+$attr = $root->getAttributeNode('a');
+
+$dom2 = new DOMDocument();
+$dom2->loadXML($xml2);
+$root2 = $dom2->documentElement;
+try {
+ $root2->setAttributeNode($attr);
+} catch (domexception $e) {
+ var_dump($e);
+}
+
+?>
+--EXPECTF--
+object(DOMException)#%d (6) {
+ ["message:protected"]=>
+ string(20) "Wrong Document Error"
+ ["string:private"]=>
+ string(0) ""
+ ["file:protected"]=>
+ string(%d) "%sdom_set_attr_node.php"
+ ["line:protected"]=>
+ int(22)
+ ["trace:private"]=>
+ array(1) {
+ [0]=>
+ array(6) {
+ ["file"]=>
+ string(%d) "%sdom_set_attr_node.php"
+ ["line"]=>
+ int(22)
+ ["function"]=>
+ string(16) "setAttributeNode"
+ ["class"]=>
+ string(10) "DOMElement"
+ ["type"]=>
+ string(2) "->"
+ ["args"]=>
+ array(1) {
+ [0]=>
+ object(DOMAttr)#%d (0) {
+ }
+ }
+ }
+ }
+ ["code"]=>
+ int(4)
+} \ No newline at end of file
diff --git a/ext/dom/tests/dom_xinclude.phpt b/ext/dom/tests/dom_xinclude.phpt
index 92df048bc..f9a3dd761 100644
--- a/ext/dom/tests/dom_xinclude.phpt
+++ b/ext/dom/tests/dom_xinclude.phpt
@@ -8,20 +8,25 @@ array_search('compress.zlib', stream_get_wrappers()) or die('skip compress.zlib
--FILE--
<?php
$dom = new domdocument;
-$dom->load(dirname(__FILE__)."/xinclude.xml");
+
+$data = file_get_contents(dirname(__FILE__)."/xinclude.xml");
+$data = str_replace('compress.zlib://ext/dom/tests/','compress.zlib://'.dirname(__FILE__).'/', $data);
+
+$dom->loadXML($data);
+
$dom->xinclude();
print $dom->saveXML()."\n";
foreach ($dom->documentElement->childNodes as $node) {
print $node->nodeName."\n";
}
-
---EXPECT--
+?>
+--EXPECTF--
<?xml version="1.0"?>
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
- <book xml:base="compress.zlib://ext/dom/tests/book.xml">
+ <book xml:base="compress.zlib://%sext/dom/tests/book.xml">
<title>The Grapes of Wrath</title>
<author>John Steinbeck</author>
- </book><book xml:base="compress.zlib://ext/dom/tests/book.xml">
+ </book><book xml:base="compress.zlib://%sext/dom/tests/book.xml">
<title>The Pearl</title>
<author>John Steinbeck</author>
</book>
diff --git a/ext/dom/text.c b/ext/dom/text.c
index 1fb4aeaf0..fb1a05e52 100644
--- a/ext/dom/text.c
+++ b/ext/dom/text.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: text.c,v 1.20.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: text.c,v 1.23 2005/08/03 14:07:06 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -38,6 +38,7 @@
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(isElementContentWhitespace, dom_text_is_whitespace_in_element_content, NULL)
PHP_FALIAS(replaceWholeText, dom_text_replace_whole_text, NULL)
PHP_ME(domtext, __construct, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
diff --git a/ext/dom/typeinfo.c b/ext/dom/typeinfo.c
index b9d6b5d1b..58a90f132 100644
--- a/ext/dom/typeinfo.c
+++ b/ext/dom/typeinfo.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: typeinfo.c,v 1.4.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: typeinfo.c,v 1.6 2005/08/03 14:07:06 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/userdatahandler.c b/ext/dom/userdatahandler.c
index be5172d68..343cbcd6e 100644
--- a/ext/dom/userdatahandler.c
+++ b/ext/dom/userdatahandler.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: userdatahandler.c,v 1.4.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: userdatahandler.c,v 1.6 2005/08/03 14:07:06 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
diff --git a/ext/dom/xml_common.h b/ext/dom/xml_common.h
index eb5b569e1..39aad7b1a 100644
--- a/ext/dom/xml_common.h
+++ b/ext/dom/xml_common.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: xml_common.h,v 1.19.2.1 2005/06/22 19:58:33 rrichards Exp $ */
+/* $Id: xml_common.h,v 1.23 2005/08/03 14:07:06 sniper Exp $ */
#ifndef PHP_XML_COMMON_H
#define PHP_XML_COMMON_H
@@ -31,6 +31,7 @@ typedef struct _dom_doc_props {
int preservewhitespace;
int substituteentities;
int stricterror;
+ int recover;
} dom_doc_props;
typedef dom_doc_props *dom_doc_propsptr;
@@ -67,7 +68,7 @@ PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj);
#define NODE_GET_OBJ(__ptr, __id, __prtype, __intern) { \
__intern = (php_libxml_node_object *)zend_object_store_get_object(__id TSRMLS_CC); \
if (__intern->node == NULL || !(__ptr = (__prtype)__intern->node->node)) { \
- php_error(E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
RETURN_NULL();\
} \
}
@@ -76,7 +77,7 @@ PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj);
__intern = (php_libxml_node_object *)zend_object_store_get_object(__id TSRMLS_CC); \
if (__intern->document != NULL) { \
if (!(__ptr = (__prtype)__intern->document->ptr)) { \
- php_error(E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
RETURN_NULL();\
} \
} \
@@ -84,13 +85,13 @@ PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj);
#define DOM_RET_OBJ(zval, obj, ret, domobject) \
if (NULL == (zval = php_dom_create_object(obj, ret, zval, return_value, domobject TSRMLS_CC))) { \
- php_error(E_WARNING, "Cannot create required DOM object"); \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object"); \
RETURN_FALSE; \
}
#define DOM_GET_THIS(zval) \
if (NULL == (zval = getThis())) { \
- php_error(E_WARNING, "Underlying object missing"); \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Underlying object missing"); \
RETURN_FALSE; \
}
diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c
index ed45d3688..af56201c7 100644
--- a/ext/dom/xpath.c
+++ b/ext/dom/xpath.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: xpath.c,v 1.22.2.1 2004/11/18 19:55:00 rrichards Exp $ */
+/* $Id: xpath.c,v 1.26 2005/08/03 14:07:06 sniper Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -27,6 +27,8 @@
#if HAVE_LIBXML && HAVE_DOM
#include "php_dom.h"
+#define PHP_DOM_XPATH_QUERY 0
+#define PHP_DOM_XPATH_EVALUATE 1
/*
* class DOMXPath
@@ -38,6 +40,7 @@ zend_function_entry php_dom_xpath_class_functions[] = {
PHP_ME(domxpath, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_FALIAS(registerNamespace, dom_xpath_register_ns, NULL)
PHP_FALIAS(query, dom_xpath_query, NULL)
+ PHP_FALIAS(evaluate, dom_xpath_evaluate, NULL)
{NULL, NULL, NULL}
};
@@ -93,7 +96,7 @@ int dom_xpath_document_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (NULL == (*retval = php_dom_create_object((xmlNodePtr) docp, &ret, NULL, *retval, obj TSRMLS_CC))) {
- php_error(E_WARNING, "Cannot create required DOM object");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
return FAILURE;
}
return SUCCESS;
@@ -116,7 +119,7 @@ PHP_FUNCTION(dom_xpath_register_ns)
ctxp = (xmlXPathContextPtr) intern->ptr;
if (ctxp == NULL) {
- php_error(E_WARNING, "Invalid XPath Context");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
RETURN_FALSE;
}
@@ -136,14 +139,12 @@ static void dom_xpath_iter(zval *baseobj, dom_object *intern)
}
-/* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context]); */
-PHP_FUNCTION(dom_xpath_query)
-{
+static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) {
zval *id, *retval, *context = NULL;
xmlXPathContextPtr ctxp;
xmlNodePtr nodep = NULL;
xmlXPathObjectPtr xpathobjp;
- int expr_len, ret, nsnbr = 0;
+ int expr_len, ret, nsnbr = 0, xpath_type;
dom_object *intern, *nodeobj;
char *expr;
xmlDoc *docp = NULL;
@@ -158,13 +159,13 @@ PHP_FUNCTION(dom_xpath_query)
ctxp = (xmlXPathContextPtr) intern->ptr;
if (ctxp == NULL) {
- php_error(E_WARNING, "Invalid XPath Context");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
RETURN_FALSE;
}
docp = (xmlDocPtr) ctxp->doc;
if (docp == NULL) {
- php_error(E_WARNING, "Invalid XPath Document Pointer");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Document Pointer");
RETURN_FALSE;
}
@@ -177,7 +178,7 @@ PHP_FUNCTION(dom_xpath_query)
}
if (nodep && docp != nodep->doc) {
- php_error(E_WARNING, "Node From Wrong Document");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Node From Wrong Document");
RETURN_FALSE;
}
@@ -208,54 +209,92 @@ PHP_FUNCTION(dom_xpath_query)
RETURN_FALSE;
}
+ if (type == PHP_DOM_XPATH_QUERY) {
+ xpath_type = XPATH_NODESET;
+ } else {
+ xpath_type = xpathobjp->type;
+ }
- MAKE_STD_ZVAL(retval);
- array_init(retval);
-
- if (xpathobjp->type == XPATH_NODESET) {
- int i;
- xmlNodeSetPtr nodesetp;
-
- if (NULL != (nodesetp = xpathobjp->nodesetval)) {
-
- for (i = 0; i < nodesetp->nodeNr; i++) {
- xmlNodePtr node = nodesetp->nodeTab[i];
- zval *child;
-
- MAKE_STD_ZVAL(child);
-
- if (node->type == XML_NAMESPACE_DECL) {
- xmlNsPtr curns;
- xmlNodePtr nsparent;
-
- nsparent = node->_private;
- curns = xmlNewNs(NULL, node->name, NULL);
- if (node->children) {
- curns->prefix = xmlStrdup((char *) node->children);
+ switch (xpath_type) {
+
+ case XPATH_NODESET:
+ {
+ int i;
+ xmlNodeSetPtr nodesetp;
+
+ MAKE_STD_ZVAL(retval);
+ array_init(retval);
+
+ if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval)) {
+
+ for (i = 0; i < nodesetp->nodeNr; i++) {
+ xmlNodePtr node = nodesetp->nodeTab[i];
+ zval *child;
+
+ MAKE_STD_ZVAL(child);
+
+ if (node->type == XML_NAMESPACE_DECL) {
+ xmlNsPtr curns;
+ xmlNodePtr nsparent;
+
+ nsparent = node->_private;
+ curns = xmlNewNs(NULL, node->name, NULL);
+ if (node->children) {
+ curns->prefix = xmlStrdup((char *) node->children);
+ }
+ if (node->children) {
+ node = xmlNewDocNode(docp, NULL, (char *) node->children, node->name);
+ } else {
+ node = xmlNewDocNode(docp, NULL, "xmlns", node->name);
+ }
+ node->type = XML_NAMESPACE_DECL;
+ node->parent = nsparent;
+ node->ns = curns;
}
- if (node->children) {
- node = xmlNewDocNode(docp, NULL, (char *) node->children, node->name);
- } else {
- node = xmlNewDocNode(docp, NULL, "xmlns", node->name);
- }
- node->type = XML_NAMESPACE_DECL;
- node->parent = nsparent;
- node->ns = curns;
+ child = php_dom_create_object(node, &ret, NULL, child, intern TSRMLS_CC);
+ add_next_index_zval(retval, child);
}
- child = php_dom_create_object(node, &ret, NULL, child, intern TSRMLS_CC);
- add_next_index_zval(retval, child);
}
+ php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
+ intern = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
+ dom_xpath_iter(retval, intern);
+ break;
}
- }
- php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
- intern = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
- dom_xpath_iter(retval, intern);
+ case XPATH_BOOLEAN:
+ RETVAL_BOOL(xpathobjp->boolval);
+ break;
+
+ case XPATH_NUMBER:
+ RETVAL_DOUBLE(xpathobjp->floatval)
+ break;
+
+ case XPATH_STRING:
+ RETVAL_STRING(xpathobjp->stringval, 1);
+ break;
+
+ default:
+ RETVAL_NULL();
+ break;
+ }
xmlXPathFreeObject(xpathobjp);
}
+
+/* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context]); */
+PHP_FUNCTION(dom_xpath_query)
+{
+ php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_QUERY);
+}
/* }}} end dom_xpath_query */
+/* {{{ proto mixed dom_xpath_evaluate(string expr [,DOMNode context]); */
+PHP_FUNCTION(dom_xpath_evaluate)
+{
+ php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_EVALUATE);
+}
+/* }}} end dom_xpath_evaluate */
+
#endif /* LIBXML_XPATH_ENABLED */
/* }}} */