Click to return to the XML (Extensible Markup Language) home page    
Defining Elements and Att...     XML Schema Developer's Gu...    
Web Workshop  |  XML (Extensible Markup Language)

Introduction to Schemas


The schema defines the elements that can appear within the document and the attributes that can be associated with an element. It also defines the structure of the document: which elements are child elements of others, the sequence in which the child elements can appear, and the number of child elements. It defines whether an element is empty or can include text. The schema can also define default values for attributes.

Consider a simple XML document that contains only three elements, "PGROUP," "PERSONA," and "GRPDESCR," as in the following example:

<?xml version="1.0" ?>
<PGROUP>
  <PERSONA>MACBETH</PERSONA>
  <PERSONA>BANQUO</PERSONA>
  <GRPDESCR>generals of the king's army.</GRPDESCR>
</PGROUP>

In all documents of this type, the document element is "PGROUP." In these examples, "PGROUP" does not contain any text, but contains only one or more child elements named "PERSONA," and one child element named "GRPDESCR." The "PERSONA" and "GRPDESCR" elements contain only text and do not contain other elements.

One method for describing this schema is the Document Type Definition (DTD), a grammar that can be used to formally describe a particular schema. The DTD for the example document appears as follows:

<!DOCTYPE PGROUP [ 
<!ELEMENT PGROUP          (PERSONA+, GRPDESCR) >
<!ELEMENT PERSONA         (#PCDATA)  >
<!ELEMENT GRPDESCR        (#PCDATA)  >
]>

For a formal description of the DTD syntax, see the Extensible Markup Language (XML) 1.0 Non-MS link specification.

Introduction to XML Schemas

A second, and more interesting, method is available to users of Internet Explorer 5. XML Schema, like DTD, can be used to specify the schema of a particular class of documents. Unlike DTDs, however, XML Schema uses XML syntax. This is convenient since you are not required to learn a completely new syntax just to describe your grammar—although you do need to learn how to declare elements and attributes using XML Schema. In addition, XML Schemas offer a number of other significant advantages over using DTDs, which are described in the following topics.

The XML Schema implementation that ships with Internet Explorer 5 is based primarily upon the XML-Data Note (http://www.w3.org/TR/1998/NOTE-XML-data-0105/ Non-MS link), posted by the W3C Non-MS link in January 1998, and the Document Content Description (DCD) (http://www.w3.org/TR/NOTE-dcd Non-MS link) note. XML Schemas in Internet Explorer 5 provide support for the subset of XML-Data that coincides directly with the functionality expressed in DCD, albeit in a slightly different XML grammar.

The XML Schema implementation provided with Internet Explorer 5 focuses on syntactic schemas, without support for inheritance or other object-oriented design features. The implementation provided with Internet Explorer 5 is described in the XML Schema Reference.

The following sample demonstrates how to use XML Schema to specify the schema for the sample document.

<?xml version="1.0"?>
<Schema name="schema_sample_1" 
    xmlns="urn:schemas-microsoft-com:xml-data" 
    xmlns:dt="urn:schemas-microsoft-com:datatypes">

  <ElementType name="PERSONA" content="textOnly" model="closed"/>
  <ElementType name="GRPDESCR" content="textOnly" model="closed"/>

  <ElementType name="PGROUP" content="eltOnly" model="closed">
  <element type="PERSONA" minOccurs="1" maxOccurs="*"/>
  <element type="GRPDESCR" minOccurs="1" maxOccurs="1"/>
  </ElementType>
</Schema>


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.