An XML document refers to a DTD within an XML"<!DOCTYPE>" tag. The document type declaration can do either or both of the following:
The document type declaration must appear before the first element in the document. Examples 4-1 and 4-2 provide samples of internal and external DTDs. Example 4-1 Internal DTD<?xml version="1.0"?> <!DOCTYPE memo [ <!ELEMENT memo (to,from,subject,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT subject (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <memo> <to>Jon</to> <from>Chris</from> <subject>Reminder</subject> <body>Three PM meeting canceled. Have a great weekend</body> </memo> Example 4-2 External DTD<?xml version="1.0"?> <!DOCTYPE memo SYSTEM "memo.dtd"> In the DTDs, "memo" is the root element. 4.2.1 Document Type Declaration FormatThe document type declaration begins with <!DOCTYPE. The name of the document's root element follows, then either of two elements: (1) the DTD contained in a pair of square brackets or (2) the SYSTEM keyword and a URI for the external DTD. You can include either an external or an internal DTD, or both. The declaration ends with a close angle bracket (">"). For example: <!DOCTYPE The-name-of-root-element SYSTEM "URI of external DTD" [ Internal DTD ]> The SYSTEM keyword simply indicates that a URI pointing to an external DTD follows. Line breaks and white space are not significant. 4.2.2 Document Type Declaration Guidelines
4.2.3 Conditional SectionsThe external document type declaration subset can have portions that are included or excluded as indicated by an enclosing conditional syntax (e.g., the keyword "INCLUDE" or "IGNORE"). These keywords can be the value of an entity. This syntax was commonly used in SGML document preparation systems to "comment out" portions of a DTD, but it is rarely used in modern XML. See [XML] for further details. |