W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2003

The use of unique

From: Xuejun Li (SH/RDC) <xuejun.li@ericsson.com>
Date: Thu, 28 Aug 2003 16:38:06 +0800
Message-ID: <55CF389EF371D511B67C00508BADDC2F02892AA4@ecnshnt514.itc.ericsson.se>
To: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>

Hi
I met some strange problem when I tried to use unique.
I made such a schema:
<xs:schema targetNamespace="http://schemas.ericsson.com/snf/cpm1.0/" xmlns:cpm="http://schemas.ericsson.com/snf/cpm1.0/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="CreateAdministratorAttributes">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="uid" type="xs:string"/>
				<xs:element name="cn" type="xs:string" maxOccurs="unbounded"/>
				<xs:element name="sn" type="xs:string" maxOccurs="unbounded"/>
				<xs:element name="userPassword" type="xs:string"/>
				<xs:element name="roles" minOccurs="0" maxOccurs="2">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:enumeration value="user admin"/>
							<xs:enumeration value="service admin"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
			</xs:sequence>
			<xs:attribute name="uid" type="xs:string" use="required"/>
		</xs:complexType>
		<xs:unique name="RolesUniqueCreate">
			<xs:selector xpath="."/>
			<xs:field xpath="cpm:roles"/>
		</xs:unique>
	</xs:element>
</xs:schema>
What I intend to limit with unique is there should not be two roles that are equal, but there can be maximum 2 different roles. But when I tried to validate the following XML, I got an error saying "The fields XPath selector of the unique identity constraint 'RolesUniqueCreate' must evaluate to exactly 0 or 1 nodes" (from XMLSpy) or "Field matches more than one value within the scope of its selector; fields must match unique values" (from Xerces).
<CreateAdministratorAttributes xmlns="http://schemas.ericsson.com/snf/cpm1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.ericsson.com/snf/cpm1.0/ UniqueTest.xsd" uid="String">
	<uid>String</uid>
	<cn>String</cn>
	<sn>String</sn>
	<userPassword>String</userPassword>
	<roles>user admin</roles>
	<roles>service admin</roles>
</CreateAdministratorAttributes>
Am I using unique the wrong way? How do I achieve the functionality I want?
Thanks
//Li Xuejun
Received on Thursday, 28 August 2003 04:35:26 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:39 GMT