默认情况下声明哪些XML命名空间?

默认情况下声明哪些
XML命名空间,不需要/不能声明? 最佳答案 简而言之:

> http://www.w3.org/XML/1998/namespace,前缀为xml
> http://www.w3.org/2000/xmlns/,前缀为xmlns

Namespaces in XML 1.0 (Third Edition)Namespaces in XML 1.1 (Second Edition)都只定义了两个名称空间:

Namespace constraint: Reserved Prefixes and Namespace Names

The prefix xml is by definition bound to the namespace name
http://www.w3.org/XML/1998/namespace. It MAY, but need not, be
declared, and MUST NOT be undeclared or bound to any other namespace
name. Other prefixes MUST NOT be bound to this namespace name, and it
MUST NOT be declared as the default namespace.

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 or
undeclared. 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.

All other prefixes beginning with the three-letter sequence x, m, l,
in any case combination, are reserved. This means that:

  • users SHOULD NOT use them except as defined by later specifications
  • processors MUST NOT treat them as fatal errors.

因此,只有http://www.w3.org/XML/1998/namespace(前缀为xml,包含一些属性,如xml:lang,see full list here)和http://www.w3.org/2000/ xmlns /(带有前缀xmlns,用于声明其他名称空间)实际上是在标准中定义的.

某些XML处理库可能会将http://www.w3.org/2001/XMLSchema(前缀为xs)和http://www.w3.org/2001/XMLSchema-instance(前缀为xsi)提升到接近默认状态,甚至在编写XML文件时默认编写这些命名空间的xmlns声明,但这只是惯例,不能作为标准行为依赖.

点赞