我正在创建一个 XML DTD,我有一组标签,并且只有一个标签必须包含属性。如何在 DTD 中强制执行此操作?想象一个多项选择的问题/答案组。见下文:
<group>
<question>This is a question</question>
<question>This is another question</question>
<question answer="true">This is another question, but this is the correct choice</question>
</group>
最佳答案
一种可能是声明一种新的元素并只允许它出现一次:
<!ELEMENT group (question*,questionWithAnswer,question*)>
<!ELEMENT question (#PCDATA)>
<!ELEMENT questionWithAnswer (#PCDATA)>
<!ATTLIST questionWithAnswer type (true|false) #REQUIRED>
关于xml - 创建 XML 文档类型定义时,如何指示在一组标签中,一个标签必须具有特定属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17929106/