Friends,
I'm trying out the concepts given by Roger Costello (xml-schemas2.ppt p.35) about replacing the baseType content with derivedTypes, in the elements defined to be of baseType. If i understand it correctly, he says that
<xsd:complexType name="baseType" block="extension">
will not allow the derived type content to be substituted for the baseType elements.
I'm trying out this concept using an example given below -
I basically have a baseType, a derivedType, an attributeGroup (which is not relevant to this discussion), two global elements "base and jaya" and another global element "test" referring to the global "base" element.
================================================
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.today.org"
targetNamespace="http://www.today.org"
elementFormDefault="qualified">
<xsd:element name="derived" type="xsd:string"/>
<xsd:attribute name="globalAttr" type="xsd:string" use="optional"/>
<!-- Defining a baseType -->
<xsd:complexType name="baseType" block="extension">
<xsd:sequence>
<xsd:element name="base_element1" type="xsd:string"/>
<xsd:element name="base_element2" type="xsd:string"/>
</xsd:sequence>
<xsd:attributeGroup ref="baseAttrs"/>
</xsd:complexType>
<!-- This derivedType adds (element,attribute) to baseType -->
<xsd:complexType name="derivedType">
<xsd:complexContent>
<xsd:extension base="baseType">
<xsd:sequence>
<xsd:element ref="derived" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="derived" type="xsd:integer" use="optional"/>
<xsd:attribute ref="globalAttr"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!-- Defining an attribute group -->
<xsd:attributeGroup name="baseAttrs">
<xsd:attribute name="baseEnumAttr" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="enum1"/>
<xsd:enumeration value="enum2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="baseOptionalAttr" type="xsd:string"
use="optional" default="optional"/>
<xsd:attribute name="baseBoolAttr" type="xsd:boolean" fixed="false"/>
</xsd:attributeGroup>
<!-- Defining elements for substitutionGroups -->
<!-- "base" is the head element -->
<!-- xsd:element name="base" type="baseType" block="substitution"/ -->
<!-- GLOBAL elements in this schema -->
<xsd:element name="base" type="baseType"/>
<xsd:element name="jaya" substitutionGroup="base" type="derivedType"/>
<xsd:element name="test">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="base"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
=================================================
<?xml version="1.0"?>
<
test xmlns="http://www.today.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.today.org
today.xsd">
<base xsi:type="derivedType">
<base_element1/>
<base_element2/>
<!-- derived/ -->
</base>
</test>
=================================================
I'm validating this stuff using Costello's xsv validator and it validates without any problem to my surprise.
My contention here is the definition -
<xsd:complexType name="baseType" block="extension">
should not make the following thing possible, i.e., trying to have a derived content for the baseType object -
<base xsi:type="derivedType">
Please rectify me for any misinterpretation of the stuff. I'm a little confused if i'm missing something here.
Thanks.