HTML 5, inline SVG, and namespace awareness for SVG DOM

后端 未结 1 1566
一生所求
一生所求 2020-12-03 05:29

The following questions are confusing me. I know they are related, but...

  1. Is HTML 5 namespace aware (for including tags of SVG/other XML dialects)?
相关标签:
1条回答
  • 2020-12-03 06:16

    HTML5 defines HTML, XHTML and the DOM.

    The DOM is namespace aware. When you use DOM methods you must take into account which namespace each element is in, but the default is the HTML (http://www.w3.org/1999/xhtml) namespace.

    HTML and XHTML are serializations that are converted into DOMs by parsing.

    XHTML is namespace aware and XHTML documents apply namespaces according to the rules of XML, so all namespaces must be assigned to each element explicitly. XHTML is converted to a DOM using an XML parser.

    HTML is also namespace aware, but namespaces are assigned implicitly. HTML is converted to a DOM using an HTML parser, which knows which elements go in which namespace. That is, it knows that <div> goes in the http://www.w3.org/1999/xhtml namespace and that <svg> goes in the http://www.w3.org/2000/svg namespace. Elements like <script> can go in either the http://www.w3.org/1999/xhtml or the http://www.w3.org/2000/svg namespace depending on the context in which they appear in the HTML code.

    The HTML parser knows about HTML elements, SVG elements, and MathML elements and no others. There is no option to use elements from other namespaces, neither implicitly nor explicitly. That is, xmlns attributes have no effect.

    0 讨论(0)
提交回复
热议问题