Home > Blockchain >  Reference another XML file from DTD
Reference another XML file from DTD

Time:07-26

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?

CodePudding user response:

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.

  • Related