I have a more or less simple task to build a XSD schema of but I'm not sure if my idea here is right. Especially for the element comment
.
Customers can make purchase orders. A purchase order includes at least one order position (product name, quantity, and price are obligatory; comment and shipping date are optional).
A purchase order has a date (order date) and an optional comment. Customers can specify different addresses (billing and shipping). Only the shipping address is required.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<xs:element name="purchase-order">
<xs:element name="order-position" type="order-position-type" minOccurs="1">
<xs:complexType name="order-position-type">
<xs:sequence>
<xs:element name="product-name" type="xs:string"></xs:element>
<xs:element name="quantity" type="xs:integer"></xs:element>
<xs:element name="price" type="xs:decimal"></xs:element>
<xs:element name="comment" type="xs:string" minOccurs="0" maxOccurs="2"></xs:element>
<xs:element name="shipping-date" type="xs:date" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="order-date" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="billing-address" type="xs:string"></xs:element>
<xs:element name="shipping-address" type="xs:string" minOccurs="1"></xs:element>
</xs:element>
</xs:schema>
So does the same element, here comment
, appear multiple times? Now I have min and maxOccurs for comment
but in the sequence so it's probably wrong.
Where else are errors you maybe see? Or can I make it even easier? The point at least one order position
let me create an element before the complexType to tell that the minOccurs value is 1.