简体   繁体   English

XML:具有空URI的名称空间

[英]XML: namespace with an empty URI

Why the XML validator does not allow the use of an empty namespace URI? 为什么XML验证程序不允许使用空的名称空间URI? Is it the validator ( http://www.xmlvalidation.com ) feature or the feature of XML in general? 它是验证器( http://www.xmlvalidation.com )功能还是XML的一般功能?

<?xml version="1.0"?>
<root xmlns:em="">
<em:elem/>  
</root>

Is it valid to use any string in namespace URI? 在名称空间URI中使用任何字符串是否有效? (eg xmlns="abcd") (例如xmlns =“ abcd”)

Use of an empty string in a namespace declaration has a specific meaning in XML Namespaces 1.1: it turns it into an "undeclaration", so within its scope, the prefix "em" is not associated with any URI. 在XML命名空间1.1中,在名称空间声明中使用空字符串具有特定含义:将其转换为“未声明”,因此在其范围内,前缀“ em”不与任何URI关联。 But XML Namespaces 1.1 has never been widely adopted, either by users or by XML parser writers. 但是XML命名空间1.1从未被用户或XML解析器编写者广泛采用。

XML Namespaces 1.0 explicitly says (§2.2): The empty string, though it is a legal URI reference, cannot be used as a namespace name. XML命名空间1.0明确指出(第2.2节):空字符串尽管是合法的URI引用,但不能用作命名空间名称。

The answer to the question "Is it valid to use any string in namespace URI?" 问题“在名称空间URI中使用任何字符串有效吗?” is a complex one. 是一个复杂的。 The XML namespaces spec says on the one hand: XML名称空间规范一方面说:

 An XML namespace is identified by a URI reference

and

    The attribute's normalized value MUST be either a URI reference — 
the namespace name identifying the namespace — or an empty string.

It also says: 它还说:

    The use of relative URI references, including 
same-document references, in namespace declarations 
is deprecated.

(Your example xmlns:p="abcd" uses a relative URI reference.) (您的示例xmlns:p="abcd"使用相对的URI引用。)

But when it comes to defining conformance rules (§7) it does NOT say that a conformant document must use valid URIs in its namespace declarations, and I know this was a deliberate decision (because I challenged it at the time). 但是,在定义一致性规则(第7节)时,并不是说一致性文档必须在其命名空间声明中使用有效的URI,而且我知道这是一个有意的决定(因为我当时对此提出了质疑)。 In practice the vast majority of XML parsers and applications allow any string as a namespace name, but there are a few exceptions, such as the XOM library, and I would advise anyone to choose absolute URIs as good practice. 在实践中,绝大多数XML解析器和应用程序都允许将任何字符串用作名称空间名称,但是也有一些例外,例如XOM库,我建议任何人都选择绝对URI作为最佳实践。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM