问题
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