<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE dtd-name .... >
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE dtd-name [ ... element declarations ... ]> <dtd-name> . . . </dtd-name>
<?xml version="1.0" encoding="UTF-8"?>
<!-- using an internal document type definition
for an invitation list to a party -->
<!DOCTYPE invitationList [
<!ELEMENT invitationList (person*)>
<!ELEMENT person ( #PCDATA )>
]>
<invitationList>
<person>mal sutherland</person>
<person>brian retallick</person>
<person>mary martin</person>
<person>fran soddell</person>
<person>phil scott</person>
<person>peter goddard</person>
</invitationList>
.dtd
extension) located by a URI. The preceding document might look like:<?xml version="1.0" encoding="UTF-8"?>
<!-- using an external document type definition
for an invitation list to a party -->
<!DOCTYPE invitationList SYSTEM "party.dtd">
<invitationList>
<person>mal sutherland</person>
<person>brian retallick</person>
<person>mary martin</person>
<person>fran soddell</person>
<person>phil scott</person>
<person>peter goddard</person>
</invitationList>
party.dtd are:<!ELEMENT invitationList (person*)> <!ELEMENT person ( #PCDATA )>
#PCDATA
SYSTEMhref.PUBLICSYSTEM
in the above examplePUBLIC identifier takes the form:
registration type // owner // DTD description // language
ISO The DTD is an ISO standard.+ The DTD is an approved non-ISO standard- The DTD is a non-approved, non-ISO standard<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 //EN"
"http://www.w3c.org/TR/html4/strict.dtd">|
Symbol
|
Meaning |
? |
zero or one occurrence of this entity |
* |
zero or more occurrences of this entity |
+ |
one or more occurrences of this entity |
, |
sequence order |
| |
or (choice, alternation) |
meals.dtd
<!ELEMENT meals ( breakfast, lunch, tea )>
<!-- meals must contain exactly one of each of the elements
breakfast, lunch and tea in sequence -->
<!ELEMENT breakfast (food+)>
<!-- breakfast must contain one or more food items -->
<!ELEMENT lunch (food?)>
<!-- lunch can be zero or one food item -->
<!ELEMENT tea (food*)>
<!-- tea can be zero or more food items -->
<!ELEMENT food (fruit | vegetable | fish | poultry | meat | dairy |cereal)>
<!-- food is one of fruit, veg, fish, poultry, meat, dairy or cereal -->
<!ELEMENT fruit (#PCDATA)>
<!ELEMENT vegetable (#PCDATA)>
<!ELEMENT fish (#PCDATA)>
<!ELEMENT poultry (#PCDATA)>
<!ELEMENT meat (#PCDATA)>
<!ELEMENT dairy (#PCDATA)>
<!ELEMENT cereal (#PCDATA)>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE meals SYSTEM "meals.dtd">
<meals>
<breakfast>
<food>
<fruit>grapefruit</fruit>
</food>
<food>
<cereal>rice bubbles</cereal>
</food>
<food>
<dairy>yogurt</dairy>
</food>
</breakfast>
<lunch>
<food>
<meat> meat pie </meat>
</food>
</lunch>
<tea>
<food>
<poultry>chicken</poultry>
</food>
<food>
<vegetable>chips</vegetable>
</food>
<food>
<vegetable>peas</vegetable>
</food>
<food>
<dairy>ice cream</dairy>
</food>
</tea>
</meals>
<!-- weather.dtd --> <!ELEMENT report (weather-station)*> <!ELEMENT weather-station (location, rainfall, max-temp, min-temp)> <!ELEMENT location (latitude, longitude, place-name)> <!ELEMENT latitude (#PCDATA)> <!ELEMENT longitude (#PCDATA)> <!ELEMENT place-name (#PCDATA)> <!ELEMENT rainfall (#PCDATA)> <!ELEMENT max-temp (#PCDATA)> <!ELEMENT min-temp (#PCDATA)>
<!-- weather.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE report SYSTEM "weather.dtd">
<report>
<weather-station>
<location>
<latitude>-36.82</latitude>
<longitude>144.30</longitude>
<place-name>Mandurang</place-name>
</location>
<rainfall>5.0</rainfall>
<max-temp>18.1</max-temp>
<min-temp>6.2</min-temp>
</weather-station>
<weather-station>
<location>
<latitude>-36.77</latitude>
<longitude>144.28</longitude>
<place-name>Bendigo</place-name>
</location>
<rainfall>8.0</rainfall>
<max-temp>19.1</max-temp>
<min-temp>7.0</min-temp>
</weather-station>
</report>
<!ATTLIST element attributeName [attributeType] [value] [-- descriptive comment ]>
<!ELEMENT x (#PCDATA)>
<!ATTLIST x
a CDATA #REQUIRED
b CDATA #IMPLIED
c CDATA #FIXED "value"
d CDATA "value" >
<!ELEMENT y (#PCDATA)>
<!ATTLIST y a #REQUIRED>
<!ELEMENT z (someElement)>
<!ATTLIST z a "value"
<!ELEMENT myTag (#PCDATA)>
<!ATTLIST myTag year "2004">
<!--year is an optional attribute with default value of "2005"-->
REQUIRED ... the attribute is required to be presentIMPLIED ... the attribute is optional and the default value
assumed by the application is usedFIXED ... the attribute is required and is set to a fixed value (that
must be specified in the DTD)<!ATTLIST myTag year CDATA "2005"> <myTag year ="2005">......</myTag> <myTag> ...... </myTag> <!-- the missing attribute "year" is assumed to have the value "2005" by the parser. -->