DOMDocument:忽略重复的元素 ID
我使用 DOMDocument::loadHTML
将一些页面内容(已通过 Tidy 运行,但如果这是问题的根源则不需要)放入 DOMDocument
中>。
它会出现各种错误:
ID x 已在实体 X 行中定义
有没有办法让 DOMDocument(或 Tidy)忽略或删除重复的元素 ID,以便它实际上创建 DOMDocument ?
谢谢。 :)
I'm putting some page content (which has been run through Tidy, but doesn't need to be if this is a source of problems) into DOMDocument
using DOMDocument::loadHTML
.
It's coming up with various errors:
ID x already defined in Entity, line X
Is there any way to make either DOMDocument
(or Tidy) ignore or strip out duplicate element IDs, so it will actually create the DOMDocument
?
Thanks. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对这个主题的快速搜索揭示了这个(不正确的)错误报告:
http://bugs。 php.net/bug.php?id=46136
最后回复内容如下:
我不确定您是否因同样的原因遇到此问题,因为您没有包含对正在加载的 HTML 页面的引用。 无论如何,使用
libxml_use_internal_errors()< /code>
至少应该抑制该错误。
HTML 文档中的 ID 通常是唯一的,因此如果可能的话,最佳解决方案仍然会验证您的文档。
A quick search on the subject reveals this (incorrect) bug report:
http://bugs.php.net/bug.php?id=46136
The last reply states the following:
I can't be sure if you are encountering this problem for the same reasons, since you did not include a reference to the HTML page being loaded. In any case, using
libxml_use_internal_errors()
should at least suppress the error.ID's in HTML documents are generally unique, so the best solution would still be validating your document, if at all possible.
根据定义,ID 是唯一的。 如果不是,您应该使用类(也不是名称,如果适用)。
我怀疑您是否可以强制 XML 工具忽略重复的 ID,这将使它们处理无效的 XML 文档。
By definition, IDs are unique. If they are not, you should use classes instead (nor names, where it applies).
I doubt you can force XML tools to ignore duplicate IDs, that will make them handle an invalid XML document.
使用Exceptions处理重复的ID,并重命名第二个ID。
或者,将同一父元素的子元素中的元素与 ID 组合起来。
ID 在 XML 文件中是唯一的(在 XMLTree 的 rootElement 中)
Use Exceptions to treat duplicate IDs, and rename the second id.
Or maybe, combine elements in sub-elements of same parent with the ID.
IDs are unique in an XML file (in the rootElement of XMLTree)