A sample test done with sample XSD and XML snippet available in spec using the eclipse XSD/XML validation feature:
- Restricting derivation of types using final
<<ipo.xsd>>
<schema targetNamespace="http://www.example.com/IPO" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ipo="http://www.example.com/IPO">
<complexType name="Address" block="extension">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" />
<element name="city" type="string" />
</sequence>
</complexType>
<complexType name="USAddress">
<complexContent>
<extension base="ipo:Address">
<sequence>
<element name="state" type="ipo:USState" />
<element name="zip" type="positiveInteger" />
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="UKAddress">
<complexContent>
<extension base="ipo:Address">
<sequence>
<element name="postcode" type="ipo:UKPostcode" />
</sequence>
<attribute name="exportCode" type="positiveInteger" fixed="1" />
</extension>
</complexContent>
</complexType>
<!-- other Address derivations for more countries -->
<simpleType name="USState">
<restriction base="string">
<enumeration value="AK" />
<enumeration value="AL" />
<enumeration value="AR" />
<!-- and so on ... -->
</restriction>
</simpleType>
<!-- simple type definition for UKPostcode -->
<simpleType name="UKPostcode">
<restriction base="string">
<enumeration value="PO16" />
<enumeration value="G41" />
<enumeration value="WC1A" />
<!-- and so on ... -->
</restriction>
</simpleType>
....
....
Screenshot of ipo.xsd validation errors
- Restricting which derivation can be used in instance documents using block
<<ipo.xsd>>
<schema targetNamespace="http://www.example.com/IPO" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ipo="http://www.example.com/IPO">
<complexType name="Address" block="extension">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
<complexType name="USAddress">
<complexContent>
<extension base="ipo:Address">
<sequence>
<element name="state" type="ipo:USState"/>
<element name="zip" type="positiveInteger"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="UKAddress">
<complexContent>
<extension base="ipo:Address">
<sequence>
<element name="postcode" type="ipo:UKPostcode"/>
</sequence>
<attribute name="exportCode" type="positiveInteger" fixed="1"/>
</extension>
</complexContent>
</complexType>
.....
.....
</schema>
<<ipo.xml>>
<?xml version="1.0"?>
<ipo:purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ipo="http://www.example.com/IPO"
orderDate="1999-12-01"
xsi:schemaLocation="http://www.example.com/IPO ipo.xsd">
<shipTo xsi:type="ipo:UKAddress" exportCode="1">
<name>Helen Zoe</name>
<street>47 Eden Street</street>
<city>Cambridge</city>
<postcode>WC1A</postcode>
</shipTo>
<billTo xsi:type="ipo:USAddress">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>AL</state>
<zip>95819</zip>
</billTo>
<items>
<item partNum="833-AA">
<productName>Lapis necklace</productName>
<quantity>1</quantity>
<USPrice>99.95</USPrice>
<ipo:comment>Want this for the holidays!</ipo:comment>
<shipDate>1999-12-05</shipDate>
</item>
</items>
</ipo:purchaseOrder>
Screenshot of ipo.xml validation errors
Note that ipo.xsd validation shows no error for the 2nd case (using block="extension").