DOMDocument:忽略重复的元素 ID

发布于 2024-07-11 11:28:54 字数 282 浏览 9 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

始终不够 2024-07-18 11:28:54

对这个主题的快速搜索揭示了这个(不正确的)错误报告:

http://bugs。 php.net/bug.php?id=46136

最后回复内容如下:

您正在使用 HTML 4 规则加载
XHTML 文档。 要么使用 load()
方法解析为 XML 或
libxml_use_internal_errors() 函数
忽略警告。

我不确定您是否因同样的原因遇到此问题,因为您没有包含对正在加载的 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:

You're using HTML 4 rules to load an
XHTML document. Either use the load()
method to parse as XML or the
libxml_use_internal_errors() function
to ignore the warnings.

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.

怪我鬧 2024-07-18 11:28:54

根据定义,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.

那请放手 2024-07-18 11:28:54

使用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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文