rrichards Wed Sep 3 06:11:54 2003 EDT
Modified files:
/php-src/ext/dom php_dom.c domexception.c dom_fe.h document.c
Log:
add document HTML load/save methods
add document standalone validate method
cleanup some prototype declarations
domexception inherits from default exception
Index: php-src/ext/dom/php_dom.c
diff -u php-src/ext/dom/php_dom.c:1.28 php-src/ext/dom/php_dom.c:1.29
--- php-src/ext/dom/php_dom.c:1.28 Sun Aug 24 06:23:43 2003
+++ php-src/ext/dom/php_dom.c Wed Sep 3 06:11:53 2003
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_dom.c,v 1.28 2003/08/24 10:23:43 rrichards Exp $ */
+/* $Id: php_dom.c,v 1.29 2003/09/03 10:11:53 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -73,7 +73,6 @@
{NULL, NULL, NULL}
};
-/* {{{ int dom_node_is_read_only(xmlNodePtr node) */
int dom_node_is_read_only(xmlNodePtr node) {
switch (node->type) {
case XML_ENTITY_REF_NODE:
@@ -95,9 +94,7 @@
}
}
}
-/* }}} end dom_node_is_read_only */
-/* {{{ int dom_node_children_valid(xmlNodePtr node) */
int dom_node_children_valid(xmlNodePtr node) {
switch (node->type) {
case XML_DOCUMENT_TYPE_NODE:
@@ -112,7 +109,6 @@
return SUCCESS;
}
}
-/* }}} end dom_node_children_valid */
int dom_get_strict_error(dom_ref_obj *document) {
if (document) {
@@ -122,7 +118,6 @@
}
}
-/* {{{ int increment_document_reference(dom_object *object) */
int increment_document_reference(dom_object *object, xmlDocPtr docp TSRMLS_DC) {
int ret_refcount = -1;
@@ -139,9 +134,7 @@
return ret_refcount;
}
-/* }}} end increment_document_reference */
-/* {{{ int decrement_document_reference(dom_object *object) */
int decrement_document_reference(dom_object *object TSRMLS_DC) {
int ret_refcount = -1;
@@ -160,9 +153,7 @@
return ret_refcount;
}
-/* }}} end decrement_document_reference */
-/* {{{ int decrement_node_ptr(dom_object *object) */
int decrement_node_ptr(dom_object *object TSRMLS_DC) {
int ret_refcount = -1;
node_ptr *obj_node;
@@ -181,9 +172,7 @@
return ret_refcount;
}
-/* }}} end decrement_node_ptr */
-/* {{{ xmlNodePtr dom_object_get_node(dom_object *obj) */
xmlNodePtr dom_object_get_node(dom_object *obj)
{
if (obj->ptr != NULL) {
@@ -192,9 +181,7 @@
return NULL;
}
}
-/* }}} end dom_object_get_node */
-/* {{{ dom_object_set_data */
static void dom_object_set_data(xmlNodePtr obj, dom_object *wrapper TSRMLS_DC)
{
if (wrapper == NULL) {
@@ -203,9 +190,7 @@
obj->_private = wrapper->ptr;
}
}
-/* }}} end dom_object_set_data */
-/* {{{ dom_object *dom_object_get_data(xmlNodePtr obj) */
dom_object *dom_object_get_data(xmlNodePtr obj)
{
if (obj->_private != NULL) {
@@ -214,9 +199,7 @@
return NULL;
}
}
-/* }}} end dom_object_get_data */
-/* {{{ php_dom_clear_object */
static void php_dom_clear_object(dom_object *object TSRMLS_DC)
{
if (object->prop_handler) {
@@ -225,9 +208,7 @@
decrement_node_ptr(object TSRMLS_CC);
decrement_document_reference(object TSRMLS_CC);
}
-/* }}} end php_dom_clear_object */
-/* {{{ void php_dom_set_object(dom_object *object, xmlNodePtr obj TSRMLS_DC) */
void php_dom_set_object(dom_object *object, xmlNodePtr obj TSRMLS_DC)
{
node_ptr *obj_node;
@@ -248,9 +229,7 @@
}
}
}
-/* }}} end php_dom_set_object */
-/* {{{ dom_unregister_node */
void dom_unregister_node(xmlNodePtr nodep TSRMLS_DC)
{
dom_object *wrapper;
@@ -260,26 +239,20 @@
php_dom_clear_object(wrapper TSRMLS_CC);
}
}
-/* }}} end dom_unregister_node */
-/* {{{ 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;
@@ -288,9 +261,7 @@
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, zend_bool silent TSRMLS_DC)
{
dom_object *obj;
@@ -331,9 +302,7 @@
}
return retval;
}
-/* }}} */
-/* {{{ dom_write_property */
void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
{
dom_object *obj;
@@ -370,7 +339,6 @@
zval_dtor(member);
}
}
-/* }}} */
zend_module_entry dom_module_entry = {
STANDARD_MODULE_HEADER,
@@ -400,7 +368,12 @@
zend_hash_init(&classes, 0, NULL, NULL, 1);
- REGISTER_DOM_CLASS(ce, "domexception", NULL,
php_dom_domexception_class_functions, dom_domexception_class_entry);
+ INIT_CLASS_ENTRY(ce, "domexception", php_dom_domexception_class_functions);
+ dom_domexception_class_entry = zend_register_internal_class_ex(&ce,
zend_exception_get_default(), NULL TSRMLS_CC);
+ dom_domexception_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ dom_domexception_class_entry->constructor->common.fn_flags |=
ZEND_ACC_PROTECTED;
+ zend_declare_property_long(dom_domexception_class_entry, "code",
sizeof("code")-1, 0, ZEND_ACC_PUBLIC);
+
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);
@@ -637,13 +610,30 @@
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);
+ /* domException Codes */
+ REGISTER_LONG_CONSTANT("DOM_INDEX_SIZE_ERR", INDEX_SIZE_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOMSTRING_SIZE_ERR", DOMSTRING_SIZE_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_HIERARCHY_REQUEST_ERR", HIERARCHY_REQUEST_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_WRONG_DOCUMENT_ERR", WRONG_DOCUMENT_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_INVALID_CHARACTER_ERR", INVALID_CHARACTER_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_NO_DATA_ALLOWED_ERR", NO_DATA_ALLOWED_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_NO_MODIFICATION_ALLOWED_ERR",
NO_MODIFICATION_ALLOWED_ERR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_NOT_FOUND_ERR", NOT_FOUND_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_NOT_SUPPORTED_ERR", NOT_SUPPORTED_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_INUSE_ATTRIBUTE_ERR", INUSE_ATTRIBUTE_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_INVALID_STATE_ERR", INVALID_STATE_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_SYNTAX_ERR", SYNTAX_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_INVALID_MODIFICATION_ERR",
INVALID_MODIFICATION_ERR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_NAMESPACE_ERR", NAMESPACE_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_INVALID_ACCESS_ERR", INVALID_ACCESS_ERR,
CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOM_VALIDATION_ERR", VALIDATION_ERR,
CONST_CS | CONST_PERSISTENT);
+
xmlInitParser();
return SUCCESS;
}
/* }}} */
-/* {{{ */
PHP_MINFO_FUNCTION(dom)
{
php_info_print_table_start();
@@ -661,7 +651,6 @@
#endif
php_info_print_table_end();
}
-/* }}} */
PHP_MSHUTDOWN_FUNCTION(dom)
{
@@ -698,7 +687,6 @@
return SUCCESS;
}
-/* {{{ node_list_unlink */
void node_list_unlink(xmlNodePtr node TSRMLS_DC)
{
dom_object *wrapper;
@@ -728,10 +716,7 @@
node = node->next;
}
}
-/* }}} end node_list_unlink */
-
-/* {{{ void dom_node_free(xmlNodePtr node) */
void dom_node_free(xmlNodePtr node)
{
if(node) {
@@ -766,9 +751,7 @@
}
}
}
-/* }}} end dom_node_free */
-/* {{{ node_free_list */
void node_free_list(xmlNodePtr node TSRMLS_DC)
{
xmlNodePtr curnode;
@@ -803,9 +786,7 @@
}
}
}
-/* }}} end node_free_list */
-/* {{{ node_free_resource */
void node_free_resource(xmlNodePtr node TSRMLS_DC)
{
if (!node) {
@@ -837,17 +818,13 @@
}
}
}
-/* }}} */
-/* {{{ dom_objects_clone */
void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
{
/* TODO */
}
-/* }}} */
#if defined(LIBXML_XPATH_ENABLED)
-/* {{{ dom_xpath_objects_dtor */
void dom_xpath_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC)
{
dom_object *intern = (dom_object *)object;
@@ -863,10 +840,8 @@
efree(object);
}
-/* }}} */
#endif
-/* {{{ dom_objects_dtor */
void dom_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC)
{
dom_object *intern = (dom_object *)object;
@@ -887,9 +862,7 @@
efree(object);
}
-/* }}} */
-/* {{{ dom_objects_set_class */
static dom_object* dom_objects_set_class(zend_class_entry *class_type TSRMLS_DC)
{
zend_class_entry *base_class;
@@ -917,9 +890,7 @@
return intern;
}
-/* }}} */
-/* {{{ dom_objects_new */
zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
{
zend_object_value retval;
@@ -936,7 +907,6 @@
/* }}} */
#if defined(LIBXML_XPATH_ENABLED)
-/* {{{ zend_object_value dom_xpath_objects_new(zend_class_entry *class_type
TSRMLS_DC) */
zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC)
{
zend_object_value retval;
@@ -950,10 +920,8 @@
return retval;
}
-/* }}} */
#endif
-/* {{{ php_dom_create_object */
zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *wrapper_in, zval
*return_value, dom_object *domobj TSRMLS_DC)
{
zval *wrapper;
@@ -1066,14 +1034,12 @@
php_dom_set_object(intern, (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;
@@ -1093,9 +1059,7 @@
return SUCCESS;
}
-/* }}} end dom_hierarchy */
-/* {{{ dom_has_feature(char *feature, char *version) */
int dom_has_feature(char *feature, char *version)
{
int retval = 0;
@@ -1107,9 +1071,7 @@
return retval;
}
-/* }}} end dom_has_feature */
-/* {{{ 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, dom_object *intern TSRMLS_DC)
{
dom_object *wrapper;
@@ -1132,10 +1094,7 @@
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, newnextp;
@@ -1178,10 +1137,7 @@
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;
@@ -1205,7 +1161,6 @@
}
cur->next = ns;
}
-/* }}} end dom_set_old_ns */
int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int
name_len) {
int errorcode = 0;
@@ -1225,7 +1180,6 @@
return errorcode;
}
-/* {{{ xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix)
*/
xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) {
xmlNsPtr nsptr = NULL;
@@ -1242,9 +1196,7 @@
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;
@@ -1272,7 +1224,6 @@
}
return ret;
}
-/* }}} end dom_get_nsdecl */
#endif /* HAVE_DOM */
Index: php-src/ext/dom/domexception.c
diff -u php-src/ext/dom/domexception.c:1.4 php-src/ext/dom/domexception.c:1.5
--- php-src/ext/dom/domexception.c:1.4 Sun Aug 24 06:23:43 2003
+++ php-src/ext/dom/domexception.c Wed Sep 3 06:11:53 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: domexception.c,v 1.4 2003/08/24 10:23:43 rrichards Exp $ */
+/* $Id: domexception.c,v 1.5 2003/09/03 10:11:53 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -41,10 +41,8 @@
{NULL, NULL, NULL}
};
-/* {{{ php_dom_throw_error */
void php_dom_throw_error(int error_code, int strict_error TSRMLS_DC)
{
- zval *dom_exception;
char *error_message;
switch (error_code)
@@ -102,17 +100,10 @@
}
if (strict_error == 1) {
- 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;
- add_property_long(dom_exception, "code", error_code);
- add_property_stringl(dom_exception, "message", error_message,
strlen(error_message), 1);
- EG(exception) = dom_exception;
+ zend_throw_exception(dom_domexception_class_entry, error_message,
error_code TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, error_message);
}
}
-/* }}} end php_dom_throw_error */
-#endif
+
+#endif /* HAVE_LIBXML && HAVE_DOM */
Index: php-src/ext/dom/dom_fe.h
diff -u php-src/ext/dom/dom_fe.h:1.3 php-src/ext/dom/dom_fe.h:1.4
--- php-src/ext/dom/dom_fe.h:1.3 Thu Jul 24 09:18:40 2003
+++ php-src/ext/dom/dom_fe.h Wed Sep 3 06:11:53 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dom_fe.h,v 1.3 2003/07/24 13:18:40 rrichards Exp $ */
+/* $Id: dom_fe.h,v 1.4 2003/09/03 10:11:53 rrichards Exp $ */
#ifndef DOM_FE_H
#define DOM_FE_H
@@ -125,6 +125,14 @@
PHP_FUNCTION(dom_document_save);
PHP_FUNCTION(dom_document_loadxml);
PHP_FUNCTION(dom_document_savexml);
+PHP_FUNCTION(dom_document_validate);
+
+#if defined(LIBXML_HTML_ENABLED)
+PHP_FUNCTION(dom_document_load_html);
+PHP_FUNCTION(dom_document_load_html_file);
+PHP_FUNCTION(dom_document_save_html);
+PHP_FUNCTION(dom_document_save_html_file);
+#endif /* defined(LIBXML_HTML_ENABLED) */
/* domnode methods */
PHP_FUNCTION(dom_node_insert_before);
Index: php-src/ext/dom/document.c
diff -u php-src/ext/dom/document.c:1.21 php-src/ext/dom/document.c:1.22
--- php-src/ext/dom/document.c:1.21 Sun Aug 24 06:23:43 2003
+++ php-src/ext/dom/document.c Wed Sep 3 06:11:53 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: document.c,v 1.21 2003/08/24 10:23:43 rrichards Exp $ */
+/* $Id: document.c,v 1.22 2003/09/03 10:11:53 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -75,10 +75,16 @@
PHP_FALIAS(loadXML, dom_document_loadxml, NULL)
PHP_FALIAS(saveXML, dom_document_savexml, NULL)
PHP_FALIAS(domdocument, dom_document_document, NULL)
+ PHP_FALIAS(validate, dom_document_validate, NULL)
+#if defined(LIBXML_HTML_ENABLED)
+ PHP_FALIAS(loadHTML, dom_document_load_html, NULL)
+ PHP_FALIAS(loadHTMLFile, dom_document_load_html_file, NULL)
+ PHP_FALIAS(saveHTML, dom_document_save_html, NULL)
+ PHP_FALIAS(saveHTMLFile, dom_document_save_html_file, NULL)
+#endif /* defined(LIBXML_HTML_ENABLED) */
{NULL, NULL, NULL}
};
-/* {{{ void add_domdocument_properties(zval *id) */
void add_domdocument_properties(zval *id TSRMLS_DC) {
add_property_bool(id, "formatOutput", 0);
add_property_bool(id, "validateOnParse", 0);
@@ -86,9 +92,7 @@
add_property_bool(id, "preserveWhiteSpace", 1);
add_property_bool(id, "substituteEntities", 0);
}
-/* }}} end add_domdocument_properties */
-/* {{{ static int dom_document_get_property_int(zval *id, char *property TSRMLS_DC) */
static int dom_document_get_property_int(zval *id, char *property TSRMLS_DC) {
zval *format, *member;
zend_object_handlers *std_hnd;
@@ -109,10 +113,28 @@
return retformat;
}
-/* }}} end dom_document_get_property_int */
-/* {{{ static void php_dom_ctx_error(void *ctx, const char *msg, ...) */
-static void php_dom_ctx_error(void *ctx, const char *msg, ...) {
+static void php_dom_validate_error(void *ctx, const char *msg, ...)
+{
+ char *buf;
+ va_list ap;
+ int len;
+
+ va_start(ap, msg);
+ len = vspprintf(&buf, 0, msg, ap);
+ va_end(ap);
+
+ /* remove any trailing \n */
+ while (len && buf[--len] == '\n') {
+ buf[len] = '\0';
+ }
+
+ php_error(E_WARNING, "%s", buf);
+ efree(buf);
+}
+
+static void php_dom_ctx_error(void *ctx, const char *msg, ...)
+{
va_list ap;
char *buf;
int len;
@@ -132,7 +154,6 @@
php_error(E_WARNING, "%s in %s, line: %d", buf, parser->input->filename,
parser->input->line);
efree(buf);
}
-/* }}} end php_dom_ctx_error */
/* {{{ proto doctype documenttype
readonly=yes
@@ -210,7 +231,6 @@
/* }}} */
-
/* {{{ 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
@@ -1057,7 +1077,6 @@
}
/* }}} end dom_document_document */
-/* {{{ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source
TSRMLS_DC) */
static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC) {
xmlDocPtr ret;
xmlParserCtxtPtr ctxt;
@@ -1121,9 +1140,7 @@
return(ret);
}
-/* }}} end dom_parser_document */
-/* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */
static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
zval *id, *rv = NULL;
xmlDoc *docp = NULL, *newdoc;
@@ -1170,7 +1187,6 @@
DOM_RET_OBJ(rv, (xmlNodePtr) newdoc, &ret, NULL);
}
}
-/* }}} end dom_parser_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
@@ -1278,4 +1294,161 @@
}
}
/* }}} end dom_document_savexml */
-#endif
+
+/* {{{ proto string domnode dom_document_validate();
+Since: DOM extended
+*/
+PHP_FUNCTION(dom_document_validate)
+{
+ zval *id;
+ xmlDoc *docp;
+ dom_object *intern;
+ xmlValidCtxt cvp;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
+
+ if (docp->intSubset == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "No DTD given in
XML-Document");
+ }
+
+ cvp.userData = NULL;
+ cvp.error = (xmlValidityErrorFunc) php_dom_validate_error;
+ cvp.warning = NULL;
+
+ if (xmlValidateDocument(&cvp, docp)) {
+ RETVAL_TRUE;
+ } else {
+ RETVAL_FALSE;
+ }
+}
+/* }}} end dom_document_validate */
+
+
+#if defined(LIBXML_HTML_ENABLED)
+
+static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode)
+{
+ zval *id, *rv = NULL;
+ xmlDoc *docp = NULL, *newdoc;
+ dom_object *intern;
+ char *source;
+ int source_len, refcount, ret;
+
+ id = getThis();
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source,
&source_len) == FAILURE) {
+ return;
+ }
+
+ if (mode == DOM_LOAD_FILE) {
+ if ((PG(safe_mode) && (!php_checkuid(source, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(source TSRMLS_CC)) {
+ RETURN_FALSE;
+ }
+ newdoc = htmlParseFile(source, NULL);
+ } else {
+ newdoc = htmlParseDoc(source, NULL);
+ }
+
+ if (!newdoc)
+ RETURN_FALSE;
+
+ if (id != NULL) {
+ intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
+ if (intern != NULL) {
+ docp = (xmlDocPtr) dom_object_get_node(intern);
+ if (docp != NULL) {
+ decrement_node_ptr(intern TSRMLS_CC);
+ refcount = decrement_document_reference(intern
TSRMLS_CC);
+ if (refcount != 0) {
+ docp->_private = NULL;
+ }
+ }
+ intern->document = NULL;
+ increment_document_reference(intern, newdoc TSRMLS_CC);
+ }
+
+ php_dom_set_object(intern, (xmlNodePtr) newdoc TSRMLS_CC);
+
+ RETURN_TRUE;
+ } else {
+ DOM_RET_OBJ(rv, (xmlNodePtr) newdoc, &ret, NULL);
+ }
+}
+
+/* {{{ proto boolean domnode dom_document_load_html_file(string source);
+Since: DOM extended
+*/
+PHP_FUNCTION(dom_document_load_html_file)
+{
+ dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
+}
+/* }}} end dom_document_load_html_file */
+
+/* {{{ proto boolean domnode dom_document_load_html(string source);
+Since: DOM extended
+*/
+PHP_FUNCTION(dom_document_load_html)
+{
+ dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
+}
+/* }}} end dom_document_load_html */
+
+/* {{{ proto long dom_document_save_html_file(string file);
+Convenience method to save to file as html
+*/
+PHP_FUNCTION(dom_document_save_html_file)
+{
+ zval *id;
+ xmlDoc *docp;
+ int file_len, bytes, format;
+ dom_object *intern;
+ char *file;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
+
+ 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;
+ }
+
+ /* encoding handled by property on doc */
+ format = dom_document_get_property_int(id, "formatOutput" TSRMLS_CC);
+ bytes = htmlSaveFileFormat(file, docp, NULL, format);
+
+ if (bytes == -1) {
+ RETURN_FALSE;
+ }
+ RETURN_LONG(bytes);
+}
+/* }}} end dom_document_save_html_file */
+
+/* {{{ proto string dom_document_save_html();
+Convenience method to output as html
+*/
+PHP_FUNCTION(dom_document_save_html)
+{
+ zval *id;
+ xmlDoc *docp;
+ dom_object *intern;
+ xmlChar *mem;
+ int size;
+
+ DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
+
+ htmlDocDumpMemory(docp, &mem, &size);
+ if (!size) {
+ if (mem)
+ xmlFree(mem);
+ RETURN_FALSE;
+ }
+ RETVAL_STRINGL(mem, size, 1);
+ xmlFree(mem);
+}
+/* }}} end dom_document_save_html */
+
+#endif /* defined(LIBXML_HTML_ENABLED) */
+
+#endif /* HAVE_LIBXML && HAVE_DOM */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php