Document Type Declaration

The Document Type Declaration, also called the DOCTYPE declaration, is optional. If present, it must occur before the document element. The DOCTYPE declaration specifies the element type name of the document element and, optionally, references external markup declarations or may include markup declarations.

The simplest form of the Document Type Declaration may be written as follows:

<!DOCTYPE theDocumentElement > 
<theDocumentElement> 
<!-- The content of the document element would go here --> 
</theDocumentElement> 

As written, the preceding DOCTYPE declaration simply indicates that the document element of the XML document has the element type name of theDocumentElement.

In addition to indicating the element type name of the document element, the DOCTYPE declaration contains or points to the markup declarations that optionally define the permitted structure of an XML document. The markup declarations provide a grammar for a class of XML documents.

A DOCTYPE Declaration, when present, may have two additional optional parts:

  • An indication of the location of the external subset of the Document Type Definition, DTD (see Chapter 4, “Valid XML—Document Type Definitions,” for further explanation)

  • A set of markup declarations that constitute the internal subset of the DTD (also discussed in Chapter 4)

When an external subset of the DTD exists, it may be expressed as a relative URI, as follows:

<!DOCTYPE documentElementName SYSTEM "myDTD.dtd" > 

Here, SYSTEM is a keyword indicating that the location of the external subset of the DTD is specified relative to the current system. The system identifiermyDTD.dtd, in this case—is a uniform resource identifier (URI) that indicates the location of the external subset.

A system identifier may be identified by a relative URI, as in the preceding example, or a full URI reference, as follows:

<!DOCTYPE myElement SYSTEM "http://www.XMML.com/myDTD.dtd"> 

An alternate syntax is to specify a public identifier, using the keyword PUBLIC, together with a system identifier:

<!DOCTYPE documentElementName PUBLIC publicidentifier SYSTEM 
  myDTD.dtd > 

This form is used when a public identifier is appropriate—for example, in the DOCTYPE declaration of the XML application language Extensible Hypertext Markup Language (XHTML) documents. For XHTML version 1.0, the DOCTYPE declaration is as follows:

<!DOCTYPE html 
 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
   transitional.dtd" > 

The public identifier indicates an organization—in this case, the W3C— and also includes an indication of the language—in this case, English, indicated by EN.

The syntax for defining the internal subset of the DTD is described in Chapter 4.

Caution

The Document Type Declaration and the Document Type Definition (DTD) are not identical, although they are closely related. The Document Type Declaration defines the location of the external subset of the DTD and optionally may contain the internal subset of the DTD.



..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset