RE: deriving restriction types

 >  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