RE: uniqueness with multiple fields

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 UTC