446 Chapter 25 – Introduction to XML
Document Type Definition (DTD)
Web Design in a Nutshell, eMatter Edition
is too bloated in that it has features that are unnecessary and wouldn’t be used.
Also, SGML documents themselves are too large and would unnecessarily take up
much of the Web’s bandwidth.
Clearly a more portable, Web-specific version of SGML had to be created. Thus
XML is SGML’s smaller cousin. XML is SGML with a reduced feature set. It is
powerful enough to describe data, but light enough to travel across the Web.
Document Type Definition (DTD)
Another important part of XML is the Document Type Definition (DTD), which
defines each tag and provides more information about each tag or the document
in general. A DTD can be part of an XML file itself, but it is usually a separate file
or series of files. The DTD is what turns XML from a meta-language into a true
language designed for a specific task. It’s a type of file associated with SGML and
XML documents that defines how markup tags should be interpreted by the appli-
cation reading the document.
The HTML Specification that defines how web pages should be displayed by a
browser is one example of a DTD. Other emerging technologies, such as the
proposed multimedia standard SMIL and the proposed vector graphics standard
PGML (both discussed later in this chapter), use DTDs that were created in compli-
ance with the XML meta-language.
If you were creating recipes that could be accessed over the Web, you might
create your own language called RML or Recipe Markup Language. RML would
have tags like<title>and<body>, but would also have RML specific tags such
as<ingredients>,<prep-time>, and<nutritional-information>.
These tags would be established in a DTD for the new language. The DTD imparts
detailed information about what data should be found in each tag. A DTD for
Recipe Markup Language might have a line like this:
<!ELEMENT ingredients ( li+, text? )>
The first line declares an element calledingredients.Aningredientstag can
contain anlielement and text. The plus sign (+) afterliindicates that an “ingre-
dients” element will have one or more “li” elements within it. The question mark
aftertextshows that text is optional. The Recipe Markup Language DTD would
also specify the “li” element:
<!ELEMENT li (#PCDATA)>
This element contains text only.
XML doesn’t have to be associated with a DTD. You can simply mark up a docu-
ment, and assume the person reading your XML file already has the proper DTD
or will make up their own. Because XML doesn’t require a DTD, you can turn
your existing DTD-less HTML files into XML by making a few changes.
XML Syntax Basics
Browsers will often recover from sloppily written or illegal HTML. This won’t be
the case with XML documents. A client reading an XML document may be reading