Java Reference
In-Depth Information
<state>Illinois</state>
<zip>60603</zip>
</address>
The name following the DOCTYPE keyword must always match the root element name in the document
so the DOCTYPE declaration here indicates that the root element in the document has the name
address . The declaration also indicates that the DTD in which this and the other elements in the
document are declared is an external DTD located at the URI following the SYSTEM keyword. This
URI, which is invariably a URL, is called the system ID for the DTD.
In principle you can also specify an external DTD by a public ID using the keyword PUBLIC in place of
the SYSTEM . A public ID is just a unique public name that identifies the DTD - a URN in other words.
As you probably know, the idea behind URNs is to get over the problem of changes to URLs. Public
IDs are intended for DTDs that are available as public standards for documents of particular types such
as SVG. However, there is a slight snag. Since there is no mechanism defined for resolving public IDs to
find the corresponding URL, if you specify a public ID you still have to supply a system ID with a URL
so the XML processor can find it, so you won't see public IDs in use much.
If the file containing the DTD is stored on the local machine, you can specify its location relative to the
directory containing the XML document. For example, the following DOCTYPE declaration implies the
DTD is in the same directory as the document itself:
<!DOCTYPE address SYSTEM "AddressDoc.dtd">
The AddressDoc.dtd file includes definitions for the elements that may be included in a document
containing an address. In general a relative URL is assumed to be relative to the location of the
document containing the reference.
Defining a DTD
In looking at the details of how we put a DTD together we will use examples where the DTD is an
internal subset, but the declarations in an external DTD are exactly the same. Here's an example of a
document with an integral DTD:
<?xml version="1.0"?>
<!DOCTYPE proverb [ <!ELEMENT proverb (#PCDATA)> ]>
<proverb>A little knowledge is a dangerous thing.</proverb>
All the internal definitions for elements used within the document appear between the square brackets
in the DOCTYPE declaration. In this case there is just one element declared, the root element, and the
element content is PCDATA - parsed character data.
We could define an external DTD in a file with the name proverbDoc.dtd in the same directory as
the document. The file would contain just a single line:
<!ELEMENT proverb (#PCDATA)>
Search WWH ::




Custom Search