[xhtml]

Bottom Up and Top Down: Introduction to XML Schema

R. Alexander Milowski

milowski at sims.berkeley.edu

#1

Bottom Up: An Example

We've got our pizza orders in XML...

<orders xmlns='urn:publicid:IDN+cde.berkeley.edu:schemas:examples:200402:us'>
  
  <order taken-on="2004-02-23T18:43:00-08:00">
     <pizza>
        <toppings>
        <kind>Jalapenos</kind>
        <kind>Pepperoni</kind>
        <kind>Feta</kind>
        <kind>Garlic</kind>
        </toppings>
     </pizza>
  </order>

  <order taken-on="2004-02-23T19:22:00-08:00">
     <pizza>
        <toppings>
        <kind>Ham</kind>
        </toppings>
     </pizza>
  </order>

  <order taken-on="2004-02-23T19:26:00-08:00">
     <pizza>
        <half>
        <toppings>
        <kind>Green Olives</kind>
        </toppings>
        </half>
     </pizza>
  </order>

</orders>

#2

An Example - Continued

And our deliveries in XML as well...

<delivery xmlns='urn:publicid:IDN+cde.berkeley.edu:schemas:examples:200402:us'>

  <order taken-on="2004-02-23T18:43:00-08:00" delivered-on="2004-02-23T19:15:00-08:00">
     <pizza>
        <toppings>
        <kind>Jalapenos</kind>
        <kind>Pepperoni</kind>
        <kind>Feta</kind>
        <kind>Garlic</kind>
        </toppings>
     </pizza>
  </order>

</delivery>

#3

Create the Schema Document

#4

The Schema Concepts

#5

The 'orders' Element

#6

The 'order' Element

#7

The 'order' Element Declaration

The XML Schema elves cooked this up over night while you slept:

  <xs:element name="order">
     <xs:complexType>
        <xs:sequence>
        <xs:element ref="my:pizza" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="taken-on" type="xs:dateTime" use="required"/>
        <xs:attribute name="on-its-way" type="xs:boolean"/>
        <xs:attribute name="delivered-on" type="xs:dateTime"/>
     </xs:complexType>
  </xs:element>

But now we need to declare my:pizza...

#8

The Elves Were Busy...

Good thing we have XML Schema elves:

  <xs:element name="pizza">
     <xs:complexType>
        <xs:sequence>
           <xs:choice>
              <xs:element ref="my:toppings"/>
              <xs:sequence>
                 <xs:element name="half" form="qualified" minOccurs="2" maxOccurs="2">
                    <xs:complexType>
                       <xs:sequence>
                          <xs:element ref="my:toppings"/>
                       </xs:sequence>
                    </xs:complexType>
                 </xs:element>
              </xs:sequence>
           </xs:choice>
        </xs:sequence>
     </xs:complexType>
  </xs:element>
  
  <xs:element name="toppings">
     <xs:complexType>
        <xs:sequence>
           <xs:element name="kind" form="qualified" maxOccurs="unbounded" type="xs:string"/>
        </xs:sequence>
     </xs:complexType>
  </xs:element>

#9

Are We Done?

#10

My Answer

Very similiar to the 'orders' element but forced to be non-empty:

  <xs:element name="delivery">
     <xs:complexType>
        <xs:sequence>
        <xs:element ref="my:order" maxOccurs="unbounded"/>
        </xs:sequence>
     </xs:complexType>
  </xs:element>

#11

Validating with Netbeans

#12

Specifying the Schema Location

#13

No More Elves

#14

Top Down: What Are Schemas?

#15

Schema Language vs Schema Language

#16

Structure Relations

#17

Structure - Children & Models

#18

Structure - Mixed Content

#19

Structure - Wildcards

#20

Structure - Attributes

#21

Structure - Validation Control

#22

Types of Constraints

#23

Value Constraints

#24

Cross Referencing Constraints

#25

Cross-Field Constraints

#26

Typing

#27

Value Constraints as Typing

#28

Element Structure Derivation

#29

Name vs. Type

#30

Polymorphic Content

#31

XML Schema