W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2001

Re: conditional schemas

From: Erik Beijnoff <erik@addsystems.com>
Date: Wed, 28 Nov 2001 16:16:53 +0100
To: "'Lieve Laporte'" <lieve.laporte@uz.kuleuven.ac.be>
Cc: <xmlschema-dev@w3.org>
Message-ID: <914A89E9F99D2C4B8E14FB8CC083F9BC739C@addex001.addsystems.com>
>In this case, wouldn't I have to duplicate everything that is inside the
"actions" element? 'Cause that's quite a lot...
>Regards, Lieve

Ok, here goes...

<xs:complexType name="outer">
  <xs:choice>
    <xs:element name="action" type="actionsWithAccess"/>
    <xs:element name="action" type="actionsWithSettings"/>
  </xs:choice>
</xs:complexType>

<xs:complexType name="action">
  <xs:sequence>
    <xs:element name="whatevercontent"/>
    <xs:element name="whatevercontent2"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="actionsWithSettings">
  <xs:complexContent>
    <xs:extension base="action">
      <xs:attribute name="name" use="required" fixed="settings"/>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="actionsWithAccess">
  <xs:complexContent>
    <xs:extension base="action">
      <xs:sequence>
        <xs:element name="tag"/>
      </xs:sequence>
      <xs:attribute name="name" use="required" fixed="access"/>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

First <xs:complexType name="outer"> is the whole that combines the other
parts. It contains a choice between two elements of type actionsWithSettings
and actionsWithAccess. <xs:complexType name="action"> is the base action
type that <xs:element name="actionsWithSettings"> and <xs:element
name="actionsWithAccess"> extends. This way you have a common base for both
elements. Perhaps not the easiest solution, but it works, and can be used as
common framework for this type of problems.

I'd like some expertise input to this solution though, since I've never
tried this it before, and am a bit uncertain about extensions.

Best regards

Erik Beijnoff
Systems development

erik.beijnoff@addsystems.com
erik@beijnoff.com
Received on Wednesday, 28 November 2001 10:20:17 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 16 March 2009 11:13:19 GMT