Suppose I have an XML file colors.xml
<colors>
<color id="white" value="#FFFFFF" />
<color id="black" value="#000000" />
<!-- 100+ colors omitted -->
</colors>
In another file I'm defining a DTD, with something like this
<!ELEMENT prettyPicture EMPTY>
<!ATTLIST prettyPicture
fg NMTOKEN <!-- fore ground color -->
bg NMTOKEN <!-- back ground color -->
>
Since fg
and bg
are specified as NMTOKEN, they can be pretty much anything. Is there an easy way to insist that they must be colors as listed in colors.xml?
Simple answer: no, unless you get into programmatic construction of the DTD. In fact, even with XSD, which is much more powerful, you would need to do some code generation to make this work - though with XSD it's much more feasible as it's all XML.