DTD - Elements
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><</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的更多相关文章
- How to read the HTML DTD
Contents How to read the HTML DTD 1. DTD Comments 2. Parameter Entity definitions 3. Element declara ...
- DTD - XML Building Blocks
The main building blocks of both XML and HTML documents are elements. The Building Blocks of XML Doc ...
- Introduction to DTD
A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines th ...
- DTD Tutorial
The purpose of a DTD (Document Type Definition) is to define the legal building blocks of an XML doc ...
- 无废话XML--XML约束(DTD)
基本术语 一.序言Prolog:包括XML声明(XML Declaration)和文档类型声明(Document Type Declaration). 二.良构(well-formed ...
- 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来 ...
- XML与DTD
什么是XML XML个称为Extensible Markup Language,意思是可扩展的标记语言. 应用常见 配置文件 <?xml version="1.0" enco ...
- DTD -- XML验证
DTD(文档类型定义)的作用是定义 XML 文档的合法构建模块. DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. DTD简介 内部的 DOCTYPE 声明 假如 DTD 被包含在您的 ...
- js81:Image对象,几张图像缓存完之后动画显示,form.elements[],document.images[]
原文发布时间为:2008-11-09 -- 来源于本人的百度文章 [由搬家工具导入] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...
随机推荐
- Win7 默认hosts文件
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP f ...
- 每个QWidget都有contentsMargins函数,善用QMargins
m_pSearchLineEdit = new QLineEdit(); QPushButton *pSearchButton = new QPushButton(this); pSearchButt ...
- SQL Server 2012 连接到数据库引擎
第 1 课:连接到数据库引擎 https://msdn.microsoft.com/zh-cn/library/ms345332(v=sql.110).aspx 本课将介绍主要的工具以及如何连接并 ...
- node.js EventEmitter发送和接收事件
EventEmitter是nodejs核心的一部分.很多nodejs对象继承自EventEmitter,用来处理事件,及回调.api文档地址: http://nodejs.org/api/events ...
- poj 1442 Black Box(堆 优先队列)
题目:http://poj.org/problem?id=1442 题意:n,m,分别是a数组,u数组的个数,u[i]w为几,就加到a几,然后输出第i 小的 刚开始用了一个小顶堆,超时,后来看了看别人 ...
- 生产环境上shell的解读
一直以来对shell都不是很熟悉,只停留在基本的linux上操作上,这周因为定位问题接触到了生产环境上的脚本,因此作为引子学习一下.很多命令只是点到,等真正需要独立完成的时候再去学习. #!/bin/ ...
- FormsAuthentication 登录兼容 IE11 保存cookie
现象:使用FormsAuthentication进行登录验证,在IE11客户端无法保存cookie 解决方法:在web.config中的forms中增加cookieless="UseCook ...
- BZOJ1954: Pku3764 The xor-longest Path
题解: 在树上i到j的异或和可以直接转化为i到根的异或和^j到根的异或和. 所以我们把每个点到根的异或和处理出来放到trie里面,再把每个点放进去跑一遍即可. 代码: #include<cstd ...
- 为自己打造Linux小系统
一.前言 Linux操作系统至1991.10.5号诞生以来,就源其开源性和自由性得到了很多技术大牛的青睐,每个Linux爱好者都为其贡献了自己的一份力,不管是在Linux内核还是开源软件等方面,都为 ...
- PopupWindow-弹窗的界面
1 效果图 2 知识点 PopupWindow(View contentView, int width, int height) //创建一个没有获取焦点.长为width.宽为height,内容为 ...