RE: Complex Type extension

Hi Kevin,

That's invalid.  When you are using extension, you can't alter any of
the attributes of the base type.  If you have control over
CheckGroupType, you could have both CheckGroupType and your new type
extend the same base type, one with the attribute optional, and one with
the attribute required.  This would allow the content model and other
attributes to be defined in only one place. It would look like:

<xs:complexType name="BaseCheckGroupType">
  <!content model and attributes (WITHOUT Logic) here-->
</xs:complexType>

<xs:complexType name="CheckGroupType>
  <xs:complexContent>
     <xs:extension base="BaseCheckGroupType">
        <xs:attribute name="Logic" type="xs:string" use="required"/>
     </xs:extension>
  </xs:complexContent>
</xs:complexType

<xs:element name="CheckGroup">
  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="BaseCheckGroupType">
        <xs:attribute name="Logic" type="xs:string" use="optional"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

Hope that helps,

Priscilla

-----------------------------------------------------
Priscilla Walmsley             priscilla@walmsley.com
Author, Definitive XML Schema     (Prentice Hall PTR)
----------------------------------------------------- 

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Kevin Burges
> Sent: Tuesday, April 30, 2002 8:45 AM
> To: xmlschema-dev@w3.org
> Subject: Complex Type extension
> 
> 
> 
> I've got a schema which XMLSpy used to say is valid but in 4.3 says is
> invalid (well, it validated in the Schema view but not in the other
> views). I think XSV validates it, but I don't understand it's output
> half the time so who knows.
> 
> I have a ComplexType which contains an Attribute called Logic which is
> required. I need to re-use this ComplexType elsewhere but make the
> Logic attribute optional.
> 
> Here's my code:
> 
> <xs:element name="CheckGroup">
>         <xs:complexType>
>                 <xs:complexContent>
>                         <xs:extension base="CheckGroupType">
>                                 <xs:attribute name="Logic" 
> type="xs:string" use="optional"/>
>                         </xs:extension>
>                 </xs:complexContent>
>         </xs:complexType>
> </xs:element>
> 
> 
> Is this in fact invalid, and is there another way to acheive this
> other than just making a new ComplexType?
> 
> -- 
> May the flares be with you,
>  Kevin                    xmldude@burieddreams.com
> 
> ++++++++++++ Cool music - http://marshanrock.com
> 
> 

Received on Tuesday, 30 April 2002 09:30:09 UTC