DTD -Document Type Definition
To use XML you need a DTD (Document Type Definition). A DTD contains
the rules for a particular type of XML-documents. Actually it's the DTD
that defines the language.
A DTD describes elements.
<!ELEMENT breed (#PCDATA)>
- the above describes the XML element called breed
- The description (#PCDATA) stands for parsed character data.
It's the tag that is shown and also will be parsed (interpreted)
by the program that reads the XML document. You can also define
(#CDATA), this stands for character data. CDATA will not be parsed
or shown.
|
Sub-elements.
e.g. dog has sub-elements breed and name, each which can contain
characters.
<!ELEMENT dog (breed. name)>
<!ELEMENT breed (#PCDATA)>
<!ELEMENT name (#PCDATA) >
|
Occurance of Sub-Elements:
- + must occur at least one time but may occur more often
- * may occur more often but may also be omitted
- ? may occur once or not at all
The indications are used behind the sub element name. For instance:
<!ELEMENT animal (color+)>
|
Choice of Sub-Elements
<!ELEMENT animal (wingsize|legsize) >
|
How to Include DTD information
External file
1) in the XML file after the <?xml version="1.0">
line you must type
<DOCTYPE name of root-element SYSTEM "URL-to-DTD-file">
2) the first line of the DTD file must also be
<DOCTYPE name of root-element SYSTEM "URL-to-DTD-file">
|
Internal to XML file
In the XML, after the <?xml version="1.0"> line,
<!DOCTYPE name of root-element [
followed by the element definitions. The DTD part is closed
with
]>
|
|