The <!DOCTYPE> Declaration

To make a document valid, it must be associated with a document type definition. The <!DOCTYPE> either directly contains or points to the element and attribute declarations that make up a DTD for a particular XML application. For instance, adding the following line to the document in Listing 2.2 instructs a validating parser to read the declarations in restaurant.dtd and ensures that the contents of the document obey the constraints given:

<!DOCTYPE restaurant SYSTEM "restaurant.dtd">

The SYSTEM keyword tells the parser to read the contents of the file referenced by the relative Uniform Resource Identifier(URI) restaurant.dtd. The contents of this external file are called the external subset. Besides the external subset, the <!DOCTYPE> syntax allows declarations to be included directly within the XML document, like so:

<!DOCTYPE restaurant SYSTEM "restaurant.dtd"
[
  <!ENTITY name "SNL Diner">
]>

The markup included within the [] characters is called the internal subset. To simplify the job of XML parser developers, the internal subset doesn't support the full range of declarations and instructions that can appear in the external subset. For most document authors, this difference is not significant. Consult a complete XML reference for a discussion of internal versus external DTD subsets.

The <!DOCTYPE> markup must appear after the XML declaration (<?xml ...>) but before the single top-level document element. Refer to ValidLunchMenu.xml to see the exact placement of the <!DOCTYPE> markup tag within a document.

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

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