Can we put regular expression for a value in a DTD?

拥有回忆 提交于 2021-01-27 17:52:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!