Document Type Definition (DTD)
Once you have created your own elements, the next step is
to define what kind of data each element will consist of.
The original method for doing this task was called a
Document Type Definition (DTD). This method is borrowed
from SGML and has its own specific language and syntax.
A DTD largely controls the syntax and semantics of an XML
file by:
-
Specifying the sequence in which elements appear
-
Selecting one out of a group of elements or attributes,
using the alternation "|" character
-
Specifying whether or not an attribute is required
-
Specifying the number of times an element can appear: "+"
means 1 or more times, "*" means 0 or more times, "?"
means 0 or 1 time, and no control means exactly one time
-
Specifying the type of data an item can hold: #PCDATA
(Parsed Code Data) means ordinary ASCII without HTML
control characters, whereas CDATA can contain any
character information including HTML control codes
|
Document Type Definition: events2.dtd
|
<!ELEMENT events (play+)>
<!ELEMENT play (title, author)>
<!ATTLIST play Ptype (drama | comedy) "drama">
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (First_Name, Last_Name)>
<!ELEMENT First_Name (#PCDATA)>
<!ELEMENT Last_Name (#PCDATA)>
|
|
Referencing A DTD From An XML File: events2.xml
|
<?xml version='1.0'?>
<!DOCTYPE events SYSTEM "events2.dtd">
<events>
<play Ptype = "drama">
<title>Three Sisters </title>
<author>
<First_Name>Anton</First_Name>
<Last_Name>Chekhov</Last_Name>
</author>
</play>
<play Ptype = "comedy">
<title>As You Like It</title>
<author>
<First_Name>William</First_Name>
<Last_Name>Shakespeare</Last_Name>
</author>
</play>
</events>
|
Files
|
|
 |
|
 |