Attribute value “001” of type ID must be an NCName when namespaces are enabled

只愿长相守 提交于 2019-12-12 16:39:12

问题


So i'm creating a xml file with my own DTD.

The simplified XML is as follows:

<!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>

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.

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.

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.


回答1:


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.

Attribute values such as x001 or id_001 are OK.

References:

  • http://www.w3.org/TR/xml/#sec-attribute-types
  • http://www.w3.org/TR/xml/#sec-common-syn


来源:https://stackoverflow.com/questions/25256989/attribute-value-001-of-type-id-must-be-an-ncname-when-namespaces-are-enabled

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