Last Modified: 1/29/08
  Computer Training
Introduction to XML

Document Type Definition (DTD)

Once you have created your own elements, the next step is to define what kind of data each element will consist of. The original method for doing this task was called a Document Type Definition (DTD). This method is borrowed from SGML and has its own specific language and syntax.

A DTD largely controls the syntax and semantics of an XML file by:
  • Specifying the sequence in which elements appear
  • Selecting one out of a group of elements or attributes, using the alternation "|" character
  • Specifying whether or not an attribute is required
  • Specifying the number of times an element can appear: "+" means 1 or more times, "*" means 0 or more times, "?" means 0 or 1 time, and no control means exactly one time
  • Specifying the type of data an item can hold: #PCDATA (Parsed Code Data) means ordinary ASCII without HTML control characters, whereas CDATA can contain any character information including HTML control codes
Document Type Definition: events2.dtd
  <!ELEMENT events (play+)>
  <!ELEMENT play (title, author)>
     <!ATTLIST play Ptype (drama | comedy) "drama">
  <!ELEMENT title (#PCDATA)>
  <!ELEMENT author (First_Name, Last_Name)>
  <!ELEMENT First_Name (#PCDATA)>
  <!ELEMENT Last_Name (#PCDATA)>


Referencing A DTD From An XML File: events2.xml
<?xml version='1.0'?>
<!DOCTYPE events SYSTEM "events2.dtd">
<events>
  <play Ptype = "drama">
    <title>Three Sisters </title>
    <author>
      <First_Name>Anton</First_Name>
      <Last_Name>Chekhov</Last_Name>
    </author>
  </play>
  <play Ptype = "comedy">
    <title>As You Like It</title>
    <author>
      <First_Name>William</First_Name>
      <Last_Name>Shakespeare</Last_Name>
    </author>
  </play>
</events>


Files

Previous Home Next

Topics

Summary

HTML Is Not Enough

What Is XML?
  Ontologies
  SGML, HTML, & XML

XML Basics
  HTML Example
  XML File
  Structure
  Paths
  Well-Formed
  DTDs
  Schemas
  Validation
  Unicode
  What It Means

Transforming For
Presentation

  DHTML
  CSS
  XSL

Serving And Processing XML
  Server Side
  Client Side

XML Applications   Information Reuse
  B2B
  Text Encoding
  Syndication

Security

XML Resources On The Web

Part Two Of Class

 
Previous Home Next

Other Topics:   XML Editors

©1999 UW Technology