4.2 Document Type Declarations


An XML document refers to a DTD within an XML"<!DOCTYPE>" tag. The document type declaration can do either or both of the following:

  • Contain the markup declarations in an internal subset within the <!DOCTYPE> tag

  • Point to an external subset containing markup declarations

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">   graphics/arrow.gif DTD reference <memo>   <to>Jon</to>   <from>Chris</from>   <subject>Reminder</subject>   <body>Three PM meeting canceled. Have a great weekend</body> </memo> 

In the DTDs, "memo" is the root element.

4.2.1 Document Type Declaration Format

The 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

  • A DTD declares all of the valid document elements using element type declarations. A DTD always contains the rules that define the syntax for elements and, if more than one are present, the relationship between elements.

  • A document type declaration contains the rules that define the syntax for attributes for any elements that have attributes.

  • It may contain rules that define entities.

  • It may contain rules that define notations.

4.2.3 Conditional Sections

The 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.



Secure XML(c) The New Syntax for Signatures and Encryption
Secure XML: The New Syntax for Signatures and Encryption
ISBN: 0201756056
EAN: 2147483647
Year: 2005
Pages: 186

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net