How to add XSD datatype restrictions to a DTD?

馋奶兔 提交于 2019-11-28 11:27:50

问题


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


回答1:


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.

1If 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.



来源:https://stackoverflow.com/questions/35957102/how-to-add-xsd-datatype-restrictions-to-a-dtd

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