HTML5语法 - HTML与XHTML [英] HTML5 syntax - HTML vs XHTML

查看:100
本文介绍了HTML5语法 - HTML与XHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使使用HTML5作为HTML的前进道路,我们也有两种开发者选择:XHTML语法和HTML语法。我一直使用XHTML作为我的主要文档类型5年左右,所以我对它很满意。

但是我的问题是,非xml语法将被允许,是否有理由使用有效的XML语法?除了偏好(兼容性等)之外,你是否还能获得一个优势?就我个人而言,我会感觉有点肮脏,回到不关闭标签,
现在是我的第二天性,但我会获得回到HTML语法的东西?



更新:我猜我的真正问题是有没有理由从XHTML切换到HTML语法?我一直在使用XHTML多年,并不确定是否有理由切换回来。浏览器的兼容性(IE有时会使用application / xhtml + xml mime-type)等等?

解决方案

我想我的真正问题是有
理由从XHTML切换到HTML
语法吗?我一直在使用XHTML
年,并不确定是否有
的原因切换回来。浏览器
的兼容性(IE有时是应用程序/ xhtml + xml
mime-type),等等?


正如前面的答案中所提到的, text / html 被解析为HTML并且 application / xhtml + xml 被解析为XML。因此,您应该使用与您使用的MIME类型匹配的语法。



如果您现在正在为 text / html 但使用XHTML语法,那么您应该修复您的内容以使用HTML5语法。您可能已经很接近了,因为HTML5允许void元素的XMLesque /> 为空元素语法(总是空的元素,比如 img br )。



如果您现在使用应用程序/ xhtml + xml ,如果您关心支持IE,IE支持将是切换到 text / html 和HTML语法的原因。



试图编写正确的HTML5和XHTML5的多语言文档(用于处理不同的MIME类型,具有相同有效字节的不同浏览器)比看起来一见难,不值得麻烦。


Even with HTML5 being the path forward for HTML we get two options as developers: XHTML syntax and HTML syntax. I've been using XHTML as my main doctype for 5 or so years so I'm very comfortable with it.

But my question is given that non-xml syntax will be allowed, is there any reason to stick with a valid XML syntax? Do you gain anything going with one over another, besides preference (compatibility, etc)? Personally I'll feel a little dirty going back to not closing tags,
is second nature to me now, but would I gain something going back to HTML syntax?

Update: I guess my true question is is there a reason to switch from XHTML to HTML syntax? I've been using XHTML for years and not sure if there is a reason to switch back. Browser compatibility (IE was sometimes finiky with the application/xhtml+xml mime-type), etc?

解决方案

I guess my true question is is there a reason to switch from XHTML to HTML syntax? I've been using XHTML for years and not sure if there is a reason to switch back. Browser compatibility (IE was sometimes finiky with the application/xhtml+xml mime-type), etc?

As mentioned in a previous answer, text/html is gets parsed as HTML and application/xhtml+xml gets parsed as XML. Thus, you should use the syntax that matches the MIME type you use.

If you are now serving text/html but using XHTML syntax, then you should fix your content to use the HTML5 syntax. You may already be close, since HTML5 allows the XMLesque /> empty element syntax for void elements (elements that are always empty, such as img and br).

If you are now using application/xhtml+xml, IE support would be a reason to switch to text/html and the HTML syntax if you care about supporting IE.

Trying to write polyglot documents that are correct HTML5 and XHTML5 (for serving different MIME types do different browsers with the same payload bytes) is harder than it seems at first sight and not worth the trouble.

这篇关于HTML5语法 - HTML与XHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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