Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

Introduction to DTD Syntax

DTDs use a specialized non-XML vocabulary, which includes the following grammar for writing and declaring markup rules that define a specific type of XML document structure:

DTD declaration statements can be added internally as a section within the <!DOCTYPE> declaration of the XML document. Alternatively, you can use a resource URI to point to an external DTD file.

For example, the following is an internal DTD that could be added to the sample XML file (Books.xml) to describe and validate its contents.

Internal DTD

<!DOCTYPE catalog [ 
<!ELEMENT catalog    (book+) >
<!ELEMENT book       (author, title, genre, price, publish_date, description) >
<!ATTLIST book       id ID #REQUIRED >
<!ELEMENT author         (#PCDATA)   >
<!ELEMENT title          (#PCDATA)   >
<!ELEMENT genre          (#PCDATA)   >
<!ELEMENT price          (#PCDATA)   >
<!ELEMENT publish_date   (#PCDATA)   >
<!ELEMENT description    (#PCDATA)   >
]>

The first line identifies "catalog" as the document type (DOCTYPE), which also happens to be the name of the root element. After this, various elements are defined for the "catalog" document type.

A set of open ([) and close (]) brackets contain this DTD as an internal section within the DOCTYPE statement. This section needs to be inserted at the top of the books.xml sample file so that it can be read as a set of directives for the XML parser to use when validating and parsing the remaining XML portion of the of the document. The DTD declaration statements are made within these brackets:

See Also

What is a DTD? | Authoring DTDs