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

[The moderator's apologies - this should have been
forwarded to the list some time ago.]

Forwarded message 1

  • From: Bernhard Bodenstorfer <bodenstorfer@yahoo.co.uk>
  • Date: Wed, 17 Dec 2003 08:56:31 -0500 (EST)
  • Subject: [Moderator Action] Unique constraint on complexType
  • To: www-xml-schema-comments@w3.org
  • Cc: bbodi@web.de
  • Message-ID: <20031217135623.22785.qmail@web25107.mail.ukl.yahoo.com>
XML Schema 1.0 provides uniqueness (and key)
constraints only as direct child of the "element"
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
relevance?

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"
minOccurs="0">
    <xs:unique name="SenderNameLanguageUniqueness">
        <xs:selector xpath="name"/>
        <xs:field xpath="@xml:lang"/>
    </xs:unique>
</xs:element>

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

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

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

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