XML & DTDs
Computing Resources >> Tutorials >> Web Development >> XML & DTDs  

Introduction and Objectives

XML Anatomy

Creating a Simple XML Document

"Well Formed" vs. Valid

Is Your Markup Well-Formed?

Creating a DTD

Validating with a DTD

XML Resources

Evaluate this tutorial

Validating with a DTD

Linking your XML document to a DTD

Now that you've created a DTD for an XML document, you need to link the XML to the DTD. This takes place in the prolog of the XML document.

Remember that the prolog starts off with the XML declaration:

<?xml version="1.0" encoding="iso-8859-1"?>

Immediately following the XML declaration, you would then either link to a DTD or write an internal DTD. While DTDs can be both internal or external, if you are using a DTD for multiple documents, it makes more sense to have the DTD in a separate "external" file. Otherwise, you will have to put the full DTD in the prolog of every XML document, rather than just one line of code.

To link to an external DTD, the declaration goes like this:

<!DOCTYPE RootElementName SYSTEM "DTDfileLocation">

Note: SYSTEM in the DTD declaration can be replaced by PUBLIC if the DTD is available via the Internet. You would then need to have a public name for the DTD in the file. For example, the W3Group uses DTDs for the various markup languages they recommend. Here is the recommended DTD for strict XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Assuming that the message.dtd file we created was in the same folder as our XML files for our email and letters, we would add the following line to the XML code:

<!DOCTYPE message SYSTEM "message.dtd">

Compare the files email.xml and email2.xml to see the differences.

Validating with a DTD

Now that you have the XML linked, you'll need a full parser to validate the XML files. While most browsers can check for well formed XML, only Internet Explorer 5.0 and higher has a complete XML parser built in to the program that checks against DTDs. You can also use programs such as Dreamweaver, Cooktop, and a variety of other XML authoring software.

There are also online resources, such as this online XML Validator, but you need an internal DTD or a DTD available on the Internet in order to compare it against.

An internal DTD is located in the same place as a link to an external DTD but follows the following structure.

<!DOCTYPE rootElement [

Element and attribute declarations go here between the brackets ]>

Internal DTD declaration
directions

To link to a DTD on the Internet, you first need to have an account that can serve items to the web, such as an iSchool account. Then you would need to link to the external DTD with the full URL address. So if we were hosting message.dtd in your personal iSchool account, its link would appear as the following: <!DOCTYPE message SYSTEM http://www.ischool.utexas.edu/~youraccountname/message.dtd >.

For more information about using an iSchool account to post items on the Internet, see the How to Use Your School of Information Account tutorial.

Hopefully, you now feel comfortable creating some basic XML and DTD documents. For more resources on XML and DTDs and XML editors, continue on.

next section >

 

Watch the video
screenshot
Choose format/speed:

real media dial-up | broadband
real media dial-up | broadband

Entire tutorial (with captions)
real
media dial-up | broadband
windows media dial-up | broadband

Flash version of tutorial
segment | entire

html transcript

© 2004 Jacob Cleary | iSchool | UT Austin | webmaster