为什么使用框架集 DTD 会导致验证失败?

发布于 2024-08-08 06:33:31 字数 1593 浏览 10 评论 0原文

我从事的项目采用随机HTML文件,尽可能将它们转换为XHTML,然后用一些 XML 元数据。由于生成的 XML 文件不是 XHTML 文档,因此 DOCTYPE 被删除。但是,当从 XML 文件检索包装的 XHTML 时,应重新插入 DOCTYPE。

因为这些是随机 HTML 文件,所以它们可以包含任何内容,但我宁愿不必存储或确定原始 DTD。我认为我应该使用框架集 DTD,因为它只是过渡 DTD 的超集,并且对所有内容都有效。但是,当对同一文档使用 W3C XHTML Validator 时,使用 Transitional DTD 会通过,但使用 Frameset DTD 会失败。

我已将文档精简到可以重现问题的最低限度。这是框架集版本:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Make The Move</title>
</head>

<body style="background: none;">
    <h3 id="why">Why should I move to Linux?</h3>
</body>

</html>


这是过渡版本:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Make The Move</title>
</head>

<body style="background: none;">
    <h3 id="why">Why should I move to Linux?</h3>
</body>

</html>


请解释为什么会发生这种情况,以及我应该如何处理。

The project I work on takes random HTML files, converts them to XHTML as best as it can, and wraps them with some XML metdata. The DOCTYPE is stripped out as the resulting XML file is not an XHTML document. However when retrieving the wrapped XHTML from the XML file the DOCTYPE should be reinserted.

Because these are random HTML files they could contain any content, but I would prefer to not have to store or determine the original DTD. I figured that I should the Frameset DTD as it was just a superset of the Transitional DTD and would be valid for all content. However when using the W3C XHTML Validator with the same document, using the Transitional DTD passes but using the Frameset DTD fails.

I've stripped down the document to the minimum with which I can reproduce the problem. Here is the Frameset version:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Make The Move</title>
</head>

<body style="background: none;">
    <h3 id="why">Why should I move to Linux?</h3>
</body>

</html>

And here is the Transitional version:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Make The Move</title>
</head>

<body style="background: none;">
    <h3 id="why">Why should I move to Linux?</h3>
</body>

</html>

Please explain why this is happening, and how I should proceed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

守不住的情 2024-08-15 06:33:31

框架集 DTD 不是过渡的“超集”。它是一个特殊的 DTD,仅用于布局框架,而不是内容(<code></code> 标签内除外)。它仅允许 <code></code> 和 <code></code> 作为 <code></code> 标记的子级。

此处 是规格。

除非您知道您的页面可能有框架,否则请坚持使用过渡或严格的 DTD。

Frameset DTD is not a 'superset' of transitional. It is a special DTD only used for laying out frames, not content (except inside <noframes> tag). It allows only <head> and <frameset> as the children of <html> tag.

Here is the specification.

Unless you know your page could have frames, stick to transitional or strict DTDs.

断桥再见 2024-08-15 06:33:31

正如 Chetan 指出的那样,框架集 DTD 应该仅在需要框架的情况下使用,即使如此,我还是建议使用 Transitional。如果您不依赖框架,则 Strict 是最佳选择。

As Chetan pointed out, the Frameset DTD should only be used in case you need frames, and even then, I would recomend on using Transitional instead. If you don't rely on frames, Strict is the way to go.

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