DTDs cannot restrict data to numeric types, let alone limit the number of digits:
Elements: DTDs define the content spec of an element as
[46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
Through Mixed
we can declare #PCDATA (parsed character data) but
make no further datatype specifications. Through children
we can
declare child elements, recursively.
None of the element type possibilities afford the specification a numeric type or length.
Attributes: DTDs define an attribute type as a string, a set of tokenized types, or an enumerated type:
[54] AttType ::= StringType | TokenizedType | EnumeratedType
TokenizedType
can be one of ID
, IDREF
, IDREFS
, ENTITY
, ENTITIES
, NMTOKEN
, or NMTOKENS
; EnumeratedType
can be an notation or an enumeration.
None of the attribute type possibilities afford the specification a numeric type or length.
Overall, there is no support for numeric types for elements or attributes.1 Use XSD instead.
1 If you're in the extraordinary situation of needing to extend DTD to express broader datatypes such as those found in XSD, see Datatypes for DTDs (DT4DTD) 1.0. However, do not expect existing validating parsers to enforce such specifications, which are more for providing the foundation for a smoother future transition path to XML Schema.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…