I want to validate the value of an attribute element value.
I have an element as
<makeOverText id="common02V1"></makeOverText>
For this I have a dtd as below,
<!ATTLIST makeOverText id NMTOKEN #REQUIRED "(?!)common02v1">
Please Note, The value common02v1 is case in-sensitive, It can be of any cases like CommOn02V1, comMON02V1,. etc., This Attribute should be mandatory and it should only hold the case in sensitive value of common02v1.
I Keep getting the error as
![CDATA[The attribute name must be specified in the attribute-list declaration for element "makeOverText".]]
Is there a way to implement this?
To expand a bit, this is how a document/DTD with proper syntax for enumerated attributes looks like, allowing/requiring the exact values common0v1
or othervalue
, and no other value to appear in id
attributes and also no uppercase or mixed-case variants:
<!DOCTYPE makeOverText [
<!ELEMENT makeOverText EMPTY>
<!ATTLIST makeOverText id (common02v1|othervalue) #REQUIRED>
]>
<makeOverText id="common02v1"></makeOverText>
Your use of NMTOKEN
would allow any name token, ie. any token that XML would also allow as element or attribute name, but can't be combined with a list of enumerated values; and what would be the point if the values are enumerated explicitly anyway?
XML is just a subset of SGML, and SGML does allow both case-sensitivity and case-insensitivity (case folding) as per the SYNTAX NAMECASE GENERAL
SGML declaration property. The DTD above would make an SGML parser validate and case-fold (normalize into uppercase) any case variations just as you require since SGML's default is case-folding of element, attributes, and name tokens (and case preservation of entities as per the separate SYNTAX NAMECASE ENTITY
property). It's just that the designers of XML (the "SGML Extended Review Board/ERB" on invitation of W3C around 1996-1998) have chosen to make XML always case-sensitive. Note that the more powerful markup schema languages such as XML Schema and Relax NG suggested in comments, while they could perform validation of mixed case attributes via regular expressions, do not implement case folding, and you'd have to script your value normalisation rules yourself.
Note the SGML declaration facilities for defining character ranges and their uppercase mapping rules, while useful for eg. expressing that a given text must be renderable in a particular font, however, still hit a practical limit with the ever-expanding Unicode repertoire covering hundreds of thousands of characters/glyphs. You may take a look at the official SGML declaration for XML 1.0 up to the 4th edition at 1 to get an idea.
Considering XML was originally just designed for replacing HTML parsing rules on the web and nothing else, one could question the decision to make XML case-sensitive, since HTML, being also derived from SGML, is case-insensitive after all. The major reason for XML doing away with it is that case-insensitivity is strictly a Latin/Western script thing, and the opportunity was seized to drop those messy rules.