属性值“ 001”为0。启用命名空间时,类型ID的ID必须为NCName [英] Attribute value "001" of type ID must be an NCName when namespaces are enabled
问题描述
所以我要使用自己的DTD创建xml文件。
So i'm creating a xml file with my own DTD.
简化的XML如下:
<!DOCTYPE catalog [
<!ELEMENT catalog (product+)>
<!ELEMENT product (title?, price, creation_date?, weight?, color, description?)>
<!ELEMENT creation_date (day, month, year)>
<!ATTLIST product category (art|dinner_set|ovenware) "art">
<!ATTLIST product id ID #REQUIRED>
<!ELEMENT id (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT day (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT weight (#PCDATA)>
<!ELEMENT color (#PCDATA)>
<!ELEMENT description (#PCDATA)>
]>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<catalog>
<product category="art" id="001">
<title>1Blue Sculpture</title>
<price>$2000</price>
<creation_date>
<day>11</day>
<month>08</month>
<year>2014</year>
</creation_date>
<weight>257g</weight>
<color>Green</color>
<description>A beutiful Green Sculpture</description>
</product>
当我尝试通过XML Validater运行它时,出现错误属性值 001启用名称空间时,类型ID必须为NCName。对于每个id属性。
When i try and run it through a XML Validater i get an error "Attribute value "001" of type ID must be an NCName when namespaces are enabled." for each of the id attributes.
我已经对其进行了一段时间的修改,似乎不允许数字,字母很好并且可以顺利通过,但是只要设置id =(任何数字),就会给我错误。
I've mucked around with it for awhile and it seems to not allow numerals, letters are fine and it passes without any problems, but as soon as you set id="(any numbers)" it gives me the error.
我是一个完整的XML NOOB,所以我猜它很简单,我
Im a complete XML NOOB, so i'm guessing its something simple, i searched around but couldnt find anything definitive that was easy to do/undertsand.
推荐答案
是的,问题在于属性值 001
。类型为 ID
的属性值必须与XML语法的 Name
生成形式匹配,这意味着数字(以及其他一些字符)
Yes, the problem is the attribute value 001
. Attribute values of type ID
must match the Name
production of the XML grammar, which means that digits (and some other characters) are disallowed as initial characters.
属性值,例如 x001
或 id_001
可以。
参考:
- http://www.w3.org/TR/xml/#sec-attribute-types
- http://www.w3.org/TR/xml/#sec-common-syn
这篇关于属性值“ 001”为0。启用命名空间时,类型ID的ID必须为NCName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!