In XML DTD, how can an attribute have two values?

雨燕双飞 提交于 2019-12-11 05:54:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!