Document Type Definition validation

XML relationship to DTD

What does an XML document do?
An XML document contains the data that is being used.
For example:
The name element contains: John Smith
The address element contains: 123 Main Street, Texarkana, TX
This data could be in an employee document, that contains all the employee data for John Smith.

What does an DTD document do?
An DTD document describes an XML document.
For example:
employee must be the root element in the XML document
exactly one name element must be in the XML document
the name element must be immediatly followed by exactly one address element in the XML document

An XML document does not need to be related to a DTD. If it has no DTD to specify what the XML document must contain, then the XML document may contain anything. For example, it might contain the country of birth of the first 97 presidents of the United States of America.
The only requirement is that the XML document must be well formed, with a closing for each opening tag, et cetera.

An XML document can be related to a DTD.
For example, this page that you are looking at has a !DOCTYPE specified:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This means that the DTD for this page is the w3c standard DTD, which specifies XHTML 1.0 strict. Often, there are many XML pages that use the same DTD. There may be millions of pages that use the XHTML 1.0 strict DTD.

When you relate your XML document to a DTD, it means you intend to meet the spcifications given in the DTD.
If you have done a good job, and meet all the DTD spcicifications, your document is valid.

Validate your XML document

There are two steps needed to validate your XML document. Always do the first step, then the second step.

Check to be sure the XML document is well formed.
This check makes sure the XML document is internally consistent.
In the XML Copy Editor, you can do this by clicking the left check mark.
Check to be sure the XML document is valid.
This check makes sure the XML document matches the requirements of the DTD.
In the XML Copy Editor, you can do this by clicking the right check mark.

Build a good DTD

Do not try to just sit down and build a complete DTD all at once. Follow the following set of simple steps, adding a little at a time.

  1. Make a plan of approximatly what you want the XML documents to look like.
  2. Build an XML document with only the root element, and no other elements.
  3. Check the XML document to be sure it is well formed.
  4. Build a corresponding DTD for only the root element.
  5. Check the XML document to be sure it is valid.
  6. After successful validation, repeatedly do the following steps.
    • Add one or two things to your XML document.
    • Check the XML document to be sure it is well formed.
    • Make the corresponding extensions to your DTD.
    • Check the XML document to be sure it is valid.

By taking small steps, you can correct problems as you go along. It can dificult to sort out a combination of problems that may be in the XML, or may be in the DTD, or may be due to an interaction of both. Taking small steps makes this much easier.

At some point in the process, you may wish to introduce an additional XML document, to test other capabilities of the DTD you are building.

Lab 3 assignment

Create a DTD document that will validate your lab 2 XML document. Design your DTD document carefully, so it will validate other similar XML documents.
The name of the file containing the document must be lab3.dtd

Put your web page on the Internet

You have built your DTD doucment; now put it on the Internet, so it can be used there.

Complete lab

You have built your lab 3 DTD document and uploaded it to voyager.
Check again to make sure the XML document on voyager is valid.
Then, send an e-mail to instructor. In the e-mail provide the following information:

  • SUBJECT: CIS 89A Lab 3
  • That you have completed Lab 3.