J2EEOnline J2EEOnline

DTD Basics   «Prev  Next»
Lesson 11

Simple and Complex DTD Conclusion

This module discussed how simple and complex DTDs define the syntax, grammar, and vocabulary of XML documents.
Now that you have learned the basics of the DTD, you are ready to build the DTD.

Learning objectives

DTDs and XML Schemas

Both document type definitions (DTDs) and XML Schemas serve to describe the definition of an XML document, its structure, and what data is allowed where. They can then be used to test whether a document that has been received is consistent with the prescribed format, a process known as validation. DTDs are the older standard and have been around since SGML. They are gradually succumbing to XML Schemas but are still in widespread use particularly with (X)HTML. They also have a few features that XML lacks, such as the ability to create entity declarations and the ability to add default attribute content. In general, XML Schemas offer more functionality; they also have the advantage of being written in XML so the same tools can be used with both the data and its schema. DTDs on the other hand use a completely different format that is much harder to work with. In addition to assisting with validation, DTDs and XML Schema are also used to help authorship of XML documents. Most modern XML editors allow you to create an XML document based on a specified schema. They prompt you with valid choices from the schema as you are editing and also warn you if you have used an element or attribute in the wrong location. Although many have misgivings about how XML Schemas have developed, it is probably true to say that most recently developed XML formats are described using schemas rather than DTDs.

Glossary terms

This module introduced the following terms:
  1. Document type declaration: The document type declaration names the document type being used and links to or includes its definition, the DTD.
  2. Infrastructure services
  3. Mixed content
  4. PCDATA : PCDATA means parsed character data. Think of character data as the text found between the start tag and the end tag of an XML element.
  5. Root element

System Identifiers

A system identifi er enables you to specify the location of an external file containing DTD declarations. It is comprised of two parts:
  1. the keyword SYSTEM, and
  2. a URI reference pointing to
the document's location. A URI can be a fi e on your local hard drive, a fi e on your intranet or network, or even a file available on the Internet:
<!DOCTYPE name SYSTEM "name.dtd" [...]>
You must type the word SYSTEM after the name of the root element in your declaration. Following the SYSTEM keyword is the URI reference to the location of the file, in quotation marks. The following examples use system identifiers:
<!DOCTYPE name SYSTEM "file:///c:/name.dtd" [ ]>
<!DOCTYPE name SYSTEM "http://wiley.com/hr/name.dtd" [ ]>
<!DOCTYPE name SYSTEM "name.dtd">

Notice that the last example has no [ and ]characters and this is perfectly normal. Specifying an internal subset is optional. An XML document might conform to a DTD that uses only an internal subset, only an external subset, or both. If you do specify an internal subset, it appears between the [ and ], immediately following the system identifier.

DTD-XML-Document - Quiz

Click the Quiz link below to check your understanding of DTDs.
DTD-XML-Document - Quiz

The next module discusses how to build the DTD.