在XML / DTD中指定多字枚举值 [英] Specify a multi-word enumeration value in an XML/DTD

查看:158
本文介绍了在XML / DTD中指定多字枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为DTD属性定义指定枚举值列表时,是否可以使用多字值?

When specifying a list of enumeration values for a DTD attribute definition, is it possible to use multi-word values?

      <!ATTLIST SystemName Case ("MIXED RESPECT"|"MIXED IGNORE"|"LOWER RESPECT"|"LOWER IGNORE"|"UPPER RESPECT"|"UPPER IGNORE") "MIXED IGNORE">

我尝试将值放在引号(如图所示)中,而不是引号中。我一直在阅读有关符号和nmtokens的信息,但是我看上去每个地方似乎都在说请参见blah-blah规范,但仅举一个例子。这样的示例价值大约一百万页规格。

I tried putting the values in quotes (as shown), and not in quotes. I keep reading about notations and nmtokens but every single place I look seems to say "see the blah-blah spec" but nary an example. Examples being worth about a million pages of specs.

推荐答案

不,枚举值不能包含空格;每个枚举值必须是合法的NMTOKEN,这意味着它必须是可以在XML名称中出现的字符序列。因此,MIXED,Mixed,RESPECT,MIXED-RESPECT和MIXED_RESPECT是枚举中的合法值,但不是 MIXED RESPECT。抱歉。

No, enumerated values cannot contain space; each enumerated value must be a legal NMTOKEN, which means it must be a sequence of characters which can occur in an XML Name. So MIXED, Mixed, RESPECT, MIXED-RESPECT, and MIXED_RESPECT are legal values in an enumeration, but not "MIXED RESPECT". Sorry.

其价值的原因是历史性的:在SGML(派生XML的语言)中,该语言的可选功能允许省略属性名称如果声明了它们的可能值的列举列表。因此,而不是

The reason, for what it's worth, is historical: in SGML (from which XML was derived), an optional feature of the language allowed attribute names to be omitted if they were declared with an enumerated list of possible values. So instead of

<SystemName Case="MIXED_RESPECT">...

作者可以写

<SystemName MIXED_RESPECT>...

而不是< table border = noborder > < table border = border> 作者只需编写< table border> < table noborder> 。为了确保这些值在上下文中可解析,它们被限制为合法的NMTOKEN。

And instead of <table border="noborder"> or <table border="border"> authors could just write <table border> or <table noborder>. In order to ensure that the values were parsable in context, they were constrained to be legal NMTOKENs.

此功能的缺点是,为了确保始终可以实现此魔术,SGML禁止将任何两个属性的枚举值重叠,因此您不能t具有两个属性,其中 yes no 作为合法值(因为解析器看到 < table yes> 可能不知道这意味着 border = yes 还是 compact = yes )。

One downside of the feature was that in order to ensure that this magic trick was always possible, SGML forbade the enumerated values of any two attributes to overlap, so you couldn't have two attributes with yes and no as the legal values (because then a parser seeing <table yes> might not know whether it means border="yes" or compact="yes").

最小化功能已在XML中删除(就像其他所有最小化功能一样,它使编写SGML解析器成为一种冒险),但是保留了使之成为可能的约束,以确保所有XML DTD都与SGML DTD一样合法。

The minimization feature was dropped in XML (like all the other minimization features that made it such an adventure to write an SGML parser), but the constraint which made it possible was retained, in order to ensure that all XML DTDs would be legal as SGML DTDs.

这篇关于在XML / DTD中指定多字枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆