元素只能具有两个文本值之一? [英] Element that can only have one of two text values?

查看:84
本文介绍了元素只能具有两个文本值之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个包含 fuel_system 元素的DTD。

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

我想在< fuel_system> 标记之间限制文本。它只能是化油燃油喷射。我怎样才能做到这一点?

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

我没有提到类似=>属性类型(汽化,加油)的情况,因为我想在中强制使用此规则; fuel_system> 标签,而不是 fuel_system 的属性。

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.

推荐答案

在DTD中定义元素时,无法限制元素内的文本。您只能说出它可能包含的其他元素(子元素)及其顺序,或者可以知道该元素包含文本,或者是2的混合。

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.

因此,基本上,您有2个限制< fuel-system> 的选项:要么将其声明为属性(< fuel-system type = 或 ),或声明子元素<燃料注入> < carburated> ; 。这两个选项之间的选择取决于您要描述的内容以及根据燃油系统的类型而变化的内容。

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)

示例第一个选项,属性

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

第二个选项,子元素

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

这篇关于元素只能具有两个文本值之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆