当前位置: 首页 > 网络学院 > XML相关教程 > DTD > DTD - 元素

DTD
DTD - 介绍
DTD - XML 基本组件群
DTD - 元素
DTD - 属性
DTD - 实体
DTD - 校验
DTD - 案例
DTD - 摘要
DTD - 元素和属性

DTD - 元素


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 562 ::
收藏到网摘: n/a

In a DTD, XML elements are declared with a DTD element declaration.
在DTD中,XML元素是用DTD元素的声明方式来声明的。


Declaring an Element
声明一个元素

In the DTD, XML elements are declared with an element declaration. An element declaration has the following syntax:
在DTD中,XML元素是用XML元素的声明方式来声明的。元素的声明方式包含以下语法:

<!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>

 


Empty elements
空元素

Empty elements are declared with the category keyword EMPTY:
空元素是用类别关键字EMPTY来声明的:

<!ELEMENT element-name EMPTY>

example:
<!ELEMENT br EMPTY>
XML example:
<br />

 


Elements with only character data
纯字符数据元素

Elements with only character data are declared with #PCDATA inside parentheses:
纯字符数据元素用圆括号中的#PCDATA来声明:

<!ELEMENT element-name (#PCDATA)>

example:
<!ELEMENT from (#PCDATA)>

 


Elements with any contents
以ANY内容声明的元素

Elements declared with the category keyword ANY, can contain any combination of parsable data:
以类别关键字ANY声明的元素将包含所有可解析数据的组合:

<!ELEMENT element-name ANY>
example:
<!ELEMENT note ANY>

 


Elements with children (sequences)
以child关键字声明的元素(按次序排列)

Elements with one or more children are defined with the name of the children elements inside parentheses:
如果元素包含若干个子类别,那么可以使用圆括号中的子元素名称来定义:

<!ELEMENT element-name 
(child-element-name)>
or
<!ELEMENT element-name
(child-element-name,child-element-name,.....)>
example:
<!ELEMENT note (to,from,heading,body)>

When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document. In a full declaration, the children must also be declared, and the children can also have children. The full declaration of the "note" element will be:
当子元素被逗号依次隔开声明时,子元素必须在文件中以相同的顺序出现。在一个完整的声明中,子元素也必须被声明。同时,子元素也可以包含子元素。"note"元素的完整声明如下:

<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

 


Declaring only one occurrence of the same element
给相同的元素声明一个发生事件

<!ELEMENT element-name (child-name)>
example:
<!ELEMENT note (message)>

The example declaration above declares that the child element message must occur once, and only once inside the "note" element.
上述案例声明:子元素信息必须只能在“note”元素中出现一次。


Declaring minimum one occurrence of the same element
声明相同元素的最小发生事件

<!ELEMENT element-name (child-name+)>
example:
<!ELEMENT note (message+)>

The + sign in the example above declares that the child element message must occur one or more times inside the "note" element.
上述案例的加号声明了子元素信息必须在"note"元素中出现一次或几次。


Declaring zero or more occurrences of the same element
不声明相同元素的发生事件或声明多次发生事件

<!ELEMENT element-name (child-name*)>
example:
<!ELEMENT note (message*)>

The * sign in the example above declares that the child element message can occur zero or more times inside the "note" element.
上述案例中的*号声明了子元素信息可以不出现在"note"元素中或出现多次。


Declaring zero or one occurrences of the same element

不声明相同元素的发生事件或只声明一次发生事件

<!ELEMENT element-name (child-name?)>
example:
<!ELEMENT note (message?)>

The ? sign in the example above declares that the child element message can occur zero or one times inside the "note" element.
上述案例中的?号声明了子元素信息可以不出现在"note"元素中或只出现一次。


Declaring either/or content
声明 either/or 内容

example:
<!ELEMENT note (to,from,header,(message|body))>

The example above declares that the "note" element must contain a "to" element, a "from" element, a "header" element, and either a "message" or a "body" element.
上述案例声明了"note"元素必须包含一个”to”元素、一个“form”元素、一个“header”元素以及一个“message”或一个“body”元素。


Declaring mixed content
声明混合内容

example:
<!ELEMENT note (#PCDATA|to|from|header|message)*>

The example above declares that the "note" element can contain zero or more occurrences of parsed character, "to", "from", "header", or "message" elements.
上述案例声明了"note"元素可以不包含解析字符的发生事件或包含多个发生事件(“or”、“form”、“header”或“message”元素)。

评论 (0) All

登陆 | 还没注册?