W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2009

RE: Restricting attribute use from optional to required

From: Michael Kay <mike@saxonica.com>
Date: Sun, 16 Aug 2009 12:59:30 +0100
To: 'Jan Přidal' <jan.pridal@gmail.com>, <xmlschema-dev@w3.org>
Message-ID: <8B3183CD8BA240DEB361F5D1B7AA08D7@Sealion>

You can do this, but only in an <xs:restriction>, not in an <xs:extension>

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay  

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Jan Pridal
> Sent: 14 August 2009 13:42
> To: xmlschema-dev@w3.org
> Subject: Restricting attribute use from optional to required
> 
> Hello all,
> my question follows, I am using XML Schema 1.0.
> 
> I have an attributeGroup with an optional attribute. This 
> attributeGroup is used in declaration of complexType. Another 
> complexType is then an extension of that complexType. Please 
> see my sample code below.
> 
> I would like to declare the attribute 'label' as required for 
> the 'derived' complexType. Is there any legal way to do it?
> 
> <xsd:attributeGroup name="attributes">
>     ...
>     <xsd:attribute name="label" type="xsd:string" /> 
> </xsd:attributeGroup>
> 
> <xsd:complexType name="parent">
>     <xsd:complexContent>
>         ...
>         <xsd:attributeGroup ref="attributes"/>
>     </xsd:complexContent>
> </xsd:complexType>
> 
> <xsd:complexType name="derived">
>     <xsd:complexContent>
>         <xsd:extension base="parent">
>             <xsd:sequence>
>                 <xsd:element ref="parameter" minOccurs="0"
> maxOccurs="unbounded"/>
>             </xsd:sequence>
>             <xsd:attribute name="name" type="xsd:string" 
> use="required"/>
>         </xsd:extension>
>     </xsd:complexContent>
> </xsd:complexType>
> 
> Regards,
> Jan Pridal
> 
> 
Received on Sunday, 16 August 2009 12:00:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:14 GMT