DTD Basics   «Prev  Next»

Lesson 1

Introduction to DTD Basics

XML documents are valid only if they conform to the structural and syntactical rules of a DTD.
Therefore it is important to know the basics of creating DTDs.
In this module, you will create DTDs for existing XML documents. You will also use a DTD as a guideline for creating new XML documents that conform to the rules laid out in the DTD.

Module learning objectives

After completing this module, you will have the skills and knowledge necessary to:
  1. Describe a valid XML document
  2. Describe the process for creating a DTD
  3. Declare basic elements in a DTD and specify their content
  4. Write element declarations for mixed content and declare empty elements
  5. Reference DTD declarations in XML
  6. Create a DTD file which works with a separate XML file
  7. Create a DTD from an existing set of tags
n the next lesson, the concept of a valid XML document will be discussed.

XML predefines no elements at all. Instead, XML allows you to define your own elements, as needed. However, these elements and the documents built from them are not completely arbitrary. They have to follow a specific set of rules elaborated in this module. A well-formed document is one that follows these rules. Well-formedness is the minimum criterion necessary for XML processors and browsers to read files. This module explores the different parts of an XML document such as tags, text, attributes, elements.
In addition, the primary rules for each part are also discussed. Particular attention is paid to how XML differs from HTML. Along the way I introduce several new XML constructs including comments, processing instructions, entity references, and CDATA sections. This module is not an exhaustive discussion of well-formedness rules. Some of the rules I present must be adjusted slightly for documents that have a document type definition (DTD), and there are additional well-formedness rules that define the relationship between the document and its DTD, but these will be explored in later modules.
An XML document can result from the aggregation of various chunks of data
  1. entities,
  2. schemas, and
  3. DTDs
coming from different network locations. In these cases, the BaseURI property tells you where these nodes come from. If the XML document is being processed through a stream (for example, an in-memory string), no URI is available and the BaseURI property returns the empty string.