[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
XSD complex types can be derived by restriction or extension. Complex type restriction defines the restricted type to be a more restricted version of the base type. Complex type extension make it possible to extend the base type by either adding attributes or contents (only by appending new content to the content model). Complex type derivation allows XSD to express type hierarchies of complex types, which can be aligned with more or less specialized code for processing instances of these types.
US
use="optional"
use="required"
or use="prohibited"
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string" minOccurs="0"/> <xs:choice> <xs:element name="state" type="xs:string"/> <xs:element name="canton" type="xs:string"/> </xs:choice> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> <xs:attribute name="territory" type="xs:string" use="optional"/> </xs:complexType> <xs:complexType name="USaddressType"> <xs:complexContent> <xs:restriction base="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:choice> <xs:element name="state" type="xs:string"/> </xs:choice> <xs:element name="zip" type="zipType"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> <xs:attribute name="territory" type="xs:string" use="prohibited"/> </xs:restriction> </xs:complexContent> </xs:complexType> <xs:simpleType name="zipType"> <xs:restriction base="xs:decimal"> <xs:totalDigits value="5"/> </xs:restriction> </xs:simpleType> </xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="addressType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string" minOccurs="0"/> <xs:choice> <xs:element name="state" type="xs:string"/> <xs:element name="canton" type="xs:string"/> </xs:choice> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> <xs:attribute name="country" type="xs:NMTOKEN"/> <xs:attribute name="territory" type="xs:string" use="optional"/> </xs:complexType> <xs:complexType name="businessAddressType"> <xs:complexContent> <xs:extension base="addressType"> <xs:sequence> <xs:element name="company" type="xs:string"/> <xs:element name="position" type="xs:string" minOccurs="0"/> </xs:sequence> <xs:attribute name="relationship" type="xs:NMTOKEN"/> </xs:extension> </xs:complexContent> </xs:complexType> </xs:schema>
handling extensionscan be as simple as skipping them