Why does Jing not allow a colon (“:”) in an id attribute?

半世苍凉 提交于 2019-12-12 18:32:30

问题


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:


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:

NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | 
    [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | 
    [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | 
    [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | 
    [#x10000-#xEFFFF]
NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | 
    [#x0300-#x036F] | [#x203F-#x2040]
Name ::= NameStartChar (NameChar)*

NCName is defined as:

NCName ::=  Name - (Char* ':' Char*) 

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.



来源:https://stackoverflow.com/questions/6811188/why-does-jing-not-allow-a-colon-in-an-id-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!