Java Reference
In-Depth Information
Note
Document Type Definition and document type declaration are two different
things.TheDTDacronymidentifiesaDocumentTypeDefinitionandneveridentifies
a document type declaration.
A document type declaration appears immediately after the XML declaration and is
specified in one of the following ways:
•
<!DOCTYPE
root-element-name
SYSTEM
uri
>
references an ex-
ternal but private DTD via
uri
. The referenced DTD is not available for
public scrutiny. For example, I might store my recipe language's DTD file
website, and use
<!DOCTYPE recipe SYSTEM "ht-
tp://www.tutortutor.ca/dtds/recipe.dtd">
to identify this
DTD's location via system identifier
http://www.tutortutor.ca/
•
<!DOCTYPE
root-element-name
PUBLIC
fpi uri
>
references
and
uri
.IfavalidatingXMLparsercannotlocatetheDTDviapublicidentifier
fpi
, it can use system identifier
uri
to locate the DTD. For example,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trans-
itional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm-
l1-transitional.dtd">
referencestheXHTML1.0DTDfirstviapub-
lic identifier
-//W3C//DTD XHTML 1.0 Transitional//EN
, and
second via system identifier
http://www.w3.org/TR/xhtml1/DTD/
•
<!DOCTYPE
root-element
[
dtd
]>
referencesaninternalDTD,one
that is embedded within the XML document. The internal DTD must appear
between square brackets.
Listing10-8
presents
Listing10-1
(minusthechildelementsbetweenthe
<recipe>
and
</recipe>
tags) with an internal DTD.
Listing 10-8.
The recipe document with an internal DTD
<?xml version="1.0"?>
<!DOCTYPE recipe [
<!ELEMENT recipe (title, ingredients, instructions)>
<!ELEMENT title (#PCDATA)>