【问题标题】:xPath loadHTML gets tripped up on Table element for "unexpected end tag"xPath loadHTML 在 Table 元素上因“意外的结束标记”而被绊倒
【发布时间】:2011-05-04 17:26:32
【问题描述】:

当我的内容包含下面的表格标记时出现错误。这是错误消息:

警告:DOMDocument::loadHTML() [domdocument.loadhtml]:意外的结束标记:实体中的 col,行:2

在我的代码中引用了这一行:

$dom->loadHTML(strtolower($post->post_content));

我的内容包含这个表格标记...

<table style="height: 658px;" 
       border="0" 
       cellspacing="0" 
       cellpadding="0" 
       width="472">
    <colgroup>
        <col width="188"></col>
        <col width="590"></col>
    </colgroup>
    <tbody>
        <tr height="20">
            <td width="188" height="20"></td>
            <td width="590"></td>
        </tr>
    </tbody>
</table>

我正在使用这个函数来解析它......

function doTheParse($heading)
{
global $post;
$content = $post->post_content;
if($content=="") return false;
$keyword = trim(strtolower(rseo_getKeyword($post)));
$dom = new DOMDocument;
$dom->loadHTML(strtolower($post->post_content));
$xPath = new DOMXPath($dom);
switch ($heading)
    {
    case "img-alt": return $xPath->evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])');
    default: return $xPath->evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])');
    }
}

【问题讨论】:

    标签: dom error-handling html-parsing


    【解决方案1】:

    我只是在猜测,但由于您的 col 元素没有内部值,请尝试不使用结束标记。所以,instead of &lt;col width="188"&gt;&lt;/col&gt; use &lt;col width="188" /&gt;

    【讨论】:

    • A@Nikky9696:感谢您的提示。假设可行,我该如何修改函数以抑制错误或克服错误?数据总是动态的,所以我不知道html标签是空的还是非空的。
    • 你在控制一代吗?我知道我们必须修改我们的一个工具来生成空元素作为 和值作为 value 的元素
    猜你喜欢
    • 1970-01-01
    • 2015-05-04
    • 2016-12-30
    • 2019-06-30
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2021-08-28
    • 1970-01-01
    相关资源
    最近更新 更多