问题描述
我正在尝试制作一个 DTD,我想在其中添加一些限制,例如:
- 只允许引入 9 个号码的电话号码
- 只允许引入包含 7 个数字和 1 个字母的 ID
但我不知道我该怎么做.(我知道用 XML Schema 添加这些限制更容易,但我想用 DTD 来做).
DTD 不能将数据限制为数字类型,更不用说限制位数了:
元素:DTD 定义 元素的内容规范为
[46] contentspec ::= 'EMPTY' |'任何' |混合 |孩子们
通过
Mixed
我们可以声明#PCDATA(已解析的字符数据),但是不做进一步的数据类型规范.通过children
我们可以递归地声明子元素.没有任何元素类型的可能性为规范提供数字类型或长度.
属性:DTD 定义了一个属性类型 作为字符串、一组标记化类型或枚举类型:
[54] AttType ::= StringType |标记化类型 |枚举类型
TokenizedType
可以是ID
、IDREF
、IDREFS
、ENTITY
之一、ENTITIES
、NMTOKEN
或NMTOKENS
;EnumeratedType
可以是符号或枚举.没有任何可能的属性类型为规范提供数字类型或长度.
总的来说,元素或属性不支持数字类型.改用 XSD.
I am trying to make a DTD in which I want to add some restrictions like:
- Only allow the introduction of telephone numbers with 9 numbers
- Only allow the introduction of an ID with 7 numbers and 1 letter
But I don't know how I can do that. (I know it is easier to add these restrictions with a XML Schema, but I want to do it with a DTD).
DTDs cannot restrict data to numeric types, let alone limit the number of digits:
Elements: DTDs define the content spec of an element as
Through
Mixed
we can declare #PCDATA (parsed character data) butmake no further datatype specifications. Throughchildren
we candeclare child elements, recursively.None of the element type possibilities afford the specification a numeric type or length.
Attributes: DTDs define an attribute type as a string, a set of tokenized types, or an enumerated type:
TokenizedType
can be one ofID
,IDREF
,IDREFS
,ENTITY
,ENTITIES
,NMTOKEN
, orNMTOKENS
;EnumeratedType
can be an notation or an enumeration.None of the attribute type possibilities afford the specification a numeric type or length.
Overall, there is no support for numeric types for elements or attributes. Use XSD instead.
这篇关于如何将 XSD 数据类型限制添加到 DTD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!