Old topic, DTD

? Zero or one of the element is allowed.

* Zero or more of the element is allowed.

+ One or more of the element is required.


In narrative documents, it's common for a single element to contain both child elements and un-marked up, nonwhitespace character data. For example, recall this definition element from Chapter 2:


 <definition>A <term>Turing Machine</term> refers to an abstract finite 

state automaton with infinite memory that can be proven equivalent

to any any other finite state automaton with arbitrarily large memory.

Thus what is true for one Turing machine is true for all Turing

machines no matter how implemented.

</definition>



The definition element contains some nonwhitespace text and a term child. This is called mixed content. An element that contains mixed content is declared like this:


<!ELEMENT definition (#PCDATA | term)*>


[b]
If an element is empty, then it can contain nothing, not even whitespace.[/b]


There are 10 attribute types in XML. They are:

CDATA
NMTOKEN
NMTOKENS
Enumeration
ENTITY
ENTITIES
[b]ID[/b]
IDREF
IDREFS
NOTATION

An ID type attribute must contain an XML name (not a name token but a name) that is unique within the XML document. More precisely, no other ID type attribute in the document can have the same value. (Attributes of non-ID type are not considered.) Each element may have no more than one ID type attribute.

As the keyword suggests, ID type attributes assign unique identifiers to elements. ID type attributes do not need to have the name "ID" or "id", although they very commonly do. For example, this ATTLIST declaration says that every employee element must have a social_security_number ID attribute:

<!ATTLIST employee social_security_number ID #REQUIRED>


ID numbers are tricky because a number is not an XML name and therefore not a legal XML ID. The normal solution is to prefix the values with an underscore or a common letter. For example:

<employee social_security_number="_078-05-1120"/>


In addition to providing a data type, each ATTLIST declaration includes a default declaration for that attribute. There are four possibilities for this default:


#IMPLIED

The attribute is optional. Each instance of the element may or may not provide a value for the attribute. No default value is provided.

#REQUIRED

The attribute is required. Each instance of the element must provide a value for the attribute. No default value is provided.

#FIXED

The attribute value is constant and immutable. This attribute has the specified value regardless of whether the attribute is explicitly noted on an individual instance of the element. If it is included, though, it must have the specified value.

Literal

The actual default value is given as a quoted string.

This ATTLIST declaration says that every web_page element has a protocol attribute. If a particular web_page element doesn't have an explicit protocol attribute, then the parser will supply one with the value http:

<!ATTLIST web_page protocol NMTOKEN "http">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值