HTML5是否有效的XML? [英] Is HTML5 valid XML?

查看:149
本文介绍了HTML5是否有效的XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑。一位同事转而指出,以 /> gt; 结尾的标签,例如< br /> 仍然可以在HTML5中使用。我认为只有< br> -style可以使用。所有在互联网上的谈话都是关于使用后者的。

有人可以向我解释这个吗?这看起来很混乱,并且记录不完全。



这引出了另一个问题:HTML 5是否被认为是格式良好的XML?

解决方案

没有。反例:

以下是有效的HTML5,但是无效的XHTML5:


  1. 可以省略一些结束标记:

     < p>首先
    < p>第二个

    请参阅:在HTML中不需要P-end-tag(< / p>)


  2. 脚本逃脱魔术:

     <脚本>< a取代;< /脚本> 

    请参阅:


  3. 没有值的属性(布尔属性):

     < input type =textdisabled /> 

    请参阅:更正已禁用属性的值


  4. 不带引号的属性,例如:

     < div data-a = b>< / div> 

    请参阅:在XHTML 1.0中,严格的do属性值需要用引号包围?


  5. 隐式开放元素和多个顶级元素。



    一些HTML元素是隐式创建的。例如。 HTML 。这允许HTML具有多个顶级元素:

     <!doctype html>< title> a<标题>< p>一种与LT; / p为H. 

    请参阅:


有效的XHTML无效HTML:



  1. ENTITY 以及其他感叹号标记结构中的CDATA ,这让人笑了:亿笑笑XML DoS攻击工作?


有效的HTML和XHTML,但含义不同:


  1. HTML有数百个命名字符引用(例如& pound; & copy; ) ,XML只有5个( quot amp lt gt )。


I am confused. A co-worker turned me on to the possibility that tags ending in />, such as <br /> can still be used in HTML5. I thought that only <br>-style could be used. All of the "talk" across the Internet is about using the latter.

Could someone please explain this to me? This seems very confusing and poorly documented.

And this brings up another question: Is HTML 5 considered to be well-formed XML?

解决方案

No. Counter-examples:

These are valid HTML5 but invalid XHTML5:

  1. Some closing tags can be omitted:

    <p>First
    <p>Second
    

    See: P-end-tag (</p>) is not needed in HTML

  2. script escape magic:

    <script><a></script>
    

    See: What is CDATA in HTML?

  3. Attributes without values (boolean attributes):

    <input type="text" disabled />
    

    See: Correct value for disabled attribute

  4. Attributes without quotes, e.g.:

    <div data-a=b></div>
    

    See: In XHTML 1.0 Strict do attribute values need to be surrounded with quotes?

  5. Implicit open elements and multiple top level elements.

    Some HTML elements are created implicitly. E.g. html. This allows the HTML to have "multiple top level elements":

    <!doctype html><title>a</title><p>a</p>
    

    See: Is it necessary to write HEAD, BODY and HTML tags?

Valid XHTML that is invalid HTML:

  1. CDATA constructs with invalid tags inside

  2. ENTITY and other exclamation mark constructs, which allow for billion laughs: How does the billion laughs XML DoS attack work?

Valid HTML and XHTML but with different meanings:

  1. HTML has hundreds of named character references (e.g. &pound;, &copy;), XML has only 5 (quot, amp, apos, lt, gt).

这篇关于HTML5是否有效的XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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