rrichards Sun Dec 5 07:01:45 2004 EDT Modified files: /php-src/ext/dom document.c Log: add optional parameter to pass libxml document load options http://cvs.php.net/diff.php/php-src/ext/dom/document.c?r1=1.61&r2=1.62&ty=u Index: php-src/ext/dom/document.c diff -u php-src/ext/dom/document.c:1.61 php-src/ext/dom/document.c:1.62 --- php-src/ext/dom/document.c:1.61 Thu Nov 18 14:54:30 2004 +++ php-src/ext/dom/document.c Sun Dec 5 07:01:44 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: document.c,v 1.61 2004/11/18 19:54:30 rrichards Exp $ */ +/* $Id: document.c,v 1.62 2004/12/05 12:01:44 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -1076,6 +1076,7 @@ if (!retnodep) { RETURN_FALSE; } + } DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret, intern); @@ -1406,7 +1407,7 @@ /* {{{ */ -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; @@ -1435,7 +1436,9 @@ 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); @@ -1447,11 +1450,13 @@ 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); @@ -1477,11 +1482,6 @@ } } - ctxt->recovery = recover; - 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; @@ -1489,15 +1489,40 @@ ctxt->sax->error = php_libxml_ctx_error; 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; + } + if (options > 0) { + 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 || recover) { ret = ctxt->myDoc; - if (recover) { + if (ctxt->recovery) { EG(error_reporting) = old_error_reporting; } /* If loading from memory, set the base reference uri for the document */ @@ -1523,14 +1548,14 @@ dom_doc_props *doc_prop; dom_object *intern; char *source; - int source_len, refcount, ret; + int source_len, refcount, ret, 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; } @@ -1539,7 +1564,7 @@ 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; @@ -1572,7 +1597,7 @@ } /* }}} 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 */ @@ -1582,7 +1607,7 @@ } /* }}} 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 */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php