问题
I would like to know if there is a way to associate regular expression for the value of an attribute. like in XML Schema:
<xs:pattern value="([0-9]|[A-Z]){3}" />
to make the DTD match with this XML line:
<airport iata="LAE" name="Nadzab Airport" city="Nadzab" country="Papua New Guinea">
回答1:
No, DTDs do not support regex. Use XSD for vastly superior datatyping.
DTD attribute values can be enumerations, however:
<!ELEMENT airport EMPTY>
<!ATTLIST airport iata (LAE|LAX|LGA) #IMPLIED>
来源:https://stackoverflow.com/questions/49175355/can-we-put-regular-expression-for-a-value-in-a-dtd