Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Can I constrain a sequence of elements to be unique?

From: "Michael Kay" <mike@--------.--->
To: "'Paul Morgan'" <pmorgan@----------.--->, <xmlschema-dev@--.--->
Date: 12/2/2004 9:08:00 AM
Under the Style element declaration, add

<xsd:unique name="u">
 <xsd:selector xpath="SizeCategory"/>
 <xsd:field xpath="@Name"/>
</xsd:unique>

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

> -----Original Message-----
> From: xmlschema-dev-request@w... 
> [mailto:xmlschema-dev-request@w...] On Behalf Of Paul Morgan
> Sent: 01 December 2004 22:45
> To: xmlschema-dev@w...
> Subject: Can I constrain a sequence of elements to be unique?
> 
> 
> Trying to create a schema that will allow a list of four 
> elements under a
> parent element.  At least one of the elements must occur.  
> Each of the four
> elements should be unique either as different element 
> definitions or with an
> element definition with an enumerated attribute.  This schema frament:
> 
> <xsd:element name="Style">
>  <xsd:complexType>
>   <xsd:sequence>
>    <xsd:element name="SizeCategory" minOccurs="1" maxOccurs="4" >
>     <xsd:complexType>
>      <xsd:attribute name="Name" use="required">
>       <xsd:simpleType>
>        <xsd:restriction base="xsd:string">
>         <xsd:enumeration value="Missy" />
>         <xsd:enumeration value="Petite" />
>         <xsd:enumeration value="Tall" />
>         <xsd:enumeration value="Womens" />
>        </xsd:restriction>
>       </xsd:simpleType>
>      </xsd:attribute>
>     </xsd:complexType>
>    </xsd:element>
>   </xsd:sequence>
>   <xsd:attribute name="Number" type="xsd:string" use="required" />
>  </xsd:complexType>
> </xsd:element>
> 
> allows for this XML:
> 
> <Style Number="51-2301">
>  <SizeCategory Name="Tall" />
>  <SizeCategory Name="Petite" />
>  <SizeCategory Name="Missy" />
>  <SizeCategory Name="Womens" />
> </Style>
> 
> but I want to modify that schema so that it does not allow this XML:
> 
> <Style Number="51-2301">
>  <SizeCategory Name="Missy" />
>  <SizeCategory Name="Missy" />
> </Style>
> 
> Is there some sort of constraint that can be placed on the 
> size categories
> to make the Name attribute unique under Style?
> 
> As an alternative I tried a different approach with this 
> schema fragment:
> 
> <xsd:element name="Style">
>   <xsd:complexType>
>    <xsd:all>
>     <xsd:element name="MissyCategory" type="sizeCategory" 
> minOccurs="0" />
>     <xsd:element name="PetiteCategory" type="sizeCategory" 
> minOccurs="0" />
>     <xsd:element name="TallCategory" type="sizeCategory" 
> minOccurs="0" />
>     <xsd:element name="WomensCategory" type="sizeCategory" 
> minOccurs="0" />
>     </xsd:all>
>    <xsd:attribute name="Number" type="xsd:string" use="required" />
>   </xsd:complexType>
>  </xsd:element>
> 
> <xsd:complexType name="sizeCategory" />
> 
> which allows for this XML:
> 
> <Style Number="51-2301">
>  <TallCategory />
>  <PetiteCategory />
>  <WomensCategory />
>  </Style>
> 
> but shouldn't allow this XML:
> 
> <Style Number="51-2301">
> </Style>
> 
> On this version of the Schema if  I add minOccurs="1" on the 
> all element
> would that force at least one sizeCategory element to occur?
> 
> Thanks,
> Paul
> 
> -- 
> Paul Morgan
> Senior Programmer Analyst - Retail
> J. Jill Group
> 100 Birch Pond Drive, PO Box 2009
> Tilton, NH 03276-2009
> Phone: (603) 266-2117
> Fax:   (603) 266-2333
> 
> 
> 
> 
> 
> 


From Simon.Cox@c... Thu Dec 02 10:37:31 2004
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.34)
	id 1CZoL5-0000y5-Bk
	f


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