DTD-属性

 DTD里属性用ATTLIST声明

语法:

<!ATTLIST element-name attribute-name attribute-type default-value>

例:

<!ATTLIST payment type CDATA "check">

XML例:<payment type="check" />

attribute-type列表如下:

TypeDescription

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 default-value can be one of the following:

ValueExplanation

value

The default value of the attribute

#REQUIRED

The attribute is required

#IMPLIED

The attribute is not required

#FIXED value

The attribute value is fixed


带默认属性值的

DTD:<!ELEMENT square EMPTY>

<!ATTLIST square width CDATA "0">

valid xml:<square width="100" />

属性必须有的:

语法:<!ATTLIST element-name attribute-name attribute-type #REQUIRED>

例:<!ATTLIST person number CDATA #REQUIRED>

有效的xml:<person number="5677" />

属性可有可无的

语法:<!ATTLIST element-name attribute-name attribute-type #IMPLIED>

例:DTD:<!ATTLIST contact fax CDATA #IMPLIED>

有效xml: <contact fax="555-667788" />  or  <contact />

固定属性的:

语法:<!ATTLIST element-name attribute-name attribute-type #FIXED "value">

例:DTD:<!ATTLIST sender company CDATA #FIXED "Microsoft">

有效xml:<sender company="Microsoft" />

带可选值属性的:

语法:<!ATTLIST element-name attribute-name (en1|en2|...)  default-value>

例:<!ATTLIST payment type (check|cash) "cash">

xml例: <payment type="check">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值