libxml htmlParseDocument忽略htmlParseOption标志 [英] libxml htmlParseDocument ignoring htmlParseOption flags

查看:82
本文介绍了libxml htmlParseDocument忽略htmlParseOption标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找通过PHP打包以外的环境使用libxml来确认HTML_PARSE_NOWARNING标志的人将被忽略. 仍然会生成警告.

Looking for someone who uses libxml through an environment other than packaged with PHP to confirm the HTML_PARSE_NOWARNING flag is ignored. Warnings are still generated.

PHP的源代码,在C中实现libxml:

Source code from PHP, implementing libxml in C:

//one of these options is 64 or HTML_PARSE_NOWARNING
htmlCtxtUseOptions(ctxt, (int)options);

ctxt->vctxt.error = php_libxml_ctx_error;
ctxt->vctxt.warning = php_libxml_ctx_warning;
if (ctxt->sax != NULL) {
    ctxt->sax->error = php_libxml_ctx_error;
    ctxt->sax->warning = php_libxml_ctx_warning;
}
htmlParseDocument(ctxt); //this still produces warnings

推荐答案

libxml2 不会忽略HTML_PARSE_NOWARNING标志.用HTML_PARSE_NOWARNING调用htmlCtxtUseOptions会导致警告处理程序被注销(设置为NULL).但是,PHP代码随后继续无条件安装其自己的处理程序,从而使该标志无用. PHP代码应该添加一个检查是否要安装处理程序:

libxml2 does not ignore the HTML_PARSE_NOWARNING flag. Calling htmlCtxtUseOptions with HTML_PARSE_NOWARNING causes the warning handlers to be unregistered (set to NULL). But the PHP code then proceeds to install its own handlers unconditionally, rendering the flag useless. The PHP code should either add a check whether to install the handlers:

htmlCtxtUseOptions(ctxt, (int)options);

if (!(options & HTML_PARSE_NOERROR)) {
    ctxt->vctxt.error = php_libxml_ctx_error;
    if (ctxt->sax != NULL)
        ctxt->sax->error = php_libxml_ctx_error;
}
if (!(options & HTML_PARSE_NOWARNING)) {
    ctxt->vctxt.warning = php_libxml_ctx_warning;
    if (ctxt->sax != NULL)
        ctxt->sax->warning = php_libxml_ctx_warning;
}
htmlParseDocument(ctxt);

或设置处理程序后调用htmlCtxtUseOptions:

Or call htmlCtxtUseOptions after setting the handlers:

ctxt->vctxt.error = php_libxml_ctx_error;
ctxt->vctxt.warning = php_libxml_ctx_warning;
if (ctxt->sax != NULL) {
    ctxt->sax->error = php_libxml_ctx_error;
    ctxt->sax->warning = php_libxml_ctx_warning;
}

htmlCtxtUseOptions(ctxt, (int)options);
htmlParseDocument(ctxt);

这篇关于libxml htmlParseDocument忽略htmlParseOption标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆