浏览器是否支持带有使用名称空间的标记的HTML文档(请参阅代码)? [英] Do browsers support an HTML document with markup that uses namespaces (see code)?

查看:101
本文介绍了浏览器是否支持带有使用名称空间的标记的HTML文档(请参阅代码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来好像可以在HTML文档中使用名称空间。虽然,我从来没有见过它完成。如果我在文档中使用名称空间,浏览器是否可以正确显示它?



这里是您的HTML:

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

以下是关于命名空间的HTML:

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

有问题吗?

仅供参考SVG使用名称空间并通过浏览器正确显示。请参阅

当您只是在自己的基于XML的环境中工作时,这一切都是不同的,其中您展示的两个XML确实非常相似。但即使如此,您仍应确保无论环境如何与外界的假设相匹配,例如HTML根本不使用名称空间前缀。


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.

解决方案

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.

这篇关于浏览器是否支持带有使用名称空间的标记的HTML文档(请参阅代码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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