XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] 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@gmail.com>
To: <xml-dev@lists.xml.org>
Sent: Thursday, September 20, 2007 2:41 PM
Subject: [xml-dev] 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@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> 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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS