什么是HTML / HTML5的默认命名空间? [英] What is the default namespace for HTML / HTML5?

查看:191
本文介绍了什么是HTML / HTML5的默认命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据某些用户的页面命名为w3c的HTML默认名称空间为:

  http://www.w3.org/1999/xhtml 

他显然是错误的,因为xhtml被用于失败的基于XML的HTML4标准。什么是我应该使用的正确的命名空间?

背景:
我在写一个使用XML的应用程序。我希望能够使用名称空间将数据保存在XML节点上。例如,

 < s:Button width =100height =100html:color =bluecolor =black/> 

XML解析器需要html前缀的命名空间才能生效。

解决方案

正如W3C所记载的那样,XML和HTML规范背后的主体是谁(WHATWG有单独的HTML 5规范,但尽管它在某些方面与W3C规范不同步,但WHATWG仍然认为它是W3C将规范标准化为REC的角色),这是用于HTML序列化时的HTML命名空间(有时称为XHTML)是 http://www.w3.org/1999/xhtml



该命名空间涵盖所有版​​本的HTML,带有迄今为止已经规定的XML序列化,包括XHTML 1.0和1.1,它们在过去十年中已经相当使用,XHTML 2.0引入了几个模块化的想法,但它可以作为一些想法的孵化器而不是作为实现的版本,以及HTML5序列化为XML,有时被称为XHTML5。



由于另一个正在讨论如何指定HTML 5的机构, WHATWG,你可以请注意,他们还说如果您将HTML5序列化为XML,那么您必须使用名称空间 http://www.w3.org/1999/xhtml 以及其他序列化要么不使用命名空间,要么使用该命名空间。根据 https://wiki.whatwg.org/wiki/FAQ#What_is_the_namespace_declaration.3F


在XHTML中,您需要指定名称空间。



< html xmlns =http://www.w3.org/1999/xhtml>



在HTML中,任何HTML元素当前都允许使用xmlns属性,但只有具有值 http:/ /www.w3.org/1999/xhtml 。它根本没有做任何事情,只允许它轻松从XHTML1迁移。它实际上并不是HTML中的名称空间声明,因为HTML尚不支持名称空间。


下面的常见问题也适用于这里:


HTML是根据DOM定义的,在解析text / html的过程中,所有的HTML元素都会自动放入HTML命名空间 http://www.w3.org/1999/xhtml 。但是,与XHTML序列化不同,HTML序列化中没有可用的实际名称空间语法(请参阅上一个问题)。换句话说,您不需要像在XHTML中那样在HTML标记中声明命名空间。但是,只要命名空间是 http://www.w3.org/1999/xhtml ,就可以在每个HTML元素上放置xmlns属性。



另外,HTML语法提供了嵌入MathML和SVG元素的方法。放置在容器元素 math svg 中的元素将分别自动放入MathML名称空间或SVG名称空间中,通过解析器。名称空间语法不是必需的,但是如果它的值是正确的名称空间,则允许再次使用xmlns属性。



总之,虽然HTML不允许使用XML名称空间语法,是一种嵌入MathML和SVG的方法,xmlns属性可以在给定约束条件下的任何元素上使用,并且可以在DOM级别上合理兼容。



According to this page by some user named "w3c" the default namespace for HTML is:

http://www.w3.org/1999/xhtml

He's obviously wrong since xhtml was used for a failed XML based HTML4 standard. What is the correct namespace I should use?

Background: I'm writing an app that uses XML. I want to be able to save data on the XML node using namespaces. For example,

<s:Button width="100" height="100" html:color="blue" color="black" /> 

The XML parser needs a namespace for the "html" prefix to be valid.

解决方案

As documented by the W3C, who are the body behind both the XML and HTML specifications (WHATWG has a separate HTML 5 spec, but while it in some ways out of sync with the W3C spec, WHATWG does still consider it the W3C's role to bring standardise a spec as a REC), the namespace for HTML when used with an XML serialisation (which is sometimes refered to as XHTML) is http://www.w3.org/1999/xhtml.

This namespace covers all versions of HTML with such XML serialisations that have been specified so far including XHTML 1.0 and 1.1 which were in considerable use for over a decade, XHTML 2.0 which introduced several modular ideas but which was arguably of more import as an incubator for several ideas than as an implemented version, and "HTML5 serialized as XML" which is sometimes called XHTML5.

Since the other body with a horse in the race as to just how HTML 5 is specified is WHATWG, you may note that they also say that if you are serialising HTML5 as XML then you must use the namespace http://www.w3.org/1999/xhtml and with the other serialisation either not use a namespace, or use that one. Per 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.

The next FAQ is also relevant here:

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.

这篇关于什么是HTML / HTML5的默认命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆