Wattle Software - producers of XMLwriter XML editor
 Home | Search | Site Map 
XMLwriter
 Screenshots
 Features
 About Latest Version
 Awards & Reviews
 User Comments
 Customers
Download
 Download XMLwriter
 Download Plug-ins
 Download Help Manual
 MSXML Updates
 Downloading FAQ
Buy
 Buy XMLwriter
 Pricing
 Upgrading
 Sales Support
 Sales FAQ
Support
 Sales Support
 Technical Support
 Submit a Bug Report
 Feedback & Requests
 Technical FAQ
Resources
 XML Links
 XML Training
 XMLwriter User Tools
 The XML Guide
 XML Book Samples
Wattle Software
 About Us
 Contact Details
DOCTYPE Declaration & DTDs

The document type (DOCTYPE) declaration consists of an internal, or references an external Document Type Definition (DTD). It can also have a combination of both internal and external DTDs. The DTD defines the constraints on the structure of an XML document. It declares all of the document's element typesglossary, children element types, and the order and number of each element type. It also declares any attributes, entities, notations, processing instructions, comments, and PE references in the document.



The Internal DTD:

<!DOCTYPE root_element [

Document Type Definition (DTD):
  elements/attributes/entities/notations/
  processing instructions/comments/PE references

]>

Example:
<?xml version="1.0" standalone="yes" ?>

<!--open the DOCTYPE declaration -
  the open square bracket indicates an internal DTD-->
<!DOCTYPE foo [

<!--define the internal DTD-->
  <!ELEMENT foo (#PCDATA)>

<!--close the DOCTYPE declaration-->
]>

<foo>Hello World.</foo>

Rules:

  • The document type declaration must be placed between the XML declaration and the first element (root element) in the documentwell-formedness constraint.
  • The keyword DOCTYPE must be followed by the name of the root element in the XML documentvalidity constraint.
  • The keyword DOCTYPE must be in upper casewell-formedness constraint.



The External DTD:

External DTDs are useful for creating a common DTD that can be shared between multiple documents. Any changes that are made to the external DTD automatically updates all the documents that reference it. There are two types of external DTDs: private, and public.

Rules:

  • If any elements, attributes, or entities are used in the XML document that are referenced or defined in an external DTD, standalone="no" must be included in the XML declarationvalidity constraint.


"Private" External DTDs:

Private external DTDs are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors.

<!DOCTYPE root_element SYSTEM "DTD_location">

where:

  • DTD_location: relative or absolute URLglossary
Example:
<!--inform the XML processor
  that an external DTD is referenced-->
<?xml version="1.0" standalone="no" ?>

<!--define the location of the
  external DTD using a relative URL address-->
<!DOCTYPE document SYSTEM "subjects.dtd">

<document>
  <title>Subjects available in Mechanical Engineering.</title>
  <subjectID>2.303</subjectID>
    <subjectname>Fluid Mechanics</subjectname>
    <prerequisite>
      <subjectID>1.001</subjectID>
      <subjectname>Mathematics</subjectname>
    </prerequisite>
    <classes>4 hours per week (lectures and tutorials) for one
      semester.</classes>
    <assessment>tutorial assignments and one 2hr exam at end of
      course.</assessment>
    <syllabus>
      Fluid statics. The Bernoulli equation. Energy equation. Momentum
      equation. Differential Continuity equation. Differential Energy
      equation. Differential Momentum equation. Dimensional Analysis.
      Similitude. Laminar flow. Turbulent flow. Lift and Drag. Boundary
      layer theory.
    </syllabus>
    <textbooks>
      <author>Foobar</author>
      <booktitle>The Study of Fluid Mechanics</booktitle>
    </textbooks>
</document>

The external DTD ("subjects.dtd") referenced in the example above contains information about the XML document's structure:

subjects.dtd:

<!--see Element Type Declarations
  for an explanation of the following syntax-->
<!ELEMENT document
  (title*,subjectID,subjectname,prerequisite?,
  classes,assessment,syllabus,textbooks*)>
<!ELEMENT prerequisite (subjectID,subjectname)>
<!ELEMENT textbooks (author,booktitle)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT subjectID (#PCDATA)>
<!ELEMENT subjectname (#PCDATA)>
<!ELEMENT classes (#PCDATA)>
<!ELEMENT assessment (#PCDATA)>
<!ATTLIST assessment assessment_type (exam | assignment) #IMPLIED>
<!ELEMENT syllabus (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT booktitle (#PCDATA)>


"Public" External DTDs:

Public external DTDs are identified by the keyword PUBLIC and are intended for broad use. The "DTD_location" is used to find the public DTD if it cannot be located by the "DTD_name".

<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location">

where:

  • DTD_location: relative or absolute URLglossary
  • DTD_name: follows the syntax:
"prefix//owner_of_the_DTD//
  description_of_the_DTD//ISO 639_language_identifier"

Example:
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
  "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>A typical HTML file</TITLE>
</HEAD>
<BODY>
  This is the typical structure of an HTML file. It follows
  the notation of the HTML 4.0 specification, including tags
  that have been deprecated (hence the "transitional" label).
</BODY>
</HTML>

Note:

The following prefixes are allowed in the DTD name:

Prefix: Definition:
ISO The DTD is an ISO standard. All ISO standards are approved.
+ The DTD is an approved non-ISO standard.
- The DTD is an unapproved non-ISO standard.



Combining Internal and External Document Type Definitions:

A document can use both internal and external DTD subsets. The internal DTD subset is specified between the square brackets of the DOCTYPE declaration. The declaration for the external DTD subset is placed before the square brackets immediately after the SYSTEM keyword.

Example:
<!--inform the XML processor
  that an external DTD is referenced-->
<?xml version="1.0" standalone="no" ?>

<!--define the location of the
  external DTD using a relative URL address - the open square
  bracket indicates an internal DTD-->
<!DOCTYPE document SYSTEM "subjects.dtd" [

<!--the markup in the internal DTD
  takes precedence over the external DTD-->
  <!ATTLIST assessment assessment_type (exam | assignment | prac)>
  <!ELEMENT results (#PCDATA)>

<!--close the DOCTYPE declaration-->
]>

subjects.dtd:
<!ELEMENT document
  (title*,subjectID,subjectname,prerequisite?,
  classes,assessment,syllabus,textbooks*)>
<!ELEMENT prerequisite (subjectID,subjectname)>
<!ELEMENT textbooks (author,booktitle)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT subjectID (#PCDATA)>
<!ELEMENT subjectname (#PCDATA)>
<!ELEMENT classes (#PCDATA)>
<!ELEMENT assessment (#PCDATA)>
<!ATTLIST assessment assessment_type (exam | assignment) #IMPLIED>
<!ELEMENT syllabus (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT booktitle (#PCDATA)>

Rules:

  • Declaring an ELEMENT with the same name in both the internal and external DTD subsets is invalidvalidity constraint.


XML Guide TOC

XML Declaration
DOCTYPE Declaration & DTDs
ELEMENT Type Declaration
ATTLIST Declaration
ENTITY Declaration
NOTATION Declaration
CDATA Section
Processing Instruction
Conditional Section
Comments

Glossary

© Wattle Software 1998-2013. All rights reserved.