DTD - Attributes
In a DTD, attributes are declared with an ATTLIST declaration.
Declaring Attributes
An attribute declaration has the following syntax:
<!ATTLIST element-name attribute-name attribute-type attribute-value> DTD example: <!ATTLIST payment type CDATA "check"> XML example: <payment type="check" />
The attribute-type can be one of the following:
| Type | Description |
|---|---|
| CDATA | The value is character data |
| (en1|en2|..) | The value must be one from an enumerated list |
| ID | The value is a unique id |
| IDREF | The value is the id of another element |
| IDREFS | The value is a list of other ids |
| NMTOKEN | The value is a valid XML name |
| NMTOKENS | The value is a list of valid XML names |
| ENTITY | The value is an entity |
| ENTITIES | The value is a list of entities |
| NOTATION | The value is a name of a notation |
| xml: | The value is a predefined xml value |
The attribute-value can be one of the following:
| Value | Explanation |
|---|---|
| value | The default value of the attribute |
| #REQUIRED | The attribute is required |
| #IMPLIED | The attribute is optional |
| #FIXED value | The attribute value is fixed |
A Default Attribute Value
DTD:
<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0"> Valid XML:
<square width="100" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE square [
<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0">
]>
<square width="100"/>
In the example above, the "square" element is defined to be an empty element with a "width" attribute of type CDATA. If no width is specified, it has a default value of 0.
#REQUIRED
Syntax
<!ATTLIST element-name attribute-name attribute-type #REQUIRED>
Example
DTD:
<!ATTLIST person number CDATA #REQUIRED> Valid XML:
<person number="5677" /> Invalid XML:
<person />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE person [
<!ELEMENT person EMPTY>
<!ATTLIST person number CDATA #REQUIRED>
]>
<person number="5677"/>
Use the #REQUIRED keyword if you don't have an option for a default value, but still want to force the attribute to be present.
#IMPLIED
Syntax
<!ATTLIST element-name attribute-name attribute-type #IMPLIED>
Example
DTD:
<!ATTLIST contact fax CDATA #IMPLIED> Valid XML:
<contact fax="555-667788" /> Valid XML:
<contact />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE contact [
<!ELEMENT contact EMPTY>
<!ATTLIST contact fax CDATA #IMPLIED>
]>
<contact fax="555-667788"/>
Use the #IMPLIED keyword if you don't want to force the author to include an attribute, and you don't have an option for a default value.
#FIXED
Syntax
<!ATTLIST element-name attribute-name attribute-type #FIXED "value">
Example
DTD:
<!ATTLIST sender company CDATA #FIXED "Microsoft"> Valid XML:
<sender company="Microsoft" /> Invalid XML:
<sender company="W3Schools" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sender [
<!ELEMENT sender EMPTY>
<!ATTLIST sender company CDATA #FIXED "Microsoft">
]>
<sender company="Microsoft"/>
Use the #FIXED keyword when you want an attribute to have a fixed value without allowing the author to change it. If an author includes another value, the XML parser will return an error.
Enumerated Attribute Values
Syntax
<!ATTLIST element-name attribute-name (en1|en2|..) default-value>
Example
DTD:
<!ATTLIST payment type (check|cash) "cash"> XML example:
<payment type="check" />
or
<payment type="cash" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE payment [
<!ELEMENT payment EMPTY>
<!ATTLIST payment type (check|cash) "cash">
]>
<payment/>
Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values.
DTD - Attributes的更多相关文章
- DTD总结
DTD 可以检测 XNM 文档的结构是否正确,就好像文章中用来保证结构正确的语法规则一样. 引入 DTD 1.引入私有的 DTD 文件,URI 可以使相对地址或绝对地址 <!DOCTYPE 根元 ...
- How to read the HTML DTD
Contents How to read the HTML DTD 1. DTD Comments 2. Parameter Entity definitions 3. Element declara ...
- XML约束——DTD约束
参考: 方立勋老师的讲课视频. 什么是XML约束 •在XML技术里,可以编写一个文档来约束一个XML文档的书写规范,这称之为XML约束. 为什么需要XML约束 常用的约束技术 •XML DTD • ...
- Expecting "jsp:param" standard action with "name" and "value" attributes错误
错误信息如下: Servlet.service() for servlet [jsp] in context with path [/20161017] threw exception [/tag/s ...
- 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 ...
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
关于网页中第一行<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- 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来 ...
随机推荐
- HDU1465+递推
经典的信封装信问题 f[ n ] = ( n-1 ) * ( f[ n-1 ]+f[ n-2 ] ) #include<stdio.h> #include<string.h> ...
- cocos2d-x 多分辨率适配详解(转载),以前北京团队设计的游戏,也是用这套方案
http://blog.csdn.net/kyo7552/article/details/17163487 多种分辨率的适配一直都是一个蛋疼的问题,各家公司可能都有自己的一套方案.今天我为大家介绍的是 ...
- C++对象的自销毁
记得在学校里的时候,曾经这样写过: void MyClass::KillMe() { delete this; } 老师看到这句话的时候,眼珠子都快瞪出来了.但是运行正确啊,没什么问题. 现在想起来, ...
- Android:布局合集
本文归纳Android布局中所用到的知识点,网络上的教程说得太细化,而对于前端来说,下面的归纳最适合不过了. Android五大布局: LinearLayout 线性布局 Relativelayout ...
- PHP设计模式浅析
工厂模式 提到的最多, 用途也最广. 简单说就是: 定义一个用户创建对象的接口. 把创建对象的过程封装起来. 工厂类是指包含一个专门用来创建其他对象的方法的类,工厂类在多态性编程实践中是至关重要的,它 ...
- Ubuntu 12.04上编译Vim7.4的时候遇到“no terminal library found”问题
错误如下: no terminal library foundchecking for tgetent()... configure: error: NOT FOUND! You need ...
- 正确认识Android的内存管理机制,合理关闭进程 (一)
随着大家收货后会有很多乐粉晒内存,为啦方便大家,在网上搜集了一些相关Andriod管理的相关机制合理管理内存,整理下发个贴. 首先要知道Android系统是基于Linux 2.6内核开发的开源操作系统 ...
- 关于广义后缀树(多串SAM)的总结
之前我们给的SAM的例题,基本上是一个串建SAM的就能做的 如果要建多个串的SAM应该怎么做呢 首先看题,bzoj2780 我一开始的想法是SA以前的弄法,把串拼起来,中间加分隔符做SAM 这题确实可 ...
- IDE模式下安装Windows 7强行改回ACHI后不断重启的解决方法
问题描述:用U盘启动进PE装的Win7,由于PE认不出硬盘,只好进BIOS设置硬盘模式为IDE才安装上.结果安装完系统后,在BIOS中强行修改硬盘模式为ACHI模式后,Win7开机不断重启,进不了系统 ...
- 在“BindingNavigator”删除数据前弹出确认框的实现
1)先设置DeleteItem为空,不让它调用自动生成的删除代码. 2)然后自己写代码实现,如下: private void bindingNavigatorDeleteItem_Click(obje ...