Herong's Tutorial Notes On XML Technologies
Dr. Herong Yang, Version 3.04

DTD Syntax

Part:   1  2  3  

(Continued from previous part...)

1. Required: The attribute is required.

<!ATTLIST element_name
 attribute_name value_type #REQUIRED
 ......
>

2. Implied: The attribute is optional.

<!ATTLIST element_name
 attribute_name value_type #IMPLIED
 ......
>

3. Fixed: The attribute has a fixed value, and the value is specified in the declaration statement. If this attribute is included in the XML file, it must have the specified value. If this attribute is not included in the XML file, the DTD validator will provide it with the specified value.

<!ATTLIST element_name
 attribute_name value_type #FIXED "value"
 ......
>

4. Default: A default value is specified for the attribute. If this attribute is not included in the XML file, the DTD validator will provide it with the specified default value. If this attribute is included in the XML file, the specified default value will be ignored.

<!ATTLIST element_name
 attribute_name value_type "value"
 ......
>

ENTITY Declaration Statement

ENTITY: A DTD statement that defines a new XML entity, and associates a value with it.

<!ENTITY entity_name "entity_value">

Once an entity is defined, it can be used in any parsed text in following form:

&entity_name;
The DTD validator will replace this by the entity value specified in ENTITY statement.

Sample XML File with DTD Statements - dictionary_dtd.xml

Let's use the following XML file, dictionary_dtd.xml, to see how different DTD statements can be used:

<?xml version="1.0"?>
<!-- dictionary_dtd.xml
     Copyright (c) 2002 by Dr. Herong Yang
-->
<!DOCTYPE dictionary [
 <!ELEMENT dictionary (note, word+)>
 <!ELEMENT note ANY>
 <!ELEMENT word (update?, name, definition+, usage*)>
 <!ELEMENT update EMPTY>
 <!ATTLIST update 
  date CDATA #REQUIRED 
  editor CDATA #IMPLIED
 >
 <!ELEMENT name (#PCDATA)>
 <!ATTLIST name is_acronym (true | false) "false">
 <!ELEMENT definition (#PCDATA)>
 <!ELEMENT usage (#PCDATA | i)*>
 <!ELEMENT i (#PCDATA)>
 <!ENTITY herong "Dr. Herong Yang">
]>
<dictionary>
 <note>Copyright (c) 2002 by &herong;</note>
 <word>
  <name is_acronym="true">POP</name>
  <definition>Post Office Protocol</definition>
  <definition>Point Of Purchase</definition>
 </word>
 <word>
  <update date="2002-12-23"/> 
  <name is_acronym="true">XML</name>
  <definition>eXtensible Markup Language</definition>
 </word>
 <word>
  <update date="2002-12-23" editor="Herong Yang"/> 
  <name>markup</name>
  <definition>The amount added to the cost price to calculate 
the selling price</definition>
 </word>
</dictionary>

Part:   1  2  3  

Dr. Herong Yang, updated in 2006
Herong's Tutorial Notes On XML Technologies - DTD Syntax