I need to specify an XML fragment like this:
<address type="work">...</address>
<address type="home">...</address>
The work
address is required, but the home
address is optional. How can I achieve that restriction in XML Schema?
This is my address
complexType:
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="street" type="xs:string"></xs:element>
<xs:element name="postalCode" type="PostalCodeType"></xs:element>
<xs:element name="town" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="work" />
<xs:enumeration value="home" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
I have listed the address
elements like this:
<xs:element name="address" type="AddressType"></xs:element>
<xs:element name="address" type="AddressType" minOccurs="0"></xs:element>
So, how do I specify that the first one be specifically a type="work"
address, and the other one a type="home"
address?