HTML 5、内联 SVG 和 SVG DOM 的命名空间感知 [英] HTML 5, inline SVG, and namespace awareness for SVG DOM

查看:23
本文介绍了HTML 5、内联 SVG 和 SVG DOM 的命名空间感知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下问题让我很困惑.我知道它们是相关的,但是...

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

  1. 是否支持 HTML 5 命名空间(用于包含 SVG/其他 XML 方言的标签)?
  2. 如果不是,那么这个 -<块引用>

    我已阅读此旧链接,但我完全困惑...因为 Mozilla 说要动态修改内联 SVG,需要编写脚本 这种方式"-最后,我如何动态修改内联SVG(如果HTML 5不知道名称空间)?

  1. Is HTML 5 namespace aware (for including tags of SVG/other XML dialects)?
  2. If it is not, then what about this -

  • 或者页面需要作为 (X)HTML 5 提供?
  • <小时>详情 -


    Details -

    以上代码是在 HTML 5 中渲染 rect(使用 SVG)的正确方法.现在,要使用 JavaScript 修改 SVG,Mozilla 建议使用 this API.我的问题是,如果 HTML 5 不知道命名空间,那么这样做的意义何在?对于这种情况,浏览器会自动切换到 (X)HTML 5 吗?

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>hello-SVG</title> </head> <body> <svg width="200" height="200"> <rect x="0" y="0" width="100" height="100" fill="blue"></rect> </svg> </body> </html>

    我阅读了关于 SO 的this评论,我发现它最接近我正在寻找的答案 -

    The above code is the correct way to render a rect (using SVG) in HTML 5. Now, to modify the SVG using JavaScript, Mozilla recommends using this API. And my question is, what is the point of doing so if HTML 5 is not namespace aware? For such cases do browsers automatically switch to (X)HTML 5?

    我猜 HTML 5 SVG 的情况基本上是没有命名空间的 SVG 在解析过程中添加了命名空间(但之后它就像之前的 (X)HTML)".

    I read this comment on SO, and I find it closest to the answer I'm looking for -

    推荐答案

    HTML5 定义了 HTML、XHTML 和 DOM.

    解决方案

    DOM 是命名空间感知的.当您使用 DOM 方法时,您必须考虑每个元素所在的命名空间,但默认是 HTML (http://www.w3.org/1999/xhtml) 命名空间.

    HTML5 defines HTML, XHTML and the DOM.

    HTML 和 XHTML 是通过解析转换成 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.

    XHTML 是命名空间感知的,XHTML 文档根据 XML 规则应用命名空间,因此所有命名空间必须明确分配给每个元素.使用 XML 解析器将 XHTML 转换为 DOM.

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

    HTML 也是命名空间感知的,但命名空间是隐式分配的.使用 HTML 解析器将 HTML 转换为 DOM,该解析器知道哪些元素位于哪个命名空间中.也就是说,它知道

    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.

    进入 http://www.w3.org/1999/xhtml 命名空间并且 进入 http://www.w3.org/2000/svg 命名空间.
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆