In a DTD, elements are declared with an ELEMENT declaration.

Declaring Elements

In a DTD, XML elements are declared with an element declaration with the following syntax:

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

Empty Elements

Empty elements are declared with the category keyword EMPTY:

<!ELEMENT element-name EMPTY>

Example:

<!ELEMENT br EMPTY>

XML example:

<br />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE br [
<!ELEMENT br EMPTY>
]>
<br/>

Elements with Parsed Character Data

Elements with only parsed character data are declared with #PCDATA inside

<!ELEMENT element-name (#PCDATA)>

Example:

<!ELEMENT from (#PCDATA)>

Elements with any Contents

Elements declared with the category keyword ANY, can contain any combination of parsable data:

<!ELEMENT element-name ANY>

Example:

<!ELEMENT note ANY>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE content [
<!ELEMENT content (any+)>
<!ELEMENT any ANY>
]>
<content>
<any></any>
<any>
<any></any>
</any>
<any>&lt;</any>
</content>

Elements with Children (sequences)

Elements with one or more children are declared with the name of the children elements inside parentheses:

<!ELEMENT element-name (child1)>
or
<!ELEMENT element-name (child1,child2,...)> 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 is:

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

Declaring Only One Occurrence of an Element

<!ELEMENT element-name (child-name)>

Example:

<!ELEMENT note (message)>

The example above declares that the child element "message" must occur once, and only once inside the "note" element.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note (message)>
<!ELEMENT message (#PCDATA)>
]>
<note>
<message></message>
</note>

Declaring Minimum One Occurrence of an 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.

Declaring Zero or More Occurrences of an 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.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note (message*)>
<!ELEMENT message (#PCDATA)>
]>
<note> </note>

Declaring Zero or One Occurrences of an Element

<!ELEMENT element-name (child-name?)>

Example:

<!ELEMENT note (message?)>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note (message?)>
<!ELEMENT message (#PCDATA)>
]>
<note>
<message></message>
</note>

The ? sign in the example above declares that the child element "message" can occur zero or one time inside the "note" element.

Declaring either/or Content

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.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,header,(message|body))>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT header (#PCDATA)>
<!ELEMENT message (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to></to>
<from></from>
<header></header>
<body></body>
</note>

Declaring Mixed Content

Example:

<!ELEMENT note (#PCDATA|to|from|header|message)*>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note (#PCDATA|to|from|header|message)*>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT header (#PCDATA)>
<!ELEMENT message (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to></to>
</note>

The example above declares that the "note" element can contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements.

DTD - Elements的更多相关文章

  1. How to read the HTML DTD

    Contents How to read the HTML DTD 1. DTD Comments 2. Parameter Entity definitions 3. Element declara ...

  2. DTD - XML Building Blocks

    The main building blocks of both XML and HTML documents are elements. The Building Blocks of XML Doc ...

  3. Introduction to DTD

    A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines th ...

  4. DTD Tutorial

    The purpose of a DTD (Document Type Definition) is to define the legal building blocks of an XML doc ...

  5. 无废话XML--XML约束(DTD)

    基本术语     一.序言Prolog:包括XML声明(XML Declaration)和文档类型声明(Document Type Declaration).     二.良构(well-formed ...

  6. XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax

    本文主要涉及:xml概念描述,xml的约束文件,dtd,xsd文件的定义使用,如何在xml中引用xsd文件,如何使用java解析xml,解析xml方式dom sax,dom4j解析xml文件 XML来 ...

  7. XML与DTD

    什么是XML XML个称为Extensible Markup Language,意思是可扩展的标记语言. 应用常见 配置文件 <?xml version="1.0" enco ...

  8. DTD -- XML验证

    DTD(文档类型定义)的作用是定义 XML 文档的合法构建模块. DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. DTD简介 内部的 DOCTYPE 声明 假如 DTD 被包含在您的 ...

  9. js81:Image对象,几张图像缓存完之后动画显示,form.elements[],document.images[]

    原文发布时间为:2008-11-09 -- 来源于本人的百度文章 [由搬家工具导入] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...

随机推荐

  1. ajax的GET和POST请求

    GET和POST请求 GET请求时最常见的请求类型,用于向服务器查询信息,必要时可以将查询字符串参数放在URL尾部发送给服务器,如果参数有特殊字符必须正确编码.我们上面使用的例子都是使用GET请求,非 ...

  2. P90、面试题11:数值的整数次方

    题目:实现函数double Power(double base, int exponent),求base的exponent次方.不得使用库函数,同时不需要考虑大数问题. 需要注意的地方: 1)输入的指 ...

  3. 编程之美:1.9高效率安排见面会 图的m着色问题 回溯法

    原书问题,可以转换为图的m着色问题 ,下面该问题的代码 这里有参考ppt与code,免积分载 http://download.csdn.net/detail/u011467621/6341195 // ...

  4. VS2012 Build相关

    最近写了一个小程序,用到了一些关于build方面的内容,google后,记录一下 1. VS工程下的bin和obj文件夹,bin文件夹下的debug和release文件夹,以及其中的文件 大家可以参考 ...

  5. bugumongo--ConnectToMongoDB

    连接MongoDB 在能够对MongDB进行操作之前,需要使用BuguConnection连接到MongoDB数据库.代码如下: BuguConnection conn = BuguConnectio ...

  6. NPOI的源代码编译

    打开版本库下的examples文件夹 然后打开对应的解决方案文件,尝试编译程序.发现提示缺少了dll 琢磨了半天,找到四个项目文件,打开之后进行编译.最后会生成dll到solution文件夹下的Lib ...

  7. unity3d游戏开发 —— 倒计时

    using UnityEngine;using System.Collections; public class CoolTime : MonoBehaviour { // Use this for ...

  8. chinacloud大数据新闻

    2015年大数据发展八大趋势   (0 篇回复) “数据很丰满,信息很骨感”:Sight Machine想用大数据的方法,打碎两者间的屏障   (0 篇回复) 百度携大数据"圈地" ...

  9. 学习Java Web开发

    学习DreamWaveMX中文版的网页设计技术 HTML网页设计,这是最基本的.学习XML的一些基本知识.初步掌握一些JSCRIPT的应用. 学习JAVA语言. 这应该分成2次来进行: 第1次找一本国 ...

  10. Gentoo源码安装图解

    Gentoo源码安装 一.前期准备 (1)下载以下三个文件 二.配置安装环境 (1)用光盘引导到LiveCD环境 (2)配置当前LiveCD环境的网络 安装Gentoo时,服务器引导的LiveCD环境 ...