summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--ext/dom/document.c49
-rw-r--r--ext/dom/dom_properties.h2
-rw-r--r--ext/dom/php_dom.c2
-rw-r--r--ext/dom/xml_common.h1
5 files changed, 53 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 58aa664a3a..cde00d40c6 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,8 @@ PHP NEWS
. mysqli->client_info property (Georg)
. inet_pton() (Sara)
. inet_ntop() (Sara)
+- Added DomDocument->recover property for parsing not well-formed
+ XML Documents. (Christian)
- Added Cursor support for MySQL 5.0.x in mysqli (Georg)
- Added proxy support to ftp wrapper via http. (Sara)
- Added MDTM support to ftp_url_stat. (Sara)
diff --git a/ext/dom/document.c b/ext/dom/document.c
index a0d6d291dc..3fcad5cf87 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -614,6 +614,48 @@ int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval TSRMLS_
}
/* }}} */
+/* {{{ proto 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;
+}
+/* }}} */
+
/* {{{ proto substituteEntities boolean
readonly=no
@@ -1392,7 +1434,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
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;
char *directory=NULL, resolved_path[MAXPATHLEN];
@@ -1406,6 +1448,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);
@@ -1455,7 +1498,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
}
}
- ctxt->recovery = 0;
+ ctxt->recovery = recover;
ctxt->validate = validate;
ctxt->loadsubset = (resolve_externals * XML_COMPLETE_ATTRS);
ctxt->replaceEntities = substitute_ent;
@@ -1470,7 +1513,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source TSRMLS_DC)
xmlParseDocument(ctxt);
- if (ctxt->wellFormed) {
+ if (ctxt->wellFormed || recover) {
ret = ctxt->myDoc;
/* If loading from memory, set the base reference uri for the document */
if (ret->URL == NULL && ctxt->directory != NULL) {
diff --git a/ext/dom/dom_properties.h b/ext/dom/dom_properties.h
index f371a7ff37..431b1b774b 100644
--- a/ext/dom/dom_properties.h
+++ b/ext/dom/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/php_dom.c b/ext/dom/php_dom.c
index ac7a5ae1fc..c65caaf618 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -126,6 +126,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;
}
@@ -462,6 +463,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);
diff --git a/ext/dom/xml_common.h b/ext/dom/xml_common.h
index 987cf86195..72f5442578 100644
--- a/ext/dom/xml_common.h
+++ b/ext/dom/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;