<-- -*- nxml -*- -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:r="http://nwalsh.com/xmlns/extreme2006/recipes/"
                elementFormDefault="qualified" targetNamespace="http://nwalsh.com/xmlns/extreme2006/recipes/">

  <xs:complexType name="RecipeList">
    <xs:sequence>
      <xs:element ref="r:recipe" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="recipeList" type="r:RecipeList"/>

  <xs:simpleType name="Servings">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="1"/>
      <xs:maxInclusive value="12"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="Recipe">
    <xs:sequence>
      <xs:element ref="r:name"/>
      <xs:element ref="r:source" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="r:description" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="r:ingredientList" minOccurs="1" maxOccurs="unbounded"/>
      <xs:element ref="r:preparation"/>
    </xs:sequence>
    <xs:attribute name="servings" type="r:Servings"/>
    <xs:attribute name="time" type="xs:duration"/>
    <xs:attribute name="calories" type="xs:positiveInteger"/>
  </xs:complexType>

  <xs:complexType name="FoodRecipe">
    <xs:complexContent>
      <xs:extension base="r:Recipe"/>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="CandyRecipe">
    <xs:complexContent>
      <xs:extension base="r:FoodRecipe">
        <xs:attribute name="sugarfree" type="xs:boolean"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="DrinkRecipe">
    <xs:complexContent>
      <xs:extension base="r:Recipe">
        <xs:attribute name="virgin" type="xs:boolean"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:element name="recipe" type="r:Recipe" abstract="true"/>
  <xs:element name="beverage" type="r:DrinkRecipe" substitutionGroup="r:recipe"/>
  <xs:element name="appetizer" type="r:FoodRecipe" substitutionGroup="r:recipe"/>
  <xs:element name="entrée" type="r:FoodRecipe" substitutionGroup="r:recipe"/>
  <xs:element name="sidedish" type="r:FoodRecipe" substitutionGroup="r:recipe"/>
  <xs:element name="dessert" type="r:FoodRecipe" substitutionGroup="r:recipe"/>
  <xs:element name="candy" type="r:CandyRecipe" substitutionGroup="r:recipe"/>

  <xs:complexType name="Prose">
    <xs:choice minOccurs="1" maxOccurs="unbounded">
      <xs:element ref="r:p"/>
      <xs:element ref="r:list"/>
    </xs:choice>
  </xs:complexType>

  <xs:element name="description" type="r:Prose"/>
  <xs:element name="preparation" type="r:Prose"/>

  <xs:complexType name="Para" mixed="true">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="em" type="xs:string"/>
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="NumberedList">
    <xs:sequence>
      <xs:element name="item" minOccurs="1" maxOccurs="unbounded" type="r:Prose"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="p" type="r:Para"/>
  <xs:element name="list" type="r:NumberedList"/>

  <xs:complexType name="IngredientList">
    <xs:sequence>
      <xs:element ref="r:title" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="r:ingredient" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="ingredientList" type="r:IngredientList"/>

  <xs:complexType name="Ingredient">
    <xs:sequence>
      <xs:element name="quantity" minOccurs="0" maxOccurs="1">
	<xs:complexType>
	  <xs:simpleContent>
	    <xs:extension base="xs:double">
	      <xs:attribute name="units"/> 
	    </xs:extension>
	  </xs:simpleContent>
	</xs:complexType>
      </xs:element>
      <xs:element name="name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="ingredient" type="r:Ingredient"/>

  <xs:element name="title" type="r:Para"/>
  <xs:element name="name" type="r:Para"/>
  <xs:element name="source" type="r:Para" nillable="true"/>

</xs:schema>