HTML / HTML5 的默认命名空间是什么?
What is the default namespace for HTML / HTML5?
根据一些名为 "w3c" 的用户 page,HTML 的默认名称空间是:
http://www.w3.org/1999/xhtml
他显然是错误的,因为 xhtml 被用于失败的 XML 基于 HTML4 的标准。我应该使用什么正确的命名空间?
背景:
我正在编写一个使用 XML 的应用程序。我希望能够使用名称空间将数据保存在 XML 节点上。例如,
<s:Button width="100" height="100" html:color="blue" color="black" />
XML 解析器需要命名空间才能使 "html" 前缀有效。
根据 W3C 的记录,body 支持 XML 和 HTML 规范(WHATWG 有一个单独的 HTML 5 规范,但是虽然它在某些方面与 W3C 规范不同步,WHATWG 仍然认为 W3C 的角色是将规范标准化为 REC),HTML 的命名空间与 XML 序列化一起使用(这是有时称为 XHTML) 是 http://www.w3.org/1999/xhtml
.
这个命名空间涵盖了 HTML 的所有版本,这些 XML 序列化到目前为止已经指定,包括 XHTML 1.0 和 1.1,它们已经被广泛使用了十多年, XHTML 2.0 引入了几个模块化的想法,但可以说它作为几个想法的孵化器比作为一个实施版本更重要,"HTML5 serialized as XML" 有时被称为 XHTML5.
因为另一个 body 与一匹马在比赛中关于如何指定 HTML 5 是 WHATWG,你可能会注意到他们也说如果你正在序列化 HTML5 as XML 那么你必须使用命名空间 http://www.w3.org/1999/xhtml
并且对于其他序列化要么不使用命名空间,要么使用那个命名空间。每 https://wiki.whatwg.org/wiki/FAQ#What_is_the_namespace_declaration.3F:
In XHTML, you are required to specify the namespace.
<html xmlns="http://www.w3.org/1999/xhtml">
In HTML, the xmlns attribute is currently allowed on any HTML element, but only if it has the value “http://www.w3.org/1999/xhtml“. It doesn’t do anything at all, it is merely allowed to ease migration from XHTML1. It is not actually a namespace declaration in HTML, because HTML doesn’t yet support namespaces. See the question will there be support for namespaces in HTML.
下一个常见问题解答也与此相关:
HTML is being defined in terms of the DOM and during parsing of a text/html all HTML elements will be automatically put in the HTML namespace, http://www.w3.org/1999/xhtml
. However, unlike the XHTML serialization, there is no real namespace syntax available in the HTML serialization (see previous question). In other words, you do not need to declare the namespace in your HTML markup, as you do in XHTML. However, you are permitted to put an xmlns attribute on each HTML element as long as the namespace is http://www.w3.org/1999/xhtml
.
In addition, the HTML syntax provides for a way to embed elements from MathML and SVG. Elements placed inside the container element math
or svg
will automatically be put in the MathML namespace or the SVG namespace, respectively, by the parser. Namespace syntax is not required, but again an xmlns attribute is allowed if its value is the right namespace.
In conclusion, while HTML does not allow the XML namespace syntax, there is a way to embed MathML and SVG and the xmlns attribute can be used on any element under the given constraints, in a way that is reasonably compatible on the DOM level.
XHTML
以下默认名称空间声明在 XHTML 中是 required 以严格符合文档:
<html xmlns="http://www.w3.org/1999/xhtml">
The root element of the document must contain an xmlns declaration for
the XHTML namespace [XMLNS]. The namespace for XHTML is defined to be
http://www.w3.org/1999/xhtml
HTML5
相同的默认命名空间声明是 optional in HTML5:
<html xmlns="http://www.w3.org/1999/xhtml">
... you do not need to declare the namespace in your HTML markup, as you
do in XHTML. However, you are permitted to put an xmlns attribute on
each HTML element as long as the namespace is
http://www.w3.org/1999/xhtml
根据一些名为 "w3c" 的用户 page,HTML 的默认名称空间是:
http://www.w3.org/1999/xhtml
他显然是错误的,因为 xhtml 被用于失败的 XML 基于 HTML4 的标准。我应该使用什么正确的命名空间?
背景: 我正在编写一个使用 XML 的应用程序。我希望能够使用名称空间将数据保存在 XML 节点上。例如,
<s:Button width="100" height="100" html:color="blue" color="black" />
XML 解析器需要命名空间才能使 "html" 前缀有效。
根据 W3C 的记录,body 支持 XML 和 HTML 规范(WHATWG 有一个单独的 HTML 5 规范,但是虽然它在某些方面与 W3C 规范不同步,WHATWG 仍然认为 W3C 的角色是将规范标准化为 REC),HTML 的命名空间与 XML 序列化一起使用(这是有时称为 XHTML) 是 http://www.w3.org/1999/xhtml
.
这个命名空间涵盖了 HTML 的所有版本,这些 XML 序列化到目前为止已经指定,包括 XHTML 1.0 和 1.1,它们已经被广泛使用了十多年, XHTML 2.0 引入了几个模块化的想法,但可以说它作为几个想法的孵化器比作为一个实施版本更重要,"HTML5 serialized as XML" 有时被称为 XHTML5.
因为另一个 body 与一匹马在比赛中关于如何指定 HTML 5 是 WHATWG,你可能会注意到他们也说如果你正在序列化 HTML5 as XML 那么你必须使用命名空间 http://www.w3.org/1999/xhtml
并且对于其他序列化要么不使用命名空间,要么使用那个命名空间。每 https://wiki.whatwg.org/wiki/FAQ#What_is_the_namespace_declaration.3F:
In XHTML, you are required to specify the namespace.
<html xmlns="http://www.w3.org/1999/xhtml">
In HTML, the xmlns attribute is currently allowed on any HTML element, but only if it has the value “http://www.w3.org/1999/xhtml“. It doesn’t do anything at all, it is merely allowed to ease migration from XHTML1. It is not actually a namespace declaration in HTML, because HTML doesn’t yet support namespaces. See the question will there be support for namespaces in HTML.
下一个常见问题解答也与此相关:
HTML is being defined in terms of the DOM and during parsing of a text/html all HTML elements will be automatically put in the HTML namespace,
http://www.w3.org/1999/xhtml
. However, unlike the XHTML serialization, there is no real namespace syntax available in the HTML serialization (see previous question). In other words, you do not need to declare the namespace in your HTML markup, as you do in XHTML. However, you are permitted to put an xmlns attribute on each HTML element as long as the namespace ishttp://www.w3.org/1999/xhtml
.In addition, the HTML syntax provides for a way to embed elements from MathML and SVG. Elements placed inside the container element
math
orsvg
will automatically be put in the MathML namespace or the SVG namespace, respectively, by the parser. Namespace syntax is not required, but again an xmlns attribute is allowed if its value is the right namespace.In conclusion, while HTML does not allow the XML namespace syntax, there is a way to embed MathML and SVG and the xmlns attribute can be used on any element under the given constraints, in a way that is reasonably compatible on the DOM level.
XHTML
以下默认名称空间声明在 XHTML 中是 required 以严格符合文档:
<html xmlns="http://www.w3.org/1999/xhtml">
The root element of the document must contain an xmlns declaration for the XHTML namespace [XMLNS]. The namespace for XHTML is defined to be http://www.w3.org/1999/xhtml
HTML5
相同的默认命名空间声明是 optional in HTML5:
<html xmlns="http://www.w3.org/1999/xhtml">
... you do not need to declare the namespace in your HTML markup, as you do in XHTML. However, you are permitted to put an xmlns attribute on each HTML element as long as the namespace is http://www.w3.org/1999/xhtml