28

“空”是 XML 命名空间的有效值吗?如果是的话是什么意思?

我有以下 XML 代码,但我不确定属于哪个名称空间Field1Field2元素。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header />
  <soap:Body>
    <Root xmlns="uri">
      <Field1 xmlns="">147079737</Field1>
      <Field2 xmlns="">POL</Field2>
    </Root>
  </soap:Body>
</soapenv:Envelope>
4

2 回答 2

27

是的,它是有效的。XML 1.0 建议中的命名空间中的第 6.2 节特别指出:

默认命名空间声明中的属性值可以为空。在声明的范围内,这与没有默认命名空间的效果相同。

引用自评论:

这是合法的,这是将元素带入全局命名空间的方式。

于 2009-10-19T10:17:02.160 回答
5

It is not a valid XML NS. It is not a valid XML NS declaration. Please check section 2.2 of Namespaces in XML 1.0 :

The empty string, though it is a legal URI reference, cannot be used as a namespace name.

It is however the only way to undeclare a default NS declaration if there is one in effect, or it has no effect. See Namespaces in XML 1.0 and 1.1, section 6.2. The 1.1 NS rec added a way to also undeclare a NS declaration with a prefix.

Thus it is a valid value for the xmlns special attribute, but it is not "a valid XML namespace" like the OP wrote it.

于 2014-10-30T19:48:57.803 回答