| home / web / authoring / languages / xml / questions |
![]() |
|
Whats a DTD and why do I need one (or not)?One of the keys to XML (and SGML) is the Document Type Definition (DTD), the specification for a particular class of documents. A DTD says what types of elements are meaningful for his type of document, and how they fit together. DTDs are important because they provide a basis for creating and managing whole groups of documents of the same type in a uniform way. This improves the quality of your information, because at least one source of error or confusion has been removed. HTMLs use of DTDs was fairly static (see HTML DTDs) but in XML it is different: you actively choose whether or not to use a DTD. If your editing software is smart enough (or if you are accurate enough), you can omit any DTD and fabricate the markup on the fly to suit the occasion. It just has to follow the rules in the XML specification for DTD-less markup, known as standalone XML, so that browsers can read it without error. This is fairly straightforward:
<?xml version="1.0" standalone="yes"?> <?xml-style href="quickmessage.xsl" type="text/xsl"?> <message stamp="1998-08-18T11:32:45.26+0000"> <to address="mike@foo.com">Mike</to> <text>Are you free for lunch at 1.00pm today?</text> <from address="pete@foo.com">Peter</from> </message> But if you are going to create the same type of document again and again (and most people do seem to want to do this), its a lot easier if you use a standard structure (and vary the appearance with a stylesheet if you wish). A DTD provides this structure. But youre not constrained to using an existing DTD: you can write your own, which is why so many groups of potential users are busy producing them. The example above represents a DTD which would look something like this: <!ELEMENT message (to,text,from)> <!ATTLIST message stamp CDATA #REQUIRED> <!ELEMENT to (#PCDATA)> <!ATTLIST to address CDATA #REQUIRED> <!ELEMENT text (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ATTLIST from address CDATA #REQUIRED> The declaration for each element type provides an
expression which models what it may contain: usually either more
element types (here |
Comments are welcome
All Rights Reserved. Legal Notices.
Created: May 11, 1998
Revised: May 14, 1998
URL: http://www.webreference.com/authoring/xml/dtd.html