Search code examples
xmldtd

How can i limit the number of characters i can put in an element through DTD?


for example i have this code

<order id_order="l9992223"></order>

and through DTD i want to limit the maximun number of character to 8 and also that it can only start with a letter but i dont know how the dtd code should be like this without the restriction i want to put

<!ELEMENT order>
<!ATTLIST order
id_order CDATA #REQUIRED>

i dont know where to start with this and i´ve been pulling my hair all afternoon because i´ve got no idea how to use DTD so thanks in advance if you know how to solve it


Solution

  • The limits you can specify in DTD with an <!ATTLIST> entry is very restricted and simple. You can use CDATA for "any possible string", special tokenized types or an explicit list of possible values with enumerations. Unless you want to define all the possible values with

    <!ATTLIST order
    id_order (1|2|3|4|5|6|.....) #REQUIRED>
    

    it is not possible to limit the attribute value to 8 characters.