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. a标签的link、visited、hover、active的顺序

    a标签的link.visited.hover.active是有一定顺序的,以下是我一直在用的一个顺序,能正确显示四个颜色,我也不知道有没有其他的顺序能正确显示,如果你没办法判断哪个是对的,那就先用这个 ...

  2. nginx面试题

    1.Nginx是如何实现高并发的 service nginx start之后,然后输入#ps -ef|grep nginx,会发现Nginx有一个master进程和若干个worker进程,这些work ...

  3. spring事物的传播行为

    1.spring事物的传播行为,主要是用来解决业务层拥有事物的方法,相互调用的问题. 2.声明事物, 在代码执行前,开启事务.代码执行完,提交事务 3.spring并没有提供事务具体的处理,而只是调用 ...

  4. iphone6S“玫瑰金”的秘密——阳极氧化

    阳极氧化对多数人来说是一个熟悉又陌生的名词,大多数可能知道它的作用之一就是是能使金属呈现各种各样色彩.最为人熟知的运用阳极氧化技术的产品就是iphone系列产品了,已经推出了金色,玫瑰金色,深空灰色, ...

  5. Android应用启动画面

    原文地址: [Android]应用启动画面 - 空客的日志 - 网易博客 http://blog.163.com/da7_1@126/blog/static/104072678201291921028 ...

  6. MySQL 5.6 安装配置

    mysql 5.6.17下载安装图解_百度经验 http://jingyan.baidu.com/article/4b07be3c67853c48b380f311.html windows 8 系统将 ...

  7. Python之数据结构篇

    简介: 数据结构是可以处理一些数据的结构,或者说,他们是用来存储一组相关数据的.在python中有三种内建的数据结构,分别是列表.元组合字典.我们将会学习如何使用它们是编程变得简单. 列表 list是 ...

  8. puppet&mcollective客户端安装

    一.环境: 1.客户端:            fedora 19 2.DnsServer:     192.168.0.160 3.server1.xxx.com(10.8.1.201):运行以下服 ...

  9. maven打包源代码sources.jar和javadoc.jar帮助文档

    maven中如何打包源代码 *-sources.jar 方式一 :   命令行方式 进入cmd命令行,进入项目工程pom.xml所在路径目录,运行mvn source:jar 和 mvn javado ...

  10. 记录遇到的IE8兼容性问题汇总

    1,伪元素:first-child不起作用,需要单独指定样式名称 2,透明度表示方法,尤其在函数中表示 @mixin opacity($value) { -webkit-opacity: $value ...