Do browsers support an HTML document with markup that uses namespaces (see code)?

时间秒杀一切 提交于 2019-12-12 04:52:58

问题


It seems like it's possible to use namespaces in an HTML document. Although, I've never seen it done. If I used namespaces in my document would browsers render it correctly?

Here is your HTML:

<html>
<head>
</head>
<body>
   <input type="button"/>
</body>
</html>

Here is your HTML on namespaces:

<h:html xmlns:h="http://www.w3.org/1999/xhtml">
<h:head>
</h:head>
<h:body>
   <h:input type="button"/>
   <svg:svg xmlns="http://www.w3.org/2000/svg"/>
</h:body>
</h:html>

Any questions?

FYI SVG uses namespaces and is rendered correctly by browsers. See this.


回答1:


Using XML mechanisms (like XML namespaces and prefixes and assuming that clients correctly process markup according to the XML processing model) is not a robust way to publish HTML. When publishing HTML, make sure you're doing it with what XML would call the "default namespace". You might get lucky that some browsers implement namespaces, or simply ignore prefixes, but I would recommend to not count on that. That's all different when you're just working in your own XML-based environment, where the two XML you're showing indeed are pretty much equivalent. But even then you should make sure that whatever leaves that environment matches the outside world's assumptions, such as HTML not using namespace prefixes at all.



来源:https://stackoverflow.com/questions/34407647/do-browsers-support-an-html-document-with-markup-that-uses-namespaces-see-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!