元素的属性必须存在并且是 dtd 文件中定义的列表之一
在 DTD 文件中,如何声明元素必须具有属性。 该属性必须是以下三个之一:si、sl 或 ii
<bla si="foo">
<bla ii="foo">
<bla sl="foo">
有效,并且:
<bla> or
<bla somthing="foo"> or
<bla si="foo" ii="bar">
都应该无效,
提前致谢
编辑:
这并不能解决问题,但很接近:
<!ATTLIST bla si CDATA #REQUIRED
sl CDATA #REQUIRED
ii CDATA #REQUIRED
>
它需要所有属性在那里,但我想强制,只有一个属性在那里。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 DTD 中,属性不能相互依赖。您可以使用
#REQUIRED
或#IMPLIED
将任何属性设置为强制或可选,但您不能以其他方式强制必须存在的属性数量。一般来说,良好的设计实践是仅使用属性来列出元素的特征,而不改变元素的含义,并保持属性彼此独立。如果这些是您的目标,请考虑使它们成为(备用)子元素或提供“主机”元素的备用版本,以便它们可以具有不同的属性集。
In DTD Attributes cannot be interdependent. You can use
#REQUIRED
or#IMPLIED
to 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.