html - 命名空间和 HTML 5

标签 html namespaces

HTML specs可以找到以下行:

In the HTML syntax, namespace prefixes and namespace declarations do not have the same effect as in XML. For instance, the colon has no special meaning in HTML element names.



在查看语法定义后,有以下部分:

在标签名称上,它指出:

Tags contain a tag name, giving the element's name. HTML elements all have names that only use alphanumeric ASCII characters. In the HTML syntax, tag names, even those for foreign elements, may be written with any mix of lower- and uppercase letters that, when converted to all-lowercase, matches the element's tag name; tag names are case-insensitive.



这几乎没有解释的余地​​。这里没有下划线或美元符号。也没有 ':' 使得不可能合法地表达 namespace 。它还可以只使用像 <1> 这样的数字。但随后是 grammar states :

Uppercase ASCII letter Create a new start tag token, set its tag name to the lowercase version of the current input character (add 0x0020 to the character's code point), then switch to the tag name state. (Don't emit the token yet; further details will be filled in before it is emitted.)

Lowercase ASCII letter Create a new start tag token, set its tag name to the current input character, then switch to the tag name state. (Don't emit the token yet; further details will be filled in before it is emitted.)



所以我们只剩下 <a1234> 之类的东西.

在属性名称上,它指出:

Attributes have a name and a value. Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), ">" (U+003E), "/" (U+002F), and "=" (U+003D) characters, the control characters, and any characters that are not defined by Unicode. In the HTML syntax, attribute names, even those for foreign elements, may be written with any mix of lower- and uppercase letters that are an ASCII case-insensitive match for the attribute's name.



阅读本文似乎这是可能的:
<div ::::::="hello" $_$="dollar"></div>

所有这些使用命名空间作为标签名称是被禁止的,对于属性,这只是一个你可以遵循但不需要遵循的约定。

所以简单地说,HTML 5 的简单命名空间不存在,至少标签名称不能被模拟,我们没有下划线,也没有点或类似的东西。

这个对吗?另一方面,HTML 5 规范声明我们可以自由地向元素添加 xmlns 属性,从而可以清楚地引入新的命名空间。这个怎么搭配?

[更新]
我使用 single page version of the specs 重新检查了规范它实际上表明 xhtml 剩余部分允许使用 namespace 声明,但实际上必须忽略它,因此我们没有 namespace 。伤心事。
[/更新]

所以剩下的唯一问题是,如果没有 ':' 或其他任何东西,我可以合法地使用元素标签名称做什么。我可以用我编的一些特别的吗?请记住,我们在这里对解析器有一个宽松的规范。解析器应该以一种可以处理未知元素标签的方式构建。这里的问题是,他们如何处理未知元素标签?

最佳答案

HTML 5 规范仅允许与 xhtml 文档规范相关的 xmlns namespace 属性。这些 namespace 将被忽略且不被重视。

规范的标签名称部分有点令人困惑,因为它只讨论了 HTML 元素。标签名称的解析器部分显示:

8.2.4.10 Tag name state

Consume the next input character:

"tab" (U+0009)
"LF" (U+000A)
"FF" (U+000C)
U+0020 SPACE
-> Switch to the before attribute name state.

"/" (U+002F)
-> Switch to the self-closing start tag state.

">" (U+003E)
-> Switch to the data state. Emit the current tag token.

Uppercase ASCII letter
-> Append the lowercase version of the current input character (add 0x0020 to the character's code point) to the current tag token's tag name.

U+0000 NULL
-> Parse error. Append a U+FFFD REPLACEMENT CHARACTER character to the current tag token's tag name.

EOF
-> Parse error. Switch to the data state. Reconsume the EOF character.

Anything else
-> Append the current input character to the current tag token's tag name.



最后一行是重要的部分。此外,规范仅声明了定义为那些的 HTML 元素。因此我们可以自由地做类似的事情,它被认为是一个有效的元素,但不是一个有效的 HTML 元素。问题是浏览器或编辑器如何对这个角色汤使用react。但同样它是一个有效的元素名称,但不是一个有效的 HTML 元素名称。

关于html - 命名空间和 HTML 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20314876/

相关文章:

php - 使用 namespace 重定位和重命名类

php - 使用 Composer 自动加载器时访问类时出错

WCF:我需要用动态命名空间替换 "http://tempuri.org/"吗?

javascript - 在日期字段中自动插入斜杠 '/' 的最佳方法是什么

javascript - Android WebView (WebChromeClient) 语音合成未定义

html - HTML 中输入标签的高度

ruby-on-rails - 嵌套命名空间路由到错误的 Controller

html - Bootstrap 4.5 如何更改容器网格装订线宽度

php - 在内联 CSS 中使用 $_POST

ruby-on-rails - rails 3 - 命名空间 - 查看器助手生成错误的路由