Html HTML5 文档类型定义在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4053917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the HTML5 Document Type Definition?
提问by ?ime Vidas
The "old" HTML/XHTML standards have a DTD (Document Type Definition) defined for them:
“旧的” HTML/XHTML 标准为它们定义了 DTD(文档类型定义):
HTML 4.01 http://www.w3.org/TR/html401/sgml/dtd.html
XHTML 1.0 http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict
HTML 4.01 http://www.w3.org/TR/html401/sgml/dtd.html
XHTML 1.0 http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict
This DTDs specify the rules for nesting elements - "which types of elements may appear in which types of elements". I made a diagram for XHTML 1.0 here(sorry, I no longer have that resource)
这个 DTD 指定了嵌套元素的规则——“哪些类型的元素可以出现在哪些类型的元素中”。我在这里为 XHTML 1.0 制作了一个图表(对不起,我不再有那个资源)
I would like to update that diagram with a new version which also includes the new HTML5 elements. However, there doesn't seem to be a HTML5 DTD. It seems that the nesting rules are defined by the various content models that are defined in HTML5.
我想用新版本更新该图表,其中还包含新的 HTML5 元素。但是,似乎没有 HTML5 DTD。嵌套规则似乎是由 HTML5 中定义的各种内容模型定义的。
So there is no DTD, correct?
所以没有DTD,对吗?
Follow-up question:Is there a reason why there is no DTD in HTML5? The DTD is such a nice method of defining the nesting rules for all the different types of elements. Why wouldn't they include such a thing?
追问:HTML5没有DTD有什么原因吗?DTD 是为所有不同类型的元素定义嵌套规则的好方法。他们为什么不包括这样的东西?
Update:I found this: http://www.w3.org/TR/html5/dom.html#kinds-of-contentI guess, this is the closest to having a DTD.
更新:我发现了这个:http://www.w3.org/TR/html5/dom.html#kinds-of-content我猜,这是最接近 DTD 的。
Update:The Visual Studio Team made a XML Schema for XHTML5. I guess that answers my question: http://blogs.msdn.com/b/webdevtools/archive/2009/11/18/html-5-intellisense-and-validation-schema-for-visual-studio-2008-and-visual-web-developer.aspx
更新:Visual Studio 团队为 XHTML5 创建了一个 XML 架构。我想这回答了我的问题:http://blogs.msdn.com/b/webdevtools/archive/2009/11/18/html-5-intellisense-and-validation-schema-for-visual-studio-2008-and -visual-web-developer.aspx
采纳答案by Jukka K. Korpela
There is no HTML5 DTD. The HTML5 RC explicitly says thiswhen discussing XHTML serialization, and this clearly applies to HTML serialization as well.
没有 HTML5 DTD。HTML5 RC在讨论 XHTML 序列化时明确说明了这一点,这显然也适用于 HTML 序列化。
DTDs have been regarded by the designers of HTML5 as too limited in expressive power, and HTML5 validators (basically the HTML5 mode of http://validator.nuand its copy at http://validator.w3.org/nu/) use schemas and ad hoc checks, not DTD-based validation.
HTML5 的设计者一直认为 DTD 的表达能力太有限,而 HTML5 验证器(基本上是http://validator.nu的 HTML5 模式及其在http://validator.w3.org/nu/ 上的副本)使用模式和临时检查,而不是基于 DTD 的验证。
Moreover, HTML5 has been designed so that writing a DTD for it is impossible. For example, there is no SGML way to capture the HTML5 rule that any attribute name that starts with “data-” and complies with certain general rules is valid. In SGML, attributes need to be listed individually, so a DTD would need to be infinite.
此外,HTML5 的设计使得为它编写 DTD 是不可能的。例如,没有 SGML 方法来捕获 HTML5 规则,即任何以“data-”开头并符合某些一般规则的属性名称都是有效的。在 SGML 中,属性需要单独列出,因此 DTD 需要是无限的。
It is possible to design DTDs that correspond to HTML5 with some omissions and perhaps with some extra rules imposed, but they won't really be HTML5 DTDs. My experimentwith the idea is not very encouraging: too many limitations, too tricky, and the DTD would need to be so permissive that many syntax errors would go uncaught.
有可能设计出与 HTML5 相对应的 DTD,但有一些遗漏,也许还强加了一些额外的规则,但它们并不是真正的 HTML5 DTD。我对这个想法的实验并不是很令人鼓舞:太多的限制,太棘手,而且 DTD 需要非常宽松,以至于许多语法错误都没有被发现。
回答by Adam
Correct. There is no DTD. However, HTML5 documents should start with <!DOCTYPE html>
So there's a DOCTYPE, but no DTD.
正确的。没有 DTD。但是,HTML5 文档应该<!DOCTYPE html>
以 DOCTYPE开头,但没有 DTD。
See:
看:
回答by Kevin
I have created an HTML5 DTD for use in my PHP XML projects. It ain't beautiful, but it works with well-formed XHTML5 (that is, HTML5 expressed as XML).
我创建了一个 HTML5 DTD 用于我的 PHP XML 项目。它并不漂亮,但它适用于格式良好的 XHTML5(即表示为 XML 的 HTML5)。
You can grab it from my bitbucket account here:
你可以在这里从我的 bitbucket 帐户中获取它:
https://bitbucket.org/kashbridge/dtd/overview
https://bitbucket.org/kashbridge/dtd/overview
Enjoy!
享受!
回答by imhotap
Certain Marcus from sgmljs.net created and analyzedan SGML DTD for HTML 5.1and started a thread in the XML-DEV mailing listfor review and discussion. The discussion revolves around entity definitions so far.
来自 sgmljs.net 的某些 Marcus 创建并分析了HTML 5.1的SGML DTD,并在 XML-DEV 邮件列表中创建了一个线程以供和讨论。到目前为止,讨论围绕实体定义展开。
I've just completed my analysis of W3C's HTML 5.1 recommendation at http://sgmljs.net/docs/html5.html(from a markup language rather than web development PoV), and I'm publishing it here for review in the form of an initial SGML DTD for parsing HTML 5.1, along with a lengthy analysis text.
[…]
I'm aware that WHATWG and W3C have since long moved away from SGML (and XML in most web-related specification work), treating it as a legacy technique and with a somewhat presumptuous attitude in the specification text and elsewhere. But as the analysis of HTML5's grammar shows, they've essentially abandoned use of any formal methods alltogether (and it shows in at least two flaws discussed in the analysis).
我刚刚在http://sgmljs.net/docs/html5.html(来自标记语言而不是 Web 开发 PoV)完成了对 W3C 的 HTML 5.1 建议的分析, 我将其发布在这里以供用于解析 HTML 5.1 的初始 SGML DTD 以及冗长的分析文本。
[…]
我知道 WHATWG 和 W3C 早已远离 SGML(以及大多数与 Web 相关的规范工作中的 XML),将其视为一种遗留技术,并在规范文本和其他地方采取了一种有点冒昧的态度。但是,正如对 HTML5 语法的分析所显示的那样,他们基本上已经完全放弃了使用任何形式化方法(并且在分析中讨论的至少两个缺陷中表明了这一点)。
Nothing official yet, but maybe this initiative will get traction, or at least find its users as an unofficial resource.
目前还没有任何官方消息,但也许这项计划会受到关注,或者至少将其用户视为一种非官方资源。
回答by Blake
I think they did away with the old DTDs, now we just start HTML pages with: <!DOCTYPE HTML>
我认为他们废除了旧的 DTD,现在我们只是开始 HTML 页面: <!DOCTYPE HTML>
Maybe the W3C will come out with one eventually.
也许 W3C 最终会推出一个。