Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Subclassing types in XSD

From: barnum@--------.--
To: NULL
Date: 9/3/2007 7:39:00 AM

On 3 Sep, 16:21, Martin Honnen <mahotr...@yahoo.de> wrote:
> bar...@bluezone.no 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/- Skjul sitert tekst -
>
> - Vis sitert tekst -

Thanks, I see. But as I cannot avoid listing the same elements as in
the "superclass", there is not a lot to gain in using xs:restriction.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent