DTD - 元素

来源:互联网 发布:js获取表格一行数据 编辑:程序博客网 时间:2024/04/28 23:24

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


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 
声明0或更多相同元素的出现事件

<!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"元素中出现0或更多次数。


Declaring zero or one occurrences of the same element 
声明0或1次相同元素的发生事件

<!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"元素中出现0或1次。


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"元素可以包含0或更多分列字符(“or”、“form”、“header”或“message”元素)。

 
原创粉丝点击