xml - xmlns 属性在哪里定义?

标签 xml xml-namespaces

我知道这是正确的 XML

<Data xmlns="http://w3.schools.com">
  <One>Data1</One>
</Data>

xmlns 是一个属性,使用上述语法意味着所有节点都属于双引号中的命名空间。我无法理解的是 xmlns 属性在哪里定义?

最佳答案

参见 Namespaces in XML 1.0 W3C Recommendation xmlns 属性和 xmlns: 前缀的定义。

使用xmlns的原因总结:

  • 使用xmlns作为属性来定义一个XML命名空间,它是一个 命名标准旨在让各方独立定义 元素和属性名称的词汇表,同时避免命名 碰撞。
  • 使用 xmlns: 作为前缀 定义自定义前缀,XML 命名空间值可以通过简写方式引用。

属性xmlns

属性 xmlns 是一个 reserved attribute并且是 defined as follows :

DefaultAttName ::= 'xmlns'

前缀xmlns:

前缀 xmlns: 是一个 reserved prefixdefined as follows :

[2] PrefixedAttName ::= 'xmlns:' NCName

另见 Namespace constraint: Reserved Prefixes and Namespace Names

The prefix xmlns is used only to declare namespace bindings and is by definition bound to the namespace name http://www.w3.org/2000/xmlns/. It MUST NOT be declared . Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. Element names MUST NOT have the prefix xmlns.

引用自XML Recommendation

2.3 Common Syntactic Constructs

Note:

The Namespaces in XML Recommendation [XML Names] assigns a meaning to names containing colon characters. Therefore, authors should not use the colon in XML names except for namespace purposes, but XML processors must accept the colon as a name character.

关于xml - xmlns 属性在哪里定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38634877/

相关文章:

xml - 我可以在不使用编译器的情况下使用 clang 获取 C/C++ 代码的 XML AST 转储吗?

xml - 通过 XSD 限制基于另一个元素的 XML 元素

jaxb - 使用 jaxb 将命名空间添加到 xml 的根元素

xsd - 在 XML Schema 中为不同的命名空间声明一个属性

xml - 如何使用 PowerShell 注释掉 XML 中的节点?

xml - 具有不同来源的查询条目?

wpf - WPF 中的 XML 命名空间 - xmlns

php - 当 xpath 在 xml 中找不到命名空间时避免错误

javascript - XML 到 JSON - 在 JavaScript 中处理 xml namespace 和别名

java - 我应该如何使用 org.w3c.dom.Node.getNamedItemNS(nsUri, name) 选择 XML "namespaced"节点?