In a DTD file, how do I declare that an element must have an attribute.
This attribute must be one of the following three: si, sl or ii
<bla si="foo">
<bla ii="foo">
<bla sl="foo">
are valid, and:
<bla> or
<bla somthing="foo"> or
<bla si="foo" ii="bar">
should all be not valid
thanks in advance
Edit:
this doesn’t do the trick, but it is close:
<!ATTLIST bla si CDATA #REQUIRED
sl CDATA #REQUIRED
ii CDATA #REQUIRED
>
it requires all of the attributes to be there, but I want to force, that only one of the attributes is there.
In DTD Attributes cannot be interdependent. You can use
#REQUIREDor#IMPLIEDto make any of the attributes mandatory or optional, but you can’t otherwise force the number of attributes that must be present.Generally a good design practice is to use attributes only to itemize the features of the element, not to change the meaning of the element, and keep to the attributes independent of each other. If these are your goals, consider making them (alternate) child elements or providing alternate versions of your “host” element so that they can for example have different attribute sets.