<!DOCTYPE NEWSPAPER [
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
]>
DTDs consist of three basic parts:
Element declarations
Attribute declarations
Entity declarations
Sequence
sequence must declare at the exact order:
<!ELEMENT contact (name, location, phone, knows, description)>
| or operator:
<!ELEMENT location (address | GPS)>
Combination of both:
<!ELEMENT location (address | (latitude, longitude))>
Mixed Content with #PCDATA
text only:
<!ELEMENT first (#PCDATA)>
DTD allow mixed tags with #PCDATA
REMEMBER: when #PCDATA is mixed with other tags, then #PCDATA must be write first and follow the following format
<!ELEMENT description (#PCDATA | em | strong | br)*>
The * character is known as a cardinality indicator
If there are child elements, the * cardinality indicator must appear at the end of the model
Cadinality
Empty Content
<!ELEMENT br EMPTY>
Any Content
Attribute Declaration
- The ATTLIST keyword
- The associated element's name
- The list of declared attributes
<!ELEMENT contacts (contact*)>
<!ATTLIST contacts source CDATA #IMPLIED>
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, the value must be #IMPLIED or #REQUIRE |
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 |
Value | Explanation |
---|---|
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 |
Entity
<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">
XML example:
<author>&writer;©right;</author>
ID, IDREF and IDREFS
IDREF The value is the id of another element
IDREFS The value is a list of other ids, separated by SPACE
<!ATTLIST Course Prerequisites IDREFS #IMPLIED>
<!ATTLIST Professor InstrID ID #REQUIRED>
<!ATTLIST Lecturer InstrID ID #REQUIRED>
<!ATTLIST Courseref Number IDREF #REQUIRED>