为什么命名空间参数?

Why namespaced parameters?

From the "Namespaces Crash Course" by Mozilla: "sometimes it is necessary to define parameters so that they can be reused on many different elements and still be considered to be the same parameter, independently of the element with which they are used."

给出的例子:

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <script xlink:href="cool-script.js" type="text/ecmascript"/>
</svg>

有人可以举例说明为什么要为参数命名空间吗?我看到他们正在引用 xlink 命名空间,并且只将 href 参数与 xlink 相关联。但这意味着元素本身是一个独立于参数的命名空间。

此外,显然 SVG 2.0 是 deprecating the use of Xlink in favor of a plain ole href attribute。这意味着您可以从 xlink:href 中删除 xlink:。在 2.0 之前,如果没有它,您是否无法 link SVG 元素?它是否像一个 mixin,您可以在其中将来自其他 xml 工具 ("dialects") 的新属性添加到元素中,有点像给元素注入类固醇或益智药以使其变得更好?

当时的想法是链接是一种通用功能,多个规范会使用它。这从来没有真正流行过,这就是为什么它基本上被放弃而赞成将所有东西放在一个命名空间中的原因。

假设您有一个 XML 描述狗和树的文件,因为狗喜欢从特定的树上取树枝。

所以狗有吠叫属性,树也有。也许这没关系,只是有人在库存中放了一只会发出吠叫声的木狗。

  1. 您不能拥有多个具有给定名称的属性,或者您的 XML 无效
  2. 如果木狗有吠叫属性是什么意思?

命名空间将允许您拥有噪声命名空间和树命名空间,并具有 tree:bark 或 noise:bark,因此您知道哪个属性是哪个。