A Simple Document W3C XML Schema

This schema defines the urn:publicid:-:Norman+Walsh:Schema Example:EN namespace by defining several elements and their complex types.

Documents that conform to this schema have the general form:

<doc xmlns="urn:publicid:-:Norman+Walsh:Schema Example:EN">
  <title>Sample Document</title>
  <para>Some paragraphs.</para>
</doc>

The Types

This schema only defines three element types: doc, title, and para.

The doc Type

This is a document.

§1.
  <xs:complexType xmlns="http://www.w3.org/TR/xhtml-basic"
                  name="doc">
    <xs:sequence>
      <xs:element ref="ex:title"
                  minOccurs="0"
                  maxOccurs="1"/>
      <xs:choice minOccurs="1"
                 maxOccurs="unbounded">
        <xs:element ref="ex:para"/>
      </xs:choice>
    </xs:sequence>
  </xs:complexType>

The title Type

This is a title.

§2.
  <xs:complexType xmlns="http://www.w3.org/TR/xhtml-basic"
                  name="title"
                  mixed="true">
    §4. The role Attribute
    <xs:anyAttribute namespace="##other"
                     processContents="lax"/>
  </xs:complexType>

The para Type

This is a paragraph.

§3.
  <xs:complexType xmlns="http://www.w3.org/TR/xhtml-basic"
                  name="para"
                  mixed="true">
    §4. The role Attribute
    <xs:anyAttribute namespace="##other"
                     processContents="lax"/>
  </xs:complexType>

The role Attribute

Each of the complex types in this schema allows an optional role attribute. The role attribute is simply a string.

§4.
    <xs:attribute xmlns="http://www.w3.org/TR/xhtml-basic"
                  name="role"
                  type="xs:string"/>

The Elements

This schema defines one element of each complex type.

§5.
  <xs:element xmlns="http://www.w3.org/TR/xhtml-basic"
              name="doc"
              type="ex:doc"/>
  <xs:element xmlns="http://www.w3.org/TR/xhtml-basic"
              name="para"
              type="ex:para"/>
  <xs:element xmlns="http://www.w3.org/TR/xhtml-basic"
              name="title"
              type="ex:title"/>

The Schema

The schema wrapper surrounds all these definitions.

§6.
<xs:schema xmlns="http://www.w3.org/TR/xhtml-basic" xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:ex="urn:publicid:-:Norman+Walsh:Schema Example:EN"
           targetNamespace="urn:publicid:-:Norman+Walsh:Schema Example:EN"
           elementFormDefault="qualified">
  §1. The doc Type
  §2. The title Type
  §3. The para Type
  §5. The Elements
</xs:schema>