Listing 1 PurchaseOrder.xml
<PurchaseOrder Tax="5.76" Total="75.77">

<ShippingInformation>
<Name>Dillon Larsen</Name>
<Address>
<Street>123 Jones Rd.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77381</Zip>
</Address>
<Method>USPS</Method>
<DeliveryDate>2001-08-12</DeliveryDate>
</ShippingInformation>

<BillingInformation>
<Name>Madi Larsen</Name>
<Address>
<Street>123 Jones Rd.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77381</Zip>
</Address>
<PaymentMethod>Credit Card</PaymentMethod>
<BillingDate>2001-08-09</BillingDate>
</BillingInformation>

<Order SubTotal="70.01" ItemsSold="17">
<Product Name="Baby Swiss" Id="702890" Price="2.89" 
Quantity="1"/>
<Product Name="Hard Salami" Id="302340" Price="2.34" 
Quantity="1"/>
<Product Name="Turkey" Id="905800" Price="5.80" 
Quantity="1"/>
<Product Name="Caesar Salad" Id="991687" Price="2.38" 
Quantity="2"/>
<Product Name="Chicken Strips" Id="133382" Price="2.50" 
Quantity="1"/>
<Product Name="Bread" Id="298678" Price="1.08" 
Quantity="1"/>
<Product Name="Rolls" Id="002399" Price="2.24" 
Quantity="1"/>
<Product Name="Cereal" Id="066510" Price="2.18" 
Quantity="1"/>
<Product Name="Jalapenos" Id="101005" Price="1.97" 
Quantity="1"/>
<Product Name="Tuna" Id="000118" Price="0.92" 
Quantity="3"/>
<Product Name="Mayonnaise" Id="126860" Price="1.98" 
Quantity="1"/>
<Product Name="Top Sirloin" Id="290502" Price="9.97" 
Quantity="2"/>
<Product Name="Soup" Id="001254" Price="1.33" 
Quantity="1"/>
<Product Name="Granola Bar" Id="026460" Price="2.14" 
Quantity="2"/>
<Product Name="Chocolate Milk" Id="024620" Price="1.58" 
Quantity="2"/>
<Product Name="Spaghetti" Id="000265" Price="1.98" 
Quantity="1"/>
<Product Name="Laundry Detergent" Id="148202" 
Price="8.82" Quantity="1"/>
</Order>
</PurchaseOrder>

Listing 2 Excerpt from hypothetical PurchaseOrder schema
<xsd:complexType name="ProductType">
<xsd:attribute name="Name" type="xsd:string"/>
<xsd:attribute name="Id" type="xsd:positiveInteger"/>
<xsd:attribute name="Price">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Quantity" type=
"xsd:positiveInteger"/>
</xsd:complexType>

Listing 3 Simple element declaration
<xsd:element name='PurchaseOrder' type=
'PurchaseOrderType'/>

<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="ShippingInformation" type=
"InfoType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="BillingInformation" type="InfoType" 
minOccurs="1" maxOccurs="1"/>
<xsd:element name="Order" type="OrderType" minOccurs=
"1" maxOccurs="1"/>
</xsd:all>
<xsd:attribute name="Tax">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Total">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>

Listing 4 Complex element
<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="ShippingInformation" type=
"InfoType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="BillingInformation" type="InfoType" 
minOccurs="1" maxOccurs="1"/>
<xsd:element name="Order" type="OrderType" minOccurs=
"1" maxOccurs="1"/>
</xsd:all>
<xsd:attribute name="Tax">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Total">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>

Listing 5 Complete schema for Listing 1 document
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:annotation>
<xsd:documentation>
Purchase Order schema for an online grocery store.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="PurchaseOrder" type=
"PurchaseOrderType"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="ShippingInformation" type=
"InfoType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="BillingInformation" type=
"InfoType" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Order" type="OrderType" minOccurs=
"1" maxOccurs="1"/>
</xsd:all>
<xsd:attribute name="Tax">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Total">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>

<xsd:group name="ShippingInfoGroup">
<xsd:all>
<xsd:element name="DeliveryDate" type="DateType"/>
<xsd:element name="Method" type="DeliveryMethodType"/>
</xsd:all>
</xsd:group>

<xsd:group name="BillingInfoGroup">
<xsd:all>
<xsd:element name="BillingDate" type="DateType"/>
<xsd:element name="PaymentMethod" type=
"PaymentMethodType"/>
</xsd:all>
</xsd:group>

<xsd:complexType name="InfoType">
<xsd:sequence>
<xsd:element name="Name" minOccurs="1" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Address" type="AddressType" minOccurs=
"1" maxOccurs="1"/>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:group ref="BillingInfoGroup"/>
<xsd:group ref="ShippingInfoGroup"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="DateType">
<xsd:restriction base="xsd:date"/>
</xsd:simpleType>

<xsd:simpleType name="DeliveryMethodType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="USPS"/>
<xsd:enumeration value="UPS"/>
<xsd:enumeration value="FedEx"/>
<xsd:enumeration value="DHL"/>
<xsd:enumeration value="Other"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="PaymentMethodType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Check"/>
<xsd:enumeration value="Cash"/>
<xsd:enumeration value="Credit Card"/>
<xsd:enumeration value="Debit Card"/>
<xsd:enumeration value="Other"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="AddressType">
<xsd:all>
<xsd:element name="Street" minOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
<xsd:element name="City" minOccurs="1" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
<xsd:element name="State" type="StateType" minOccurs=
"1" maxOccurs="1"/>
<xsd:element name="Zip" type="ZipType" minOccurs="1"
maxOccurs="1"/>
</xsd:all>
</xsd:complexType>

<xsd:simpleType name="ZipType">
<xsd:restriction base="xsd:string">
<xsd:minLength value="5"/>
<xsd:maxLength value="10"/>
<xsd:pattern value="[0-9]{5}(-[0-9]{4})?"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="StateType">
<xsd:restriction base="xsd:string">
<xsd:length value="2"/>
<xsd:enumeration value="AR"/>
<xsd:enumeration value="LA"/>
<xsd:enumeration value="MS"/>
<xsd:enumeration value="OK"/>
<xsd:enumeration value="TX"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="OrderType">
<xsd:sequence>
<xsd:element name="Product" type="ProductType" minOccurs=
"1" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="SubTotal">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="ItemsSold" type=
"xsd:positiveInteger"/>
</xsd:complexType>

<xsd:complexType name="ProductType">
<xsd:attribute name="Name" type="xsd:string"/>
<xsd:attribute name="Id" type="xsd:positiveInteger"/>
<xsd:attribute name="Price">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Quantity" type=
"xsd:positiveInteger"/>
</xsd:complexType>

</xsd:schema>