D A T Y P I C
home
services
books
Overview
Table of Contents
Sample Chapter
Examples
1. Intro
2. Quick tour
3. Namespaces
4. Include/Import
5. Instances
6. Annotations
7. Element Decls
8. Attribute Decls
9. Simple types
10. Regexes
11. Union/List types
12. Built-in types
13. Complex types
14. Type derivation
15. Groups
16. Subst. groups
17. ID constraints
18. Redefines
19. DTDs topics
20. Naming
21. Extensibility
Errata
about
Definitive XML Schema

Definitive XML Schema

Priscilla Walmsley (pwalmsley@datypic.com)
1st edition (December 7, 2001)
Prentice Hall PTR; ISBN: 0130655678
Amazon.com
Buy at 30% off list price


Chapter 1: Schemas: an introduction


Full Example

This example consists of a very simple instance and schema.

Instance (chapter01.xml)

<product effDate="2001-04-02"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="chapter01.xsd">
  <number>557</number>
  <size>10</size>
</product>

Schema (chapter01.xsd)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="product" type="ProductType"/>
  <xs:complexType name="ProductType">
    <xs:sequence>
      <xs:element name="number" type="xs:integer"/>
      <xs:element name="size" type="SizeType"/>
    </xs:sequence>
    <xs:attribute name="effDate" type="xs:date"/>
  </xs:complexType>
  <xs:simpleType name="SizeType">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="2"/>
      <xs:maxInclusive value="18"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>


Book Examples

Example 1-1. Product instance

<product effDate="2001-04-02">
  <number>557</number>
  <size>10</size>
</product>


Example 1-2. Product schema

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="product" type="ProductType"/>
  <xsd:complexType name="ProductType">
    <xsd:sequence>
      <xsd:element name="number" type="xsd:integer"/>
      <xsd:element name="size" type="SizeType"/>
    </xsd:sequence>
    <xsd:attribute name="effDate" type="xsd:date"/>
  </xsd:complexType>
  <xsd:simpleType name="SizeType">
    <xsd:restriction base="xsd:integer">
      <xsd:minInclusive value="2"/>
      <xsd:maxInclusive value="18"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>


Example 1-3. Product DTD

<!ELEMENT product (number, size?)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT size (#PCDATA)>
<!ATTLIST product effDate CDATA #IMPLIED>