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:
- Describe a valid XML document
- Describe the process for creating a DTD
- Declare basic elements in a DTD and specify their content
- Write element declarations for mixed content and declare empty elements
- Reference DTD declarations in XML
- Create a DTD file which works with a separate XML file
- 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
- schemas, and
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.