chregu Sun Oct 26 19:01:40 2003 EDT Modified files: /php-src/ext/dom document.c Log: - Make distinction in error-reporting between Warnings and Errors from libxml2 - Use internal error_handlers during html-parsing as well Index: php-src/ext/dom/document.c diff -u php-src/ext/dom/document.c:1.32 php-src/ext/dom/document.c:1.33 --- php-src/ext/dom/document.c:1.32 Sun Oct 26 10:57:01 2003 +++ php-src/ext/dom/document.c Sun Oct 26 19:01:39 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: document.c,v 1.32 2003/10/26 15:57:01 rrichards Exp $ */ +/* $Id: document.c,v 1.33 2003/10/27 00:01:39 chregu Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -115,15 +115,43 @@ efree(buf); } +/* {{{ static void php_dom_ctx_error_level(int level, void *ctx, const char *msg, ...) */ +static void php_dom_ctx_error_level(int level, void *ctx, const char *msg) +{ + xmlParserCtxtPtr parser; + + parser = (xmlParserCtxtPtr) ctx; + php_error(level, "%s in %s, line: %d", msg, parser->input->filename, parser->input->line); + +} +/* }}} end php_dom_ctx_error */ + /* {{{ static void php_dom_ctx_error(void *ctx, const char *msg, ...) */ static void php_dom_ctx_error(void *ctx, const char *msg, ...) { va_list ap; char *buf; int len; - xmlParserCtxtPtr parser; - parser = (xmlParserCtxtPtr) ctx; + 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_dom_ctx_error_level(E_WARNING, ctx, buf); + efree(buf); +} +/* }}} end php_dom_ctx_error */ + +static void php_dom_ctx_warning(void *ctx, const char *msg, ...) +{ + va_list ap; + char *buf; + int len; va_start(ap, msg); len = vspprintf(&buf, 0, msg, ap); @@ -134,11 +162,12 @@ buf[len] = '\0'; } - php_error(E_WARNING, "%s in %s, line: %d", buf, parser->input->filename, parser->input->line); + php_dom_ctx_error_level(E_NOTICE, ctx, buf); efree(buf); } /* }}} end php_dom_ctx_error */ + /* {{{ proto doctype documenttype readonly=yes URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-B63ED1A31 @@ -1299,10 +1328,11 @@ ctxt->replaceEntities = substitute_ent; ctxt->vctxt.error = php_dom_ctx_error; - ctxt->vctxt.warning = php_dom_ctx_error; + ctxt->vctxt.warning = php_dom_ctx_warning; if (ctxt->sax != NULL) { ctxt->sax->error = php_dom_ctx_error; + ctxt->sax->warning = php_dom_ctx_warning; } xmlParseDocument(ctxt); @@ -1687,7 +1717,8 @@ dom_doc_props *doc_prop; char *source; int source_len, refcount, ret; - + htmlParserCtxtPtr ctxt; + id = getThis(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { @@ -1695,11 +1726,21 @@ } if (mode == DOM_LOAD_FILE) { - newdoc = htmlParseFile(source, NULL); + ctxt = htmlCreateFileParserCtxt(source, NULL); } else { - newdoc = htmlParseDoc(source, NULL); + source_len = xmlStrlen(source); + ctxt = htmlCreateMemoryParserCtxt(source, source_len); } - + ctxt->vctxt.error = php_dom_ctx_warning; + ctxt->vctxt.warning = php_dom_ctx_warning; + if (ctxt->sax != NULL) { + ctxt->sax->error = php_dom_ctx_error; + ctxt->sax->warning = php_dom_ctx_warning; + } + htmlParseDocument(ctxt); + newdoc = ctxt->myDoc; + htmlFreeParserCtxt(ctxt); + if (!newdoc) RETURN_FALSE;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php