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

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

问题描述

我正在尝试制作一个 DTD,我想在其中添加一些限制,例如:

  • 只允许引入 9 个号码的电话号码
  • 只允许引入包含 7 个数字和 1 个字母的 ID

但我不知道我该怎么做.(我知道用 XML Schema 添加这些限制更容易,但我想用 DTD 来做).

解决方案

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

  • 元素:DTD 定义 元素的内容规范

    <块引用>

    [46] contentspec ::= 'EMPTY' |'任何' |混合 |孩子们

    通过 Mixed 我们可以声明#PCDATA(已解析的字符数据),但是不做进一步的数据类型规范.通过 children 我们可以递归地声明子元素.

    没有任何元素类型的可能性为规范提供数字类型或长度.

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

    <块引用>

    [54] AttType ::= StringType |标记化类型 |枚举类型

    TokenizedType 可以是 IDIDREFIDREFSENTITY 之一、ENTITIESNMTOKENNMTOKENSEnumeratedType 可以是符号或枚举.

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

总的来说,元素或属性不支持数字类型.1改用 XSD.

1 如果您处于需要扩展 DTD 以表达更广泛的数据类型(例如 XSD 中的数据类型)的特殊情况,请参阅 DTD 的数据类型 (DT4DTD) 1.0.但是,不要期望现有的验证解析器强制执行此类规范,这些规范更多是为了为更顺畅的未来过渡路径提供基础到 XML Schema.

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

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

    Through Mixed we can declare #PCDATA (parsed character data) but make no further datatype specifications. Through children we can declare 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:

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

    TokenizedType can be one of ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, or NMTOKENS; 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.1 Use XSD instead.

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天全站免登陆