如何将XSD数据类型限制添加到DTD? [英] How to add XSD datatype restrictions to a DTD?

查看:73
本文介绍了如何将XSD数据类型限制添加到DTD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个DTD,其中要添加一些限制,例如:

I am trying to make a DTD in which I want to add some restrictions like:


  • 仅允许使用以下方式引入电话号码: 9个数字

  • 仅允许引入具有7个数字和1个字母的ID

我不知道该怎么做。 (我知道使用XML模式添加这些限制会更容易,但是我想使用DTD来做到这一点。)

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).

推荐答案

DTD不能将数据限制为数字类型 ,更不用说限制位数了:

DTDs cannot restrict data to numeric types, let alone limit the number of digits:


[46]     contentspec ::=     'EMPTY' | 'ANY' | Mixed | children


通过混合我们可以声明#PCDATA(已解析的字符数据),但是
没有进一步的数据类型说明。通过 children ,我们可以
递归声明子元素。

Through Mixed we can declare #PCDATA (parsed character data) but make no further datatype specifications. Through children we can declare child elements, recursively.

没有元素类型可能会为规范提供数字类型或长度。

属性:DTD定义了 属性类型 ,作为字符串,一组标记化类型或枚举类型:

Attributes: DTDs define an attribute type as a string, a set of tokenized types, or an enumerated type:


[54]       AttType     ::=     StringType | TokenizedType | EnumeratedType


TokenizedType 可以是 ID IDREF IDREFS 之一, ENTITY ENTITIES NMTOKEN NMTOKENS EnumeratedType 可以是符号或枚举。

TokenizedType can be one of ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, or NMTOKENS; EnumeratedType can be an notation or an enumeration.

没有任何一种属性类型可能为规范提供数字类型或长度。

总体而言,不支持元素或属性的数字类型。 1

1 如果您处于特殊情况下需要扩展DTD以表示更广泛的数据类型,请改用XSD。例如在XSD中找到的数据,请参见 DTD的数据类型(DT4DTD)1.0 。但是,不要期望现有的验证解析器执行这样的规范,而这些规范更多地是为为将来向XML Schema过渡提供更平滑的路径奠定基础。

1 If you're in the extraordinary situation of needing to extend DTD to express broader datatypes such as those found in XSD, see Datatypes for DTDs (DT4DTD) 1.0. However, do not expect existing validating parsers to enforce such specifications, which are more for providing the foundation for a smoother future transition path to XML Schema.

这篇关于如何将XSD数据类型限制添加到DTD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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