<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!-- xsd:element name="test" type="USPhoneNumberType"/ -->
<!-- xsd:element name="test" type="identifierType"/ -->
<!-- xsd:element name="test" type="twoCharType"/ -->
<!-- xsd:element name="test" type="integerType"/ -->
<!--xsd:element name="test" type="priceType"/ -->
<!--xsd:element name="test" type="partType"/ -->
<xsd:element name="address" type="USAddressType"/>

<xsd:simpleType name="USPhoneNumberType">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="identifierType">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="[a-zA-Z][a-zA-Z0-9]*"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="twoCharType">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="[a-z][0-9]?"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="pnoType">
  <xsd:restriction base="xsd:positiveInteger">
    <xsd:minInclusive value="10000"/>
    <xsd:maxInclusive value="99999"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="integerType">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="0|[-]?[1-9][0-9]*"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="priceType">
  <xsd:simpleContent>
    <xsd:extension base="mydecimal">
      <xsd:attribute name="currency" type="xsd:string"/>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>

<xsd:simpleType name="mydecimal">
  <xsd:restriction base="xsd:decimal">
    <xsd:totalDigits value="7"/>
    <xsd:fractionDigits value="2"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="partType">
  <xsd:all>
    <xsd:element name="pname" type="xsd:string"/>
    <xsd:element name="qoh" type="xsd:positiveInteger"/>
    <xsd:element name="price" type="xsd:decimal"/>
    <xsd:element name="level" type="xsd:positiveInteger"/>
  </xsd:all>
  <xsd:attribute name="pno" type="pnoType" use="optional"/>
</xsd:complexType>

<xsd:complexType name="USAddressType">
  <xsd:sequence>
    <xsd:choice>
      <xsd:element name="pobox" type="xsd:positiveInteger"/>
      <xsd:sequence>
        <xsd:element name="street" type="xsd:string"/>
        <xsd:element name="apt" 
                     type="xsd:positiveInteger"
                     minOccurs="0"/>
      </xsd:sequence>
    </xsd:choice>
    <xsd:element name="city" type="xsd:string"/>
    <xsd:element name="state" type="xsd:string"/>
    <xsd:element name="zip" type="xsd:positiveInteger"/>
  </xsd:sequence>
</xsd:complexType>

</xsd:schema>
