[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: XML Schemas: Best Practices
- From: Eddie Robertsson <eddie@allette.com.au>
- To: "Roger L. Costello" <costello@mitre.org>
- Date: Mon, 08 Jan 2001 17:20:52 +1100
> PublicationType - the base type:
>
> <complexType name="PublicationType">
> <sequence>
> <element name="Title" type="string"/>
> <element name="Author" type="string" maxOccurs="unbounded"/>
> <element name="Date" type="year"/>
> </sequence>
> </complexType>
>
> BookType - extends PublicationType by adding two new elements, ISBN
> and Publisher:
>
> <complexType name="BookType">
> <complexContent>
> <extension base="c:PublicationType" >
> <sequence>
> <element name="ISBN" type="string"/>
> <element name="Publisher" type="string"/>
> </sequence>
> </extension>
> </complexContent>
> </complexType>
>
> MagazineType - restricts PublicationType by dropping the Author
> element:
>
> <complexType name="MagazineType">
> <complexContent>
> <restriction base="c:PublicationType">
> <sequence>
> <element name="Title" type="string"/>
> <element name="Author" type="string"
> minOccurs="0" maxOccurs="0"/>
> <element name="Date" type="year"/>
> </sequence>
> </restriction>
> </complexContent>
> </complexType>
>
> - Oftentimes the variable content section will contain elements that
> are conceptually related but structurally vastly different. The base
> type (the abstract element's type) should contain items common to all
> the variable content elements. To allow for elements that may be
> very dissimilar the base type would need to have very little
> structure. This defeats the purpose of inheritance.
>
> Question:
>
> - In the second disadvantage above I state: "This defeats the purpose
> of inheritance." This seems like a very weak statement. Can you
> provide a stronger statement telling why it is bad that the base
> type has little structure?
I agree with Roger here. Sometimes the base type will have very little
structure but that doesn't mean you can't use extension if that suit your
purpose. I think it's better to have a small base type instead of having to
use the restriction functionality but maybe that's just me not being used to
derivation by restriction. I'm still very new to XSD and I haven't made up
my mind about restriction yet.
For example, in the above example I would much rather see that the Author
element is removed from the base type and then added in the BookType.
/Eddie