W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > January to March 2004

[Fwd: [Moderator Action] Unique constraint on complexType]

From: C. M. Sperberg-McQueen <cmsmcq@acm.org>
Date: 26 Jan 2004 17:15:04 -0700
To: W3C XML Schema Comments list <www-xml-schema-comments@w3.org>
Message-Id: <1075162504.2638.31.camel@localhost>
[The moderator's apologies - this should have been
forwarded to the list some time ago.]

attached mail follows:

XML Schema 1.0 provides uniqueness (and key)
constraints only as direct child of the "element"

Why can such constraints not be put into the
"complexType" so that they can be shared between
elements of the same type? What are reasons for this
Schema 1.0 design decision? For instance, I could
imagine problems in some rare (close to insane?) cases
of type extension, when elements are added with the
same name as that upon which there is a uniqueness
constraint. But is there anything of higher practical

The example for illustration is as follows:

I have two elements "Sender" and "Receiver" with equal
type "PartyType".

PartyType provides a multi-lingual name. Therefore, it
can carry a list of "name" elements, each of which
carries an attribute "xml:lang". Within the PartyType,
the values for this attribute "xml:lang" should be
different among all "name" elements.

Unfortunately, XML Schema 1.0 foresees the uniqueness
constraint with the element definition rather than the
complex type definition. Therefore, I have to
duplicate the uniqueness constraint like so:

<xs:element name="Sender" type="PartyType"
    <xs:unique name="SenderNameLanguageUniqueness">
        <xs:selector xpath="name"/>
        <xs:field xpath="@xml:lang"/>

<xs:element name="Receiver" type="PartyType"
    <xs:unique name="ReceiverNameLanguageUniqueness">
        <xs:selector xpath="name"/>
        <xs:field xpath="@xml:lang"/>

<xs:complexType name="PartyType">
        <xs:element name="name" type="textType"
minOccurs="0" maxOccurs="unbounded"/>

<xs:complexType name="textType">
        <xs:extension base="xs:string">
            <xs:attribute ref="xml:lang"

This means that the PartyType loses some semantics.

A second (almost unrelated) question that I have in
mind would be why unique constraints can only use
names of type "NCName". Why not use qualified names to
avoid collisions?

Thank you for any enlightening thoughts,

Bernhard Bodenstorfer

BT Yahoo! Broadband - Save 80 when you order online today. Hurry! Offer ends 21st December 2003. The way the internet was meant to be. http://uk.rd.yahoo.com/evt=21064/*http://btyahoo.yahoo.co.uk
Received on Monday, 26 January 2004 19:16:54 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:09:01 UTC