我一直在努力反对 xsd:ID 不允许在 id 属性中使用冒号(“:”)。我第一次注意到这一点是在 Emacs 中使用 James Clark 的 nxml-mode 时,因为它验证了我正在使用的 XHTML 文件。然后,我使用 Jing 针对 RNG(由 nxml-mode-20041004 提供)运行 XHTML 文件,并收到以下错误:
error: value of attribute "id" is invalid; must be an XML name without colons
我见过的大多数 W3 页面都表明冒号有效。然后我发现了这个, http://www.w3.org/XML/xml- 19980210-errata#E98,我的意思是:“你不应该在 id 属性中使用冒号,但你应该被允许这样做。”鉴于这种解释,我很困惑为什么Jing说我不能。
谢谢你,
扎卡里
I've been banging my head against xsd:ID not allowing a colon (":") in an id attribute. I first noticed this when using James Clark's nxml-mode in Emacs as it validated an XHTML file I was working with. I then ran the XHTML file against the RNG (provided with nxml-mode-20041004) using Jing and received the following error(s):
error: value of attribute "id" is invalid; must be an XML name without colons
Most of the W3 pages I've seen indicate that a colon is valid. Then I found this, http://www.w3.org/XML/xml-19980210-errata#E98, which I take to mean: "you shouldn't use a colon in an id attribute, but you should be allowed to." Given that interpretation, I'm stumped why Jing says I can't.
Thank you,
Zachary
发布评论
评论(1)
您在这里看到的是两个略有不同的定义。 xsd:ID 是根据 定义的 "http://www.w3.org/TR/xml-names/#ns-decl" rel="nofollow">XML 1.0 中的命名空间 和基本 XML 标准的 ID 类型是根据以下内容定义的名称类型。两者共享以下定义:
NCName 定义为:
名称减去冒号。
其结果是,就 XML 本身而言,键入为 ID 的值可以包含冒号。对于使用 XML 模式数据类型的任何内容(例如您的 RelaxNG 模式),存在更受限制的数据类型,禁止使用冒号。任何使用 XML 模式兼容属性的内容都将根据基本定义有效,但反之则不一定。
You're looking at two subtly different definitions here. xsd:ID is defined in terms of the NCName type in Namespaces in XML 1.0 and the ID type of the base XML standard is defined in terms of the Name type. Both share the following definition:
NCName is defined as:
which is Name minus the colon.
The result of this is that in terms of XML itself, the value of something typed as ID can contain a colon. In terms of anything that uses the XML Schema datatypes (such as your RelaxNG schema) there is more restricted data type in use which forbids the use of the colon. Anything that uses an XML Schema compliant attribute will be valid against the base definition but not necessarily the other way around.