
This is where the power of XML, as a method of self describing and validating data, becomes more obvious. In building DTDs, and later schemas, you will create a "schema" for the data and data types in your project files. Creating and validating with DTDs is, more or less, straightforward. We will use a couple different validating sites to determine if your files are "valid". While XSD has been approved by the W3C, many authors use different approaches to creating these schemas. DTDs are still used by business and technology as standards for ensuring that XML documents are created with consistency. This section normally takes more than a week to cover. Online students are encouraged to stay up with reading, and have have a good DTD to submit by week four (please see the assignment one project progress description that includes a css file for rendering).
From the point of view of a DTD, all XML documents (and HTML documents) are made up of the following building blocks.
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
]>
<address_book> </address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (#PCDATA)>
]>
<address_book> </address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (#PCDATA)>
]>
<address_book>
<record> </record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT contact (#PCDATA)>
]>
<address_book>
<record>
<name> </name>
<address> </address>
<contact> </contact>
</record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, (address | contact))>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT contact (#PCDATA)>
]>
<address_book>
<record>
<name> </name>
<address> </address>
</record>
</address_book>
<!ELEMENT record (name, address, contact, comments?)>
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments*)>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT contact (#PCDATA)>
<!ELEMENT comments (#PCDATA)>
]>
<address_book>
<record>
<name> </name>
<address> </address>
<contact> </contact>
<comments> </comments>
</record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments)>
<!ELEMENT name (first_name, middle_name, last_name, nick_name?)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT middle_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT nick_name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT contact (#PCDATA)>
<!ELEMENT comments (#PCDATA)>
]>
<address_book>
<record>
<name>
<first_name>first name goes here</first_name>
<middle_name>middle name goes here</middle_name>
<last_name>last name goes here</last_name>
<!-- Notice, no nickname needed since it is optional -->
</name>
<address> </address>
<contact> </contact>
<comments> </comments>
</record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments)>
<!ELEMENT name (first_name, middle_name, last_name, nick_name?)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT middle_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT nick_name (#PCDATA)>
<!ELEMENT address (street_address, street_address_detail,
city, state, zipcode)>
<!ELEMENT street_address (#PCDATA)>
<!ELEMENT street_address_detail (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT zipcode (#PCDATA)>
<!ELEMENT contact (#PCDATA)>
<!ELEMENT comments (#PCDATA)>
]>
<address_book>
<record>
<name>
<first_name>first name goes here</first_name>
<middle_name>middle name goes here</middle_name>
<last_name>last name goes here</last_name>
<nick_name>nick name goes here</nick_name>
</name>
<address>
<street_address>street address goes here</street_address>
<street_address_detail>
apartment number goes here
</street_address_detail>
<city>city goes here</city>
<state>state goes here</state>
<zipcode>zipcode goes here</zipcode>
</address>
<contact> </contact>
<comments> </comments>
</record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments)>
<!ELEMENT name (first_name, middle_name, last_name, nick_name?)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT middle_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT nick_name (#PCDATA)>
<!ELEMENT address (street_address, street_address_detail,
city, state, zipcode)>
<!ELEMENT street_address (#PCDATA)>
<!ELEMENT street_address_detail (#PCDATA)>
<!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)>
<!ELEMENT zipcode (#PCDATA)>
<!ELEMENT contact (home_phone, work_phone, cell_phone,
fax_number, email_address)>
<!ELEMENT home_phone (#PCDATA)>
<!ELEMENT work_phone (#PCDATA)>
<!ELEMENT cell_phone (#PCDATA)>
<!ELEMENT fax_number (#PCDATA)>
<!ELEMENT email_address (#PCDATA)>
<!ELEMENT comments (#PCDATA)>
]>
<address_book>
<record>
<name>
<first_name>first name goes here</first_name>
<middle_name>middle name goes here</middle_name>
<last_name>last name goes here</last_name>
<nick_name>nick name goes here</nick_name>
</name>
<address>
<street_address>street address goes here</street_address>
<street_address_detail>
apartment number goes here
</street_address_detail>
<city>city goes here</city>
<state>state goes here</state>
<zipcode>zipcode goes here</zipcode>
</address>
<contact>
<home_phone>home phone goes here</home_phone>
<work_phone>work phone goes here</work_phone>
<cell_phone>cell phone goes here</cell_phone>
<fax_number>fax number goes here</fax_number>
<email_address>email address goes here</email_address>
</contact>
<comments> </comments>
</record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [
<!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments)>
<!ELEMENT name (first_name, middle_name, last_name, nick_name?)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT middle_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT nick_name (#PCDATA)>
<!ELEMENT address (street_address, street_address_detail,
city, state, zipcode)>
<!ELEMENT street_address (#PCDATA)>
<!ELEMENT street_address_detail (#PCDATA)>
<!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)>
<!ELEMENT zipcode (#PCDATA)>
<!ELEMENT contact (home_phone, work_phone, cell_phone,
fax_number, email_address)>
<!ELEMENT home_phone (#PCDATA)>
<!ELEMENT work_phone (#PCDATA)>
<!ELEMENT cell_phone (#PCDATA)>
<!ELEMENT fax_number (#PCDATA)>
<!ELEMENT email_address (#PCDATA)>
<!ELEMENT comments (misc_comments)>
<!ELEMENT misc_comments (#PCDATA)>
]>
<address_book>
<record>
<name>
<first_name>first name goes here</first_name>
<middle_name>middle name goes here</middle_name>
<last_name>last name goes here</last_name>
<nick_name>nick name goes here</nick_name>
</name>
<address>
<street_address>street address goes here</street_address>
<street_address_detail>
apartment number goes here
</street_address_detail>
<city>city goes here</city>
<state>state goes here</state>
<zipcode>zipcode goes here</zipcode>
</address>
<contact>
<home_phone>home phone goes here</home_phone>
<work_phone>work phone goes here</work_phone>
<cell_phone>cell phone goes here</cell_phone>
<fax_number>fax number goes here</fax_number>
<email_address>email address goes here</email_address>
</contact>
<comments>
<misc_comments>comments go here</misc_comments>
</comments>
</record>
</address_book>
<?xml version="1.0"?>
<!-- The first step is to name and define our documents-->
<!DOCTYPE address_book [ <!ELEMENT address_book (record+)>
<!ELEMENT record (name, address, contact, comments)>
<!ATTLIST record ID CDATA #REQUIRED>
.
.
.
<address_book>
<record ID="1">
<name>
.
.
.
.
.
.
<!ENTITY copyright "©">
]>
<address_book>
<copyright>©right; 2003</copyright>
.
.
.
<!ELEMENT para (#PCDATA | fact | name)*>
The xml document, below, uses the story.dtd and shows an example of each possible combination that "para" may use. Line breaks have been added for readability.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE story SYSTEM "story.dtd">
<story>
<chapter id="1">
<para id="1">Some words will go here and a
<fact>will appear here</fact> and then my initials.
Some more words will go here and a <fact>will appear here</fact> and then my
initials again <name>RDC</name>.
</para>
<para id="2">Some words will go here and a
<fact>will appear here</fact> and then my initials.
<name>RDC</name>Some more words will go here and a
<fact>will appear here</fact> and then my initials again <name>RDC</name>.
</para>
<para id="3">
</para>
<para id="4">And only text is in this element. So all the other elements are
optional
</para>
</chapter>
</story>
<!--DTD generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<!ELEMENT course_outline (outcomes, activities, assessments, resources, assignments, exams, portfolio)>
<!ATTLIST course_outline
id CDATA #REQUIRED
>
<!ELEMENT outcomes (outcome+)>
<!ELEMENT resource (#PCDATA)>
<!ATTLIST resource
number ID #REQUIRED
activity IDREF #REQUIRED
>
<!ELEMENT outcome (#PCDATA)>
<!ATTLIST outcome
number ID #REQUIRED
activity IDREFS #REQUIRED
assessment IDREFS #REQUIRED
resource IDREFS #REQUIRED
>
<!ELEMENT activities (activity+)>
<!ELEMENT activity (#PCDATA)>
<!ATTLIST activity
number ID #REQUIRED
resource IDREF #REQUIRED
>
<!ELEMENT assessments (assessment+)>
<!ELEMENT assessment (#PCDATA)>
<!ATTLIST assessment
number ID #REQUIRED
type (assignment | exam | portfolio) #REQUIRED
outcome IDREF #REQUIRED
>
<!ELEMENT resources (resource+)>
<!ELEMENT assignments (assignment+)>
<!ELEMENT assignment (#PCDATA)>
<!ATTLIST assignment
number ID #REQUIRED
resource IDREF #REQUIRED
outcome IDREF #REQUIRED
>
<!ELEMENT exams (exam)>
<!ELEMENT exam (#PCDATA)>
<!ATTLIST exam
number ID #REQUIRED
outcome IDREF #REQUIRED
>
<!ELEMENT portfolio (link)>
<!ATTLIST portfolio
url CDATA #REQUIRED
outcome IDREFS #REQUIRED
>
<!ELEMENT link (#PCDATA)>
The following is the Assertion Network XML file that uses the DTD shown above:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE course_outline SYSTEM "course_outline.dtd">
<course_outline id="CID_123"> <outcomes> <outcome number="O1" activity="ACT1" assessment="AS1" resource="R1"> Outcome number one </outcome> <outcome number="O2" activity="ACT2" assessment="AS2" resource="R2"> Outcome number two </outcome> <outcome number="O3" activity="ACT3" assessment="AS3" resource="R3"> Outcome number three </outcome> <outcome number="O4" activity="ACT4" assessment="AS4" resource="R4"> Outcome number four </outcome> <outcome number="O5" activity="ACT5" assessment="AS5" resource="R5"> Outcome number five </outcome> </outcomes>
<activities> <activity number="ACT1" resource="R1">Activity one</activity> <activity number="ACT2" resource="R2">Activity two</activity> <activity number="ACT3" resource="R3">Activity three</activity> <activity number="ACT4" resource="R4">Activity four</activity> <activity number="ACT5" resource="R5">Activity five</activity> </activities> <assessments> <assessment number="AS1" type="assignment" outcome="O1">Assessment one</assessment> <assessment number="AS2" type="assignment" outcome="O2">Assessment two</assessment> <assessment number="AS3" type="assignment" outcome="O3">Assessment three</assessment> <assessment number="AS4" type="exam" outcome="O4">Assessment four</assessment> <assessment number="AS5" type="portfolio" outcome="O5">Assessment five</assessment> </assessments> <resources> <resource number="R1" activity="ACT1">Resource one</resource> <resource number="R2" activity="ACT2">Resource two</resource> <resource number="R3" activity="ACT3">Resource three</resource> <resource number="R4" activity="ACT4">Resource four</resource> <resource number="R5" activity="ACT5">Resource five</resource> </resources> <assignments> <assignment number="ASN1" resource="R1" outcome="O1">Assignment One</assignment> <assignment number="ASN2" resource="R2" outcome="O2">Assignment One</assignment> <assignment number="ASN3" resource="R3" outcome="O3">Assignment One</assignment> </assignments> <exams> <exam number="E1" outcome="O4">Exam one</exam> </exams> <portfolio url="http://www.theospi.org/portfolio" outcome="O1 O2 O3 O4 O5"> <link>http://www.theospi.org/portfolio</link> </portfolio> </course_outline>
Step through the w3schools DTD tutorial: http://www.w3schools.com/DTD/