Hi,
I was going through Roger L. Costello's slides on schemas. While talking about derivation by restriction, he mentions on slide 100:
'If the base type has an element with minOccurs="0", and the subtype wishes to
not have that element, then it can simply leave it out.'
Does it mean that only those elements which have a minOccurs="0" can be omitted in types derived by restriction?
I tried it by creating a pair of xml and xsd files and omitted some elements of the base type at random and the resulting xsd file was okayed by XSV.
My confusion is if any element can be deleted from the base type just by omission from the derived type, then why did Costello put that condition of 'minOccurs="0"' in his statement? Or did I just read too much between the lines?
I'm including the xml and xsd files:
XML file:
<?xml version="1.0"?>
<
test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
<some-elem>
<elem1>this is elem1</elem1>
<elem2>10</elem2>
<elem3>this is elem3</elem3>
</some-elem>
</test>
Schema file:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:complexType name="baseType">
<xs:sequence>
<xs:element name="elem1" type="xs:string"/>
<xs:element name="elem2" type="xs:integer"/>
<xs:element name="elem3" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="derived">
<xs:complexContent>
<xs:restriction base="baseType">
<xs:sequence>
<xs:element name="elem1" type="xs:string"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element name="some-elem" type="baseType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Any help would be greatly appreciated.
Thanks,
Dhananjay