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

RE: uniqueness with multiple fields

From: Zafar Abbas <zafara@microsoft.com>
Date: Mon, 13 Oct 2003 10:56:25 -0700
Message-ID: <563BD3496D37BB4B9F4E8F896A58F2B317139A@RED-MSG-50.redmond.corp.microsoft.com>
To: "kajoha" <kajoha@gmx.at>, <xmlschema-dev@w3.org>

This <unique> construct should work for you:

		<xs:unique name="idMustBeUnique">
			<xs:selector xpath=".//Name"/>          
			<xs:field       xpath="Surname"/>
			<xs:field       xpath="Forename"/>
		</xs:unique>

To read more about specifying uniqueness over combinations of values, read http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness



-----Original Message-----
From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] On Behalf Of kajoha
Sent: Monday, October 13, 2003 6:57 AM
To: xmlschema-dev@w3.org
Subject: uniqueness with multiple fields


hi,

i've following xml-file:

=====
<?xml version="1.0" encoding="UTF-8"?>
<Contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\XML\uniqueness.xsd">
	<Name>
		<Surname>Doe</Surname>
		<Forename>John</Forename>
	</Name>
	
	<Name>
		<Surname>Moe</Surname>
		<Forename>John</Forename>
	</Name>
	
	<Name>
		<Surname>Toe</Surname>
		<Forename>John</Forename>
	</Name>
	.
	.
	.
</Contact>
=====

how must i define the unique element within the uniqueness.xsd file to
assure that each Surname/Forename pair is unique within a xml-document?

=====
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="Contact">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Name" maxOccurs="unbounded">
					<xs:complexType>
						<xs:sequence>
						<xs:element name="Surname" type="xs:string"/>
						<xs:element name="Forename" type="xs:string"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
		<xs:unique name="idMustBeUnique">
			<xs:selector xpath=".//Surname"/>          
			<xs:field       xpath="."/>
		</xs:unique>
	</xs:element>
</xs:schema>
=====
above given one only checks against double entries for Surname because of
the given selector statement. i think it have something to do with the
definition of the field elements, but until now i come not up with it.

thanks for your help, johann kandl

-- 
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService

Jetzt kostenlos anmelden unter http://www.gmx.net

+++ GMX - die erste Adresse für Mail, Message, More! +++
Received on Monday, 13 October 2003 13:57:33 GMT

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