Attribute value "001" of type ID must be an NCName when namespaces are enabled
Asked Answered
K

2

6

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.

Kishakishinev answered 12/8, 2014 at 5:47 Comment(0)
B
12

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:

Bukovina answered 12/8, 2014 at 7:20 Comment(0)
A
2

Add NCName to your Attlist element like this :

!ATTLIST complexe code ID NCName #REQUIRED 
Alligator answered 12/6, 2022 at 8:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.