以下是服务器给我的意外警告消息:
警告:DOMDocument :: loadHTML()[domdocument.loadhtml]:已在实体中定义的ID页面3,在C:\ Program Files \ Zend \ Apache2 \ htdocs \ joom \ templates \ valueTemplate \ updateRecord中的行:25第74行的.php
执行以下代码时会生成上述警告消息:
$html = new DOMDocument();
$html->loadHTML( $fetchedData[ 'content' ] );
该消息是意外的,因为HTML页面中没有重复使用“page3”作为ID。但是,'page3'在HTML文档中多次用作name属性的值。例如:
<li id="index00025" name="page3" class="fooBar"></li>
对此的任何帮助都将得到全心全意的赞赏。提前谢谢。
答案 0 :(得分:2)
这是预期的行为。在HTML中,属性“name”引入了一个id,就像属性“id”本身一样,如果元素是a
(我对libxml内部结构一无所知,所以我不知道在哪个环境elem
可以为NULL)。
/**
* xmlIsID:
* [...]
*
* Determine whether an attribute is of type ID. In case we have DTD(s)
* then this is done if DTD loading has been requested. In the case
* of HTML documents parsed with the HTML parser, then ID detection is
* done systematically.
* [...]
*/
int
xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
[...]
} else if (doc->type == XML_HTML_DOCUMENT_NODE) {
if ((xmlStrEqual(BAD_CAST "id", attr->name)) ||
((xmlStrEqual(BAD_CAST "name", attr->name)) &&
((elem == NULL) || (xmlStrEqual(elem->name, BAD_CAST "a")))))
return(1);
return(0);
}
[...]
}
来源:libxml发行版的valid.c
。
答案 1 :(得分:2)
Artefacto是正确的。查看它的另一种方法 - 正如HTML规范所做的那样 - 是name
和id
属性共享相同的命名空间。因此,其中一个属性中定义的标识符显示在另一个属性的值集合中,即,如果您定义name="foo"
,则在列出所有foo
属性时将显示name
或所有id
属性。