我正在尝试用 XML 来做这个练习,但我陷入了这个特定的点。我被要求创建一个 DTD 来满足一系列要求,但我找不到实现以下目标的方法:
The seasonal_prices' list can have none, one, two or three occurrences of the 'season_price' element
有没有办法仅使用 DTD 来实现此目的?
最佳答案
Is there a way to achieve this using only a DTD?
不。
你只能做:
season_price
(恰好是一个)season_price?
(零或一)season_price+
(一个或多个)season_price*
(零或多个)
参见https://www.w3.org/TR/xml11/#sec-element-content了解更多信息。
----- 编辑 -----
就像您在 another question 中提到的那样,您可以使用?
来做到这一点,例如:
<!ELEMENT seasonal_prices (season_price?, season_price?, season_price?)>
但是没有像 XML Schema (minOccurs/maxOccurs) 那样的直接方法。
关于xml - 使用 DTD 我可以指定元素出现的确切数量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61257088/