当前位置: 首页 > 网络学院 > XML相关教程 > DTD > DTD - 元素
In a DTD, XML elements are declared with a DTD element declaration.
在DTD中,XML元素是用DTD元素的声明方式来声明的。
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> |
Empty elements are declared with the category keyword EMPTY:
空元素是用类别关键字EMPTY来声明的:
<!ELEMENT element-name EMPTY> <!ELEMENT br EMPTY> XML example: <br /> |
Elements with only character data are declared with #PCDATA inside parentheses:
纯字符数据元素用圆括号中的#PCDATA来声明:
<!ELEMENT element-name (#PCDATA)> <!ELEMENT from (#PCDATA)> |
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 one or more children are defined with the name of the children elements inside parentheses:
如果元素包含若干个子类别,那么可以使用圆括号中的子元素名称来定义:
<!ELEMENT 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 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”元素中出现一次。
<!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"元素中出现一次或几次。
<!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"元素中或出现多次。
<!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"元素中或只出现一次。
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”元素。
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”元素)。