Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Restricting attribute use from optional to required

From: =?ISO-8859-2?Q?Jan_P=F8idal?= <jan.pridal@-----.--->
To: xmlschema-dev@--.---
Date: 8/17/2009 1:14:00 PM
I feared it was so :-)

But it is then more than a little bit awkward - as I have to add a new
complexType that restricts the complexType 'parent' and then within it
I have to repeat all the stuff declared the 'parent' and its parent
types (by extension) etc., and eventually I have to use the new
complexType as a base of 'derived' complextType. Also I do not like
the section in the new complexType declaration where I have to list
all attributes of the attributeGroup one by one.

<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="parentWithRequiredLabelAttribute">
   <xsd:complexContent>
       <xsd:restriction base="parent">
           <xsd:sequence>
               ... list all elements of 'parent' type etc.
           </xsd:sequence>
           ...
           <xsd:attribute name="label" type="xsd:string" use="required"/>
           ...
           ... and list all remaining attributes from attributeGroup
called ''attributes"
           ...
       </xsd:restriction>
   </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="derived">
  <xsd:complexContent>
      <xsd:extension base="parentWithRequiredLabelAttribute">
          <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>

Or am I missing something and it could be done better?

Thank you for all your help,
-Jan Pridal

2009/8/16 Michael Kay <mike@s...>:
>
> 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@w...
>> [mailto:xmlschema-dev-request@w...] On Behalf Of Jan Pridal
>> Sent: 14 August 2009 13:42
>> To: xmlschema-dev@w...
>> 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
>>
>>
>
>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent