Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Subclassing types in XSD >Thread Next - Re: Subclassing types in XSD Re: Subclassing types in XSDTo: NULL Date: 9/3/2007 4:21:00 PM
barnum@b... wrote:
> if I have defined a type in a schema, can I subclass it (refine it)
> without rewriting all of the type?
> E.g. I have:
> <xs:element name="Apple" type="xs:string"/>
> <xs:element name="Banana" type="xs:string"/>
> <xs:element name="Citrus" type="xs:string"/>
> <xs:complexType name="MyType">
> <xs:sequence>
> <xs:element ref="Apple"/>
> <xs:element ref="Banana" minOccurs="0" maxOccurs="unbounded"/>
> <xs:element ref="Citrus"/>
> </xs:sequence>
> </xs:complexType>
> And I want a derived type (where the new thing is that there must be
> one or more Banana):
> <xs:complexType name="MyDerivedType">
> <xs:sequence>
> <xs:element ref="Apple"/>
> <xs:element ref="Banana" maxOccurs="unbounded"/>
> <xs:element ref="Citrus"/>
> </xs:sequence>
> </xs:complexType>
> Can I do this without having to write Apple and Citrus in
> MyDerivedType?
You have not used any type derivation at all as with the above
definition for MyDerivedType you have defined a new type, there is no
relation to MyType.
A derivation by restriction looks as follows:
<xs:complexType name="MyDerivedType">
<xs:complexContent>
<xs:restriction base="MyType">
<xs:sequence>
<xs:element ref="Apple"/>
<xs:element ref="Banana" maxOccurs="unbounded"/>
<xs:element ref="Citrus"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
So you need to list the same elements, you can then restrict the occurance.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
