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. 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET

    看完以下这段话之后,就理解DOCUMNET.READY之类的说法了. 或是JAVASCRIPT的浏览器里更细致的操作DOCUMENT的东西了. DOCUMNET和WINDOWS谁大谁小, 立即执行的匿 ...

  2. POJ3034+DP

    题意:给定一个N*N的矩阵, 然后在这个矩阵的每个格子在任意时间会出现一个鼹鼠,这个出现     出现鼹鼠的时间是输出信息所确定的. 现在你手里有一把锤子能够去锤这些鼹鼠. 你能     够移动锤子, ...

  3. SGU111 Very simple problem

    多少个平方数小于等于X,二分. PS:java BigInteger. import java.util.*; import java.math.*; public class Solution { ...

  4. HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)

    Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...

  5. Android性能优化之如何避免Overdraw

    什么是Overdraw? Overdraw就是过度绘制,是指在一帧的时间内(16.67ms)像素被绘制了多次,理论上一个像素每次只绘制一次是最优的,但是由于重叠的布局导致一些像素会被多次绘制,而每次绘 ...

  6. nigix以及相关

    nginx+php的配置 php与nginx整合 http://www.thinkphp.cn/topic/13082.html [入门篇]Nginx + FastCGI 程序(C/C++) 搭建高性 ...

  7. Task的使用

    在.net4.0的时候推出的Task using System; using System.Threading; using System.Threading.Tasks; namespace Tas ...

  8. 解决JDeveloper运行慢的设置/BPM/SOA Server JVM参数设定

    最近在使用 Jdeveloper 10.1.3.3 版本时发现速度奇慢无比,后经Google,发现如下解决方案:在 jdev.conf 文件的末尾加上如下两行,速度即可得到显着的提高, jdev.co ...

  9. js实现对数据库的增删查改

    1.查询 复制代码 代码如下: <HTML> <HEAD> <TITLE>数据查询</TITLE> <Script > var conn = ...

  10. POJ 3140-Contestants Division(树形dp)

    题意: n给节点的树,分成两个联通分支,使它们大小的绝对值最小,求这个最小值. 分析: 分成两个联通分支,即删除一条边,开始看到m(边数)和n(点数)没什么关系,但题目说的是一棵树,则m==n-1,求 ...