W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2004

RE: deriving restriction types

From: Xan Gregg <Xan.Gregg@jmp.com>
Date: Thu, 8 Apr 2004 13:04:57 -0400
Message-ID: <939FBCFFFF9B0C40BF8B53294E2296DB4AFA51@merc20.na.sas.com>
To: "gayathri veerarajan" <gaytri_v@yahoo.co.in>, <xmlschema-dev@w3.org>
 >  I would like to know whether this is a valid restriction
 
<xsd:complexType name="WineGrape">
 <xsd:choice>
  <xsd:element ref="WineGrape" minOccurs="0" maxOccurs="unbounded" /> 
  <xsd:element ref="CabernetFrancGrape" minOccurs="0" maxOccurs="unbounded" /> 
  <xsd:element ref="CabernetSauvignonGrape" minOccurs="0" maxOccurs="unbounded" /> 
  <xsd:element ref="ChardonnayGrape" minOccurs="0" maxOccurs="unbounded" /> 
  <xsd:element ref="CheninBlancGrape" minOccurs="0" maxOccurs="unbounded" /> 
  <xsd:element ref="ZinfandelGrape" minOccurs="0" maxOccurs="unbounded" /> 
  <xsd:element ref="GamayGrape" minOccurs="0" maxOccurs="unbounded" /> 
 </xsd:choice>
</xsd:complexType>
 
> I want to derive a new complex type restricted from wineGrape where I expect the element   
> CabernetFrancGrape to appear at least once.
 
If you want CabernetFrancGrape to appear at least once, then the others can't appear at all,
so the restriction would be:
 
<xsd:complexType name="WineGrape_hasValue_CabernetFrancGrape">
   <xsd:complexContent>
     <xsd:restriction base="vin:WineGrape">
       <xsd:choice >
        <xsd:element ref="CabernetFrancGrape" minOccurs="1" maxOccurs="unbounded" /> 
     </xsd:choice >
  </xsd:restriction>
 </xsd:complexContent>
</xsd:complexType>
 
I'm guessing you originally meant something like
 
<xsd:complexType name="WineGrape">
 <xsd:choice minOccurs="0" maxOccurs="unbounded" >
  <xsd:element ref="WineGrape"  /> 
  <xsd:element ref="CabernetFrancGrape"  /> 
  <xsd:element ref="CabernetSauvignonGrape" /> 
  <xsd:element ref="ChardonnayGrape"  /> 
  <xsd:element ref="CheninBlancGrape"  /> 
  <xsd:element ref="ZinfandelGrape"  /> 
  <xsd:element ref="GamayGrape"  /> 
 </xsd:choice>
</xsd:complexType> 
 
To restrict it to require at least one CabernetFrancGrape, you might try
 
<xsd:complexType name="WineGrape"> 
<xsd:sequence> 

 <xsd:choice minOccurs="0" maxOccurs="unbounded">
  <xsd:element ref="WineGrape"  /> 
  <xsd:element ref="CabernetSauvignonGrape" /> 
  <xsd:element ref="ChardonnayGrape"  /> 
  <xsd:element ref="CheninBlancGrape"  /> 
  <xsd:element ref="ZinfandelGrape"  /> 
  <xsd:element ref="GamayGrape"  /> 
 </xsd:choice> 
 
 <xsd:element ref="CabernetFrancGrape"  />  
 
 <xsd:choice minOccurs="0" maxOccurs="unbounded" >
  <xsd:element ref="WineGrape"  /> 
  <xsd:element ref="CabernetFrancGrape"  /> 
  <xsd:element ref="CabernetSauvignonGrape" /> 
  <xsd:element ref="ChardonnayGrape"  /> 
  <xsd:element ref="CheninBlancGrape"  /> 
  <xsd:element ref="ZinfandelGrape"  /> 
  <xsd:element ref="GamayGrape"  /> 
 </xsd:choice> 
 
</xsd:sequence> 
</xsd:complexType> 
 
But I don't know how that matches up with the explicit restriction rules, which some processors enforce.  I think the given restriction does obey the general restriction rule that the derived must validate a subset of the base.
 
xan 
Received on Thursday, 8 April 2004 13:05:24 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:15:11 UTC