DTD Basics   «Prev 

Working with DTDs

There are two ways of associating a DTD with a document: internally and externally. The internal approach includes the DTD within the XML document. Although this is not a very common way of using DTDs in the IT world, it can be very useful during development because you can easily change the shape of the XML and associated DTD and you can quickly confirm they are consistent with each other. Once a DTD has been developed, typically XML documents will be associated with it by reference. It is very likely you will have seen such a reference already; a large proportion of HTML pages include a line like the following:
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

You will soon see what all of this means, but first you need to get equipped to write your own DTDs. To get started, the following section examines a text editor with DTD support that can be used to parse and validate XML documents.


Separate DTD and XML

Filename: hello.xml
Filename: hello.xml

The standalone attribute has a value of "no" because the DTD information will not be included in the XML file.
The standalone attribute has a value of "no" because the DTD information will not be included in the XML file.


The <!DOCTYPE> declaration points to the external DTD file.
The <!DOCTYPE> declaration points to the external DTD file.