问题
Trying to achieve something like this
ATTLIST employee role (leader|analyst|leader,analyst)
where I can't change it into an element; it needs to be an attribute.
It seems like DTD doesn't like commas in its expressions.
回答1:
An attribute in XML cannot contain elements.
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
See also: XML Element vs XML Attribute
回答2:
You can do :
<!ATTLIST employee role (leader|analyst|leader) "analyst">
来源:https://stackoverflow.com/questions/30114753/in-xml-dtd-how-can-an-attribute-have-two-values