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

Can I constrain a sequence of elements to be unique?

From: Paul Morgan <pmorgan@jjillgroup.com>
Date: Wed, 1 Dec 2004 17:44:59 -0500
To: xmlschema-dev@w3.org
Message-ID: <colhhd$kkl$1@sea.gmane.org>

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:element name="SizeCategory" minOccurs="1" maxOccurs="4" >
     <xsd:attribute name="Name" use="required">
       <xsd:restriction base="xsd:string">
        <xsd:enumeration value="Missy" />
        <xsd:enumeration value="Petite" />
        <xsd:enumeration value="Tall" />
        <xsd:enumeration value="Womens" />
  <xsd:attribute name="Number" type="xsd:string" use="required" />

allows for this XML:

<Style Number="51-2301">
 <SizeCategory Name="Tall" />
 <SizeCategory Name="Petite" />
 <SizeCategory Name="Missy" />
 <SizeCategory Name="Womens" />

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" />

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: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:attribute name="Number" type="xsd:string" use="required" />

<xsd:complexType name="sizeCategory" />

which allows for this XML:

<Style Number="51-2301">
 <TallCategory />
 <PetiteCategory />
 <WomensCategory />

but shouldn't allow this XML:

<Style Number="51-2301">

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?


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
Received on Thursday, 2 December 2004 02:56:12 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:07 UTC