Using DTD can I specify an exact number of element occurrences?

雨燕双飞 提交于 2020-04-30 09:26:51

问题


I am trying to do this exercise in XML and I am stuck at this particular point. I am being asked to create a DTD that will satisfy a list of requirements and I cannot find a way to achieve the following:

The seasonal_prices' list can have none, one, two or three occurrences of the 'season_price' element

Is there a way to achieve this using only a DTD?


回答1:


Is there a way to achieve this using only a DTD?

Nope.

You can only do:

  • season_price (exactly one)
  • season_price? (zero or one)
  • season_price+ (one or more)
  • season_price* (zero or more)

See https://www.w3.org/TR/xml11/#sec-element-content for more info.

----- Edit -----

Like you mentioned in another question, you could do this using ? like:

<!ELEMENT seasonal_prices (season_price?, season_price?, season_price?)>

but there's no direct way like in XML Schema (minOccurs/maxOccurs).



来源:https://stackoverflow.com/questions/61272296/using-only-a-dtd-are-there-any-disadvantages-in-limiting-the-number-of-children

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