DTD Basics   «Prev  Next»

Lesson 7Referencing DTD declarations
ObjectiveReference DTD Declarations in XML

Reference DTD Declarations in XML

Every XML file that uses a DTD must have a document type declaration[1] which is used to declare the DTD. That is, the structure and syntax of a given DTD is defined using a document type declaration. A document type declaration has thefollowing general syntax:

<!DOCTYPE root element name [DTD]>

This syntax may vary depending on whether the document type declaration points to an internal DTD, as indicated using the syntax above, or an external DTD.
Using a document type declaration to reference an external DTD will be presented later in the course.

The standalone attribute

A special standalone attribute may be added to the <?xml?> declaration to indicate whether the <!DOCTYPE> declaration should point to
  1. internal or
  2. external
DTD declarations.
If all the DTD information will be enclosed within the XML document, you can specify that the standalone attribute's value is "yes". If the XML document should be referencing an external DTD, the value of this attribute should be "no" The following tag indicates that the DTD information should appear in the XML document itself:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 

If the DTD will exist in a separate file, you would use the following XML declaration instead:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> 

Both the internal and external DTD examples require a <!DOCTYPE> declaration in some form.
The <!DOCTYPE> declaration should be on the line just below the <?xml?> declaration to avoid errors when the document is parsed.
In the next lesson, I will discuss how to create a DTD file to work with a separate XML files.
[1]Document Type Declaration : The document type declaration names the document type being used and links to or includes its definition, the DTD. The <!DOCTYPE > declaration should be on the line just below the <?xml?> declaration.