Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm constructing a DTD which has a fuel_system element.

I want to restrict the text between <fuel_system> tag. It must be only carbureted or fuel-injected. How can I do this?

I don't mention something like this = > attribute type (carbureted, fuel-injected), because I want to force this rule in <fuel_system> tags, not the attribute of fuel_system.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
775 views
Welcome To Ask or Share your Answers For Others

1 Answer

when defining an element in a DTD, there is no way to restrict the text inside the element. you can only tell what other element (child elements) it might contain and their order, or you can tell that the element contains text, or a mixture of the 2.

so, basically you have 2 options for restricting the <fuel-system>: either declare it as an attribute (<fuel-system type="fuel-injected"/>), or declare children elements <fuel-injected> and <carburated>. the choice between those 2 options depends on what you are trying to describe and what will change depending on the type of fuel-system.

(the grammar for the declaration of an element is defined here)

examples: first option, attributes

<!ELEMENT fuel-system EMPTY>
<!ATTLIST fuel-system (fuel-injected|carburated) #REQUIRED>

second option, child elements

<!ELEMENT fuel-system (fuel-injected|carburated)>
<!ELEMENT fuel-injected ...>
<!ELEMENT carburated ...>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...