HTML 5 Adding XML Namespaces

2019-02-22 12:00发布

问题:

Can anyone tell me how you add additional XML namespaces to an HTML 5 document?

I'm trying to create an HTML 5 version of the following

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="https://www.facebook.com/2008/fbml">

Is it simply a case of dropping the xhtml namespace:

<html xmlns:og="http://ogp.me/ns#"
      xmlns:fb="https://www.facebook.com/2008/fbml">

Thanks.

回答1:

According to the WHATWG, in html 5 you are permitted to use the xmlns attribute on each html element as long as the namespace is http://www.w3.org/1999/xhtml (the namespace of the document)

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