[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Type inheritance in XML Schema

  • From: "Pete Cordell" <petexmldev@t...>
  • To: "Mukul Gandhi" <gandhi.mukul@g...>, <xml-dev@l...>
  • Date: Thu, 20 Sep 2007 16:58:19 +0100

Re:  Type inheritance in XML Schema
As you've discovered, schema does not allow you to use xs:extension on 
xs:all.  This may change in XSD 1.1, but is something we have to live with 
for the time being.

The easiest thing to do is change your xs:all statements to xs:sequence.  As 
you've noted, this would require the order to be fixed, but it's worth 
considering whether you really need the order to be variable.

Another approach that would work in this case would be to use attributes to 
store the data.  In this case the order would not matter, and the semantics 
of what is allowed in terms of occurrences is very much xs:all like.

Another observation is that, if you want your OBJECTS element to be more OO 
polymorphic like, the you could define it something like:

    <xs:element name="OBJECTS">
      <xs:complexType>
          <xs:sequence>
            <xs:element name="object" type="shape" maxOccurs="unbounded"/>
          </xs:sequence>
      </xs:complexType>
    </xs:element>

XML instances of that will look something like:

<OBJECTS>
    <object xsi:type='circle'...>...</object>
    <object xsi:type='rectangle'...>...</object>
</OBJECT>
etc.

HTH,

Pete.
--
=============================================
Pete Cordell
Codalogic
for XML Schema to C++ data binding visit
 http://www.codalogic.com/lmx/
=============================================

----- Original Message ----- 
From: "Mukul Gandhi" <gandhi.mukul@g...>
To: <xml-dev@l...>
Sent: Thursday, September 20, 2007 2:41 PM
Subject:  Type inheritance in XML Schema


> Hi all,
>   I want to use the concept of type inheritance in W3C XML Schema. I
> am trying to write a small Schema for the same. Below is my attempt.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="unqualified" attributeFormDefault="unqualified">
>
>    <xs:complexType name="shape">
>      <xs:all>
>        <xs:element name="id" type="xs:string" />
>        <xs:element name="attr2" type="xs:string" />
>      </xs:all>
>    </xs:complexType>
>
>    <xs:complexType name="circle">
>      <xs:complexContent>
>         <xs:extension base="shape">
>            <xs:all>
>               <xs:element name="radius" type="xs:float" />
>            </xs:all>
>         </xs:extension>
>      </xs:complexContent>
>    </xs:complexType>
>
>    <xs:complexType name="rectangle">
>      <xs:complexContent>
>         <xs:extension base="shape">
>            <xs:all>
>               <xs:element name="side1" type="xs:float" />
>               <xs:element name="side2" type="xs:float" />
>               <xs:element name="side3" type="xs:float" />
>               <xs:element name="side4" type="xs:float" />
>             </xs:all>
>          </xs:extension>
>      </xs:complexContent>
>    </xs:complexType>
>
>    <xs:element name="OBJECTS">
>      <xs:complexType>
>          <xs:all>
>            <xs:element name="A" type="circle"/>
>             <xs:element name="B" type="rectangle"/>
>          </xs:all>
>      </xs:complexType>
>    </xs:element>
> </xs:schema>
>
> I am creating a base type called "shape". The subtypes "circle" and
> "rectangle" derive from this base type. I want to use something like
> xs:all, because I want to keep the elements unordered.
>
> But the above XML Schema is wrong, and the validator complains about 
> xs:all.
>
> My questions are..
> 1) What will be the right syntax for type inheritance for the requirement 
> above?
> 2) Will trying to map the OO inheritance concepts to XML Schema be the
> right design approach?
>
>
> -- 
> Regards,
> Mukul Gandhi
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@l...
> subscribe: xml-dev-subscribe@l...
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
> 




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.