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

XML Schemas

Why should the definition of elements in an XML file be in a non-XML syntax? This simple question led to the development of an alternative to Document Type Definitions (DTDs), XML schemas.

Schemas follow XML syntax rules and offer a more flexible and comprehensive way to define XML elements.

XML Schemas offer the same control as DTDs along with the following extensions (not all of which, however, are implemented at this time):

  • Sequence
    In addition to allowing different enumerations of elements (the "+", "*", and "|" controls of DTDs), schemas also allow elements to occur in any order
  • Data Types
    In addition to the types #PCDATA and CDATA, schemas let you restrict data types to strings, numbers (integer, floating point, fixed point), date and time formats, boolean, hexadecimal, and ASCII, among others
  • Data Values
    Schemas let you set boundaries on data values using controls such as "dt:max", "dt.min", "dt:maxlength", etc.
  • Element Contents
    With schemas, elements can be restricted to containing other elements only, or text only, or a mixture of text and elements, or null.
XML Schema: events_schema.xml
<?xml version="1.0" ?>

<Schema name="listSchema"
   xmlns="urn:schemas-microsoft-com:xml-data"
   xmlns:dt="urn:schemas-microsoft-com:datatypes">

<AttributeType name="Ptype" dt:type="enumeration"
  dt:values="drama comedy" default="drama" />

<ElementType name="play" content="eltOnly" model="closed">
  <description>Contains the title and author 
      of each play</description>
  <attribute type="Ptype" />
  <group order="seq">
    <element type="title" />
    <element type="author" />
  </group>
</ElementType>

<ElementType name="events" content="eltOnly" model="closed">
  <description>Contains the set of plays </description>
    <element type="play" minOccurs="1" maxOccurs="*" />
</ElementType>

<ElementType name="title" content="textOnly" model="closed"
   dt:type="string">
  <description>Contains the title of the play</description>
</ElementType>

<ElementType name="author" content="eltOnly" model="closed">
  <description>Contains the 1st and last 
      name of author</description>
  <group order="seq">
    <element type="First_Name" />
    <element type="Last_Name" />
  </group>
</ElementType>

<ElementType name="First_Name" content="textOnly" model="closed"
  dt:type="string">
</ElementType>

<ElementType name="Last_Name" content="textOnly" model="closed"
  dt:type="string">
</ElementType>

</Schema>


Referencing A Schema From An XML File: events3.xml
<?xml version='1.0'?>

<events xmlns="x-schema:events_schema.xml">
  <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

Resources

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