|
Imposing Structure on XML Documents Using a DTD
An Introduction to Document Type Definitions |
|
Prof. David Bernstein |
| Computer Science Department |
| bernstdh@jmu.edu |
DOCTYPE declaration in
the XML documentDOCTYPE Declaration:
DOCTYPE Declaration (in the XML Document)
DOCTYPE
|
The root declaration. |
ELEMENT
|
Declares an element type. |
ATTLIST
|
Declares an attribute list for an element type. |
+
|
The element can appear one or more times. |
*
|
The element can appear zero or more times. |
?
|
The element can appear zero or one times. |
|
|
Essentially the delimiter in a list of possible elements. |
#PCDATA
|
The element can contain any text (i.e., parsed character data). |
EMPTY
|
The element has no content. |
ANY
|
The element can have any type of content. |
DOCTYPE Declaration (in a DTD)ELEMENT Declaration (in a DTD)ELEMENT Declaration (cont.)ATTLIST Declaration (in a DTD)ATTLIST Declaration (cont.)
<!ELEMENT timetable (train*) >
<!ATTLIST timetable subtitle CDATA #IMPLIED>
<!ATTLIST timetable title CDATA #IMPLIED>
<!ELEMENT station (#PCDATA) >
<!ELEMENT stop (station, time*) >
<!ELEMENT time (#PCDATA) >
<!ATTLIST time status (Ar | Dp) #IMPLIED>
<!ELEMENT train (stop+) >
<!ATTLIST train businessclass (YES | NO) "NO" >
<!ATTLIST train normaldays (Daily | Mo-Fr | Sa | Su) #REQUIRED >
<!ATTLIST train number CDATA #REQUIRED >
<!ATTLIST train reservations (YES | NO) "NO" >
<?xml version="1.0"?>
<!DOCTYPE timetable SYSTEM "timetable.dtd">
<timetable title="Boston...Providence...New London...New York"
subtitle="Through services to Philadelphia...Washington...Newport News">
<train number="95" normaldays="Mo-Fr" reservations="YES" businessclass="YES">
<stop>
<station>Boston, MA-South Station</station>
<time>6:20AM</time>
</stop>
<stop>
<station>Boston, MA-Back Bay</station>
<time>6:25AM</time>
</stop>
<stop>
<station>Route 128, MA</station>
<time>7:07AM</time>
</stop>
<stop>
<station>Providence, RI</station>
<time>7:31AM</time>
</stop>
<stop>
<station>Kingston, RI</station>
<time></time>
</stop>
<stop>
<station>Westerly, RI</station>
<time></time>
</stop>
<stop>
<station>Mystic, CT</station>
<time></time>
</stop>
<stop>
<station>New London, CT</station>
<time>8:06AM</time>
</stop>
<stop>
<station>Old Saybrook, CT</station>
<time></time>
</stop>
<stop>
<station>New Haven, CT</station>
<time status="Ar">9:00AM</time>
<time status="Dp">9:15AM</time>
</stop>
<stop>
<station>Bridgeport, CT</station>
<time></time>
</stop>
<stop>
<station>Stamford, CT</station>
<time></time>
</stop>
<stop>
<station>New Rochelle, NY</station>
<time></time>
</stop>
<stop>
<station>New York, NY</station>
<time status="Ar">10:50AM</time>
</stop>
<stop>
<station>Newark, NJ</station>
<time>11:26AM</time>
</stop>
<stop>
<station>Metropark, NJ</station>
<time>11:40AM</time>
</stop>
<stop>
<station>Trenton, NJ</station>
<time>12:04AM</time>
</stop>
<stop>
<station>Philadelphia, PA</station>
<time>12:32PM</time>
</stop>
<stop>
<station>Wilmington, DE</station>
<time>12:58PM</time>
</stop>
<stop>
<station>Baltimore, MD</station>
<time>1:49PM</time>
</stop>
<stop>
<station>BWI Airport Rail Sta., MD</station>
<time>2:02PM</time>
</stop>
<stop>
<station>New Carrollton, MD</station>
<time>2:17PM</time>
</stop>
<stop>
<station>Washington, DC</station>
<time>2:35PM</time>
</stop>
<stop>
<station>Richmond, VA</station>
<time>5:19PM</time>
</stop>
<stop>
<station>Newport News, VA</station>
<time status="Ar">7:07PM</time>
</stop>
</train>
<train number="191" normaldays="Sa" reservations="YES" businessclass="YES">
<stop>
<station>Boston, MA-South Station</station>
<time>6:20AM</time>
</stop>
<stop>
<station>Boston, MA-Back Bay</station>
<time>6:25AM</time>
</stop>
<stop>
<station>Route 128, MA</station>
<time>7:07AM</time>
</stop>
<stop>
<station>Providence, RI</station>
<time>7:31AM</time>
</stop>
<stop>
<station>Kingston, RI</station>
<time></time>
</stop>
<stop>
<station>Westerly, RI</station>
<time></time>
</stop>
<stop>
<station>Mystic, CT</station>
<time></time>
</stop>
<stop>
<station>New London, CT</station>
<time>8:06AM</time>
</stop>
<stop>
<station>Old Saybrook, CT</station>
<time></time>
</stop>
<stop>
<station>New Haven, CT</station>
<time status="Ar">9:00AM</time>
<time status="Dp">9:15AM</time>
</stop>
<stop>
<station>Bridgeport, CT</station>
<time></time>
</stop>
<stop>
<station>Stamford, CT</station>
<time></time>
</stop>
<stop>
<station>New Rochelle, NY</station>
<time></time>
</stop>
<stop>
<station>New York, NY</station>
<time status="Ar">10:50AM</time>
</stop>
<stop>
<station>Newark, NJ</station>
<time>11:26AM</time>
</stop>
<stop>
<station>Metropark, NJ</station>
<time>11:40AM</time>
</stop>
<stop>
<station>Trenton, NJ</station>
<time>12:04AM</time>
</stop>
<stop>
<station>Philadelphia, PA</station>
<time>12:32PM</time>
</stop>
<stop>
<station>Wilmington, DE</station>
<time>12:58PM</time>
</stop>
<stop>
<station>Baltimore, MD</station>
<time>1:49PM</time>
</stop>
<stop>
<station>BWI Airport Rail Sta., MD</station>
<time>2:02PM</time>
</stop>
<stop>
<station>New Carrollton, MD</station>
<time>2:17PM</time>
</stop>
<stop>
<station>Washington, DC</station>
<time>2:35PM</time>
</stop>
<stop>
<station>Richmond, VA</station>
<time></time>
</stop>
<stop>
<station>Newport News, VA</station>
<time></time>
</stop>
</train>
<train number="171" normaldays="Daily" businessclass="YES">
<stop>
<station>Boston, MA-South Station</station>
<time>7:22AM</time>
</stop>
<stop>
<station>Boston, MA-Back Bay</station>
<time>7:27AM</time>
</stop>
<stop>
<station>Route 128, MA</station>
<time>7:42AM</time>
</stop>
<stop>
<station>Providence, RI</station>
<time>8:17AM</time>
</stop>
<stop>
<station>Kingston, RI</station>
<time>8:43AM</time>
</stop>
<stop>
<station>Westerly, RI</station>
<time>8:59AM</time>
</stop>
<stop>
<station>Mystic, CT</station>
<time>9:10AM</time>
</stop>
<stop>
<station>New London, CT</station>
<time>9:25AM</time>
</stop>
<stop>
<station>Old Saybrook, CT</station>
<time>9:47AM</time>
</stop>
<stop>
<station>New Haven, CT</station>
<time status="Ar">10:25AM</time>
<time status="Dp">10:35AM</time>
</stop>
<stop>
<station>Bridgeport, CT</station>
<time>10:57AM</time>
</stop>
<stop>
<station>Stamford, CT</station>
<time>11:23AM</time>
</stop>
<stop>
<station>New Rochelle, NY</station>
<time>11:43AM</time>
</stop>
<stop>
<station>New York, NY</station>
<time status="Ar">12:20PM</time>
</stop>
<stop>
<station>Newark, NJ</station>
<time>12:56PM</time>
</stop>
<stop>
<station>Metropark, NJ</station>
<time></time>
</stop>
<stop>
<station>Trenton, NJ</station>
<time>1:34PM</time>
</stop>
<stop>
<station>Philadelphia, PA</station>
<time>2:02PM</time>
</stop>
<stop>
<station>Wilmington, DE</station>
<time>2:43PM</time>
</stop>
<stop>
<station>Baltimore, MD</station>
<time>3:42PM</time>
</stop>
<stop>
<station>BWI Airport Rail Sta., MD</station>
<time>3:55PM</time>
</stop>
<stop>
<station>New Carrollton, MD</station>
<time>4:10PM</time>
</stop>
<stop>
<station>Washington, DC</station>
<time>4:30PM</time>
</stop>
<stop>
<station>Richmond, VA</station>
<time></time>
</stop>
<stop>
<station>Newport News, VA</station>
<time></time>
</stop>
</train>
</timetable>