xml - 使用 DTD 我可以指定元素出现的确切数量吗?

标签 xml dtd

我正在尝试用 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/

相关文章:

javascript - 如何在 jQuery 中对附加的 <li> 项进行排序

c# - 使用 XML 作为存储和 Google Drive

dtd - 在 DTD 中声明具有任意名称的元素

xml - 选择具有唯一值的元素

java - 在 android xml 文件的 edittext View 中引用一个整数

python - 使用ElementTree的iterparse方法如何知道元素的父元素?

java - DTD 显示在 Eclipse 中的项目目标路径中,但通过 Maven 命令行使用时不显示

java - struts-config.xml中action节点的 "attribute"属性有什么用?

c# - 使用 DTD 验证 - 强制关闭连接

html - HTML5 中的 svg 内联和 svg 自定义属性