Herong's Tutorial Notes On XML Technologies
Dr. Herong Yang, Version 3.04

DTD Syntax

Part:   1   2  3 

This tutorial describes:

  • DOCTYPE Declaration Statement
  • ELEMENT Declaration Statement
  • ATTLIST Declaration Statement
  • ENTITY Declaration Statement
  • Sample XML File with DTD Statements - dictionary_dtd.xml

DTD is a simple language with only 4 statements:

  • DOCTYPE: Links an XML file to a set of DTD statements.
  • ELEMENT: Declares an XML element.
  • ATTLIST: Declares one or more XML attributes.
  • ENTITY: Declares one XML entity.

DOCTYPE Declaration Statement

DOCTYPE: A special statement included in an XML file to declare that this XML file has been linked to DTD statements either internally or externally.

Valid syntax formats for DOCTYPE statement are:

<!DOCTYPE root_element [
   internal_DTD_statements
]>
<!DOCTYPE root_element SYSTEM "DTD_location">
<!DOCTYPE root_element SYSTEM "DTD_location" [
   internal_DTD_statements
]>
<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location">
<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location"
   internal_DTD_statements
]>

General rules about the DOCTYPE statements:

  • It must appear right after the "xml" processing instruction.
  • It must name the root element of the XML file.
  • Key word "SYSTEM" indicates that the external DTD file is private.
  • Key word "PUBLIC" indicates that the external DTD file is public.
  • "DTD_location" is a URL of the external DTD file.
  • "DTD_name" is a publicly recognized name of a specific DTD file, like "-//W3C//DTD HTML 4.0 Transitional//EN".
  • If an internal DTD statement is conflicting with an external statement, the internal statement takes precedence.

ELEMENT Declaration Statement

ELEMENT: A DTD statement that defines an XML element. The ELEMENT statement specifies what is the name of the element, and what is structure of its content.

The syntax for ELEMENT statement is:

<!ELEMENT element_name content_expression>

"content_expression" is made of key words, element names, expressional symbols, and grouping parentheses. Elements can be declared as one of the following 5 content modes:

1. Empty Content: No text or child element is allowed in the content.

<!ELEMENT element_name EMPTY>

(Continued on next part...)

Part:   1   2  3 

Dr. Herong Yang, updated in 2006
Herong's Tutorial Notes On XML Technologies - DTD Syntax