在XML DTD中,属性如何具有两个值? [英] In XML DTD, how can an attribute have two values?
问题描述
试图实现这样的目标
ATTLIST employee role (leader|analyst|leader,analyst)
我无法将其更改为元素;
where I can't change it into an element; it needs to be an attribute.
似乎DTD在表达式中不喜欢逗号。
It seems like DTD doesn't like commas in its expressions.
推荐答案
XML中的属性不能包含元素。
An attribute in XML cannot contain elements.
您确实反对在任何对象中向属性添加结构办法。如果必须这样做,请保持简单:您可以使用空格或逗号分隔的值表示列表。进行任何进一步的讨论都需要一个与XML解析器不同的单独的微型解析器,仅用于解析属性值。这不是一个好主意,不要期望DTD会提供 NMTOKENS
, IDREFS
提供的支持,或 ENTITIES
You're really going against the grain to try to add structure to attributes in any way. If you must do it, keep it simple: You can represent a list via space or comma-separated values. Going any further runs into requiring a separate micro-parser distinct from an XML parser just to parse the attribute values. It's not a good idea, and don't expect support from DTD beyond that which is provided by NMTOKENS
, IDREFS
, or ENTITIES
另请参阅: XML元素与XML属性
这篇关于在XML DTD中,属性如何具有两个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!