CS639 orderDap schemas: two namespaces, so two schemas

======================Link.xsd=================================================
Note: handling of attributes

<?xml version="1.0" standalone="yes"?>

<xs:schema version="1.0" targetNamespace="http://schemas.restbucks.com/dap" xmlns:tns="http://schemas.restbucks.com/dap" xmlns:xs="http://www.w3.org/2001/XMLSchema">

 

  <xs:element name="link" type="tns:link"/>

 

  <xs:complexType name="link">

    <xs:sequence/>

    <xs:attribute name="rel" type="xs:string"/>

    <xs:attribute name="uri" type="xs:string"/>

    <xs:attribute name="mediaType" type="xs:string"/>

  </xs:complexType>

</xs:schema>

======================OrderDap.xsd==========================================
Notes: import of Link.xsd, ns1: prefix set up for it, item is no longer global (no @XmlRootElement on Item.java),  abstract complex type (can’t be used on its own), ref=”ns1:link” to element declaration in the imported schema, type extension for complex types

<?xml version="1.0" standalone="yes"?>

<xs:schema elementFormDefault="qualified" version="1.0" targetNamespace="http://schemas.restbucks.com" xmlns:ns1="http://schemas.restbucks.com/dap" xmlns:tns="http://schemas.restbucks.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">

 

  <xs:import namespace="http://schemas.restbucks.com/dap" schemaLocation="Link.xsd"/>

 

  <xs:element name="order" type="tns:orderRepresentation"/>

 

  <xs:element name="payment" type="tns:paymentRepresentation"/>

 

  <xs:complexType name="paymentRepresentation">

    <xs:complexContent>

      <xs:extension base="tns:representation">

        <xs:sequence>

          <xs:element name="amount" type="xs:double"/>

          <xs:element name="cardholderName" type="xs:string" minOccurs="0"/>

          <xs:element name="cardNumber" type="xs:string" minOccurs="0"/>

          <xs:element name="expiryMonth" type="xs:int"/>

          <xs:element name="expiryYear" type="xs:int"/>

        </xs:sequence>

      </xs:extension>

    </xs:complexContent>

  </xs:complexType>

 

  <xs:complexType name="representation" abstract="true">

    <xs:sequence>

      <xs:element ref="ns1:link" minOccurs="0" maxOccurs="unbounded"/>

    </xs:sequence>

  </xs:complexType>

 

  <xs:complexType name="orderRepresentation">

    <xs:complexContent>

      <xs:extension base="tns:representation">

        <xs:sequence>

          <xs:element name="item" type="tns:item" maxOccurs="unbounded"/>

          <xs:element name="location" type="tns:location"/>

          <xs:element name="cost" type="xs:double"/>

          <xs:element name="status" type="tns:orderStatus" minOccurs="0"/>

        </xs:sequence>

      </xs:extension>

    </xs:complexContent>

  </xs:complexType>

 

  <xs:complexType name="item">

    <xs:sequence>

      <xs:element name="milk" type="tns:milk"/>

      <xs:element name="size" type="tns:size"/>

      <xs:element name="drink" type="tns:drink"/>

    </xs:sequence>

  </xs:complexType>

<xs:simpleType name="milk">

    <xs:restriction base="xs:string">

      <xs:enumeration value="whole"/>

      <xs:enumeration value="skim"/>

      <xs:enumeration value="semi"/>

      <xs:enumeration value="none"/>

    </xs:restriction>

  </xs:simpleType>

 

  <xs:simpleType name="size">

    <xs:restriction base="xs:string">

      <xs:enumeration value="small"/>

      <xs:enumeration value="medium"/>

      <xs:enumeration value="large"/>

    </xs:restriction>

  </xs:simpleType>

 

  <xs:simpleType name="drink">

    <xs:restriction base="xs:string">

      <xs:enumeration value="espresso"/>

      <xs:enumeration value="latte"/>

      <xs:enumeration value="cappuccino"/>

      <xs:enumeration value="flatWhite"/>

    </xs:restriction>

  </xs:simpleType>

 

  <xs:simpleType name="location">

    <xs:restriction base="xs:string">

      <xs:enumeration value="takeaway"/>

      <xs:enumeration value="inStore"/>

    </xs:restriction>

  </xs:simpleType>

 

  <xs:simpleType name="orderStatus">

    <xs:restriction base="xs:string">

      <xs:enumeration value="unpaid"/>

      <xs:enumeration value="preparing"/>

      <xs:enumeration value="ready"/>

      <xs:enumeration value="taken"/>

    </xs:restriction>

  </xs:simpleType>

</xs:schema>

Another use of type extension, from Harold’s order.xsd, Chap 1: add an attribute to a SimpleType, making it a ComplexType.

<xsd:complexType name="MoneyType">

    <xsd:simpleContent>

      <xsd:extension base="xsd:decimal">

        <xsd:attribute name="currency" type="xsd:string"/>

      </xsd:extension>

    </xsd:simpleContent>

  </xsd:complexType>

 

In the XML: an element of typu MoneyType:

<Total currency='USD'>290.79</Total>