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

Re: Illegal use of unique? I need it. Microsoft supports it. Alternatives?

From: Eddie Robertsson <eddie@allette.com.au>
Date: Thu, 11 Oct 2001 09:59:14 +1000
Message-ID: <3BC4E0D2.CA062678@allette.com.au>
To: Eric van der Vlist <vdv@dyomedea.com>
CC: Gary Robertson <gazinyork@hotmail.com>, xmlschema-dev@w3.org
> > <xs:complexType name="ObjectType">
> >   <xs:complexContent>
> >   <xs:extension base="AbstractElementType">
> >     <xs:sequence>
> >       <xs:element name="State" type="StateType" minOccurs="0"
> > maxOccurs="unbounded">
> This is invalid! "xs:unique" should come after xs:sequence as a direct
> child of xs:element.
> >       <xs:unique name="StateNamesUniqueWithinAnObject">
> >       <xs:selector xpath="../State"/>
> >       <xs:field xpath="@name"/>
> >       </xs:unique>
> >       </xs:element>
> >     </xs:sequence>
> >   </xs:extension>
> >   </xs:complexContent>
> > </xs:complexType>
> >
> > However, note use of parent node syntax (..) in the selector xpath.
> > Is this illegal?
> Yes.
> > If so, how do I acheive my aim legally?
> By defining the xs:unique in the definition of your object element:
> <xs:element name="object">
>    .../...
>    <xs:unique name="singleStatePerObject">
>      <xs:selector xpath="State"/>
>      <xs:field xpath="@name"/>
>    </xs:unique>
> </xs:element>
> > I intend to
> > declare object instances at multiple points and levels in my schema
> > and it would be extremely onerous and poor software engineering
> > practice to have to attach a unique to every instance.
> I am not sure I understand what you mean here, but -good or bad software
> engineering practice- it's the way it needs to be defined by W3C XML
> Schema !

I think what Gary means is that the complexType "ObjectType" will be reused
as the type of many elements in the schema. This would mean that he would
have to add:

   <xs:unique name="singleStatePerObject">
     <xs:selector xpath="State"/>
     <xs:field xpath="@name"/>

to every element that uses the ObjectType which can be a bit tedious.
Unfortunately, like Eric said, this is the way it needs to be defined and
there's not much we can do about it.
The only solution I can think of (which may not work for you) is to instead
of defining a complexType "ObjectType" you declare a global element "Object"
like this:

<xs:element name="Object"
      <xs:extension base="AbstractElementType">
          <xs:element name="State" type="StateType" minOccurs="0"
  <xs:unique name="singleStatePerObject">
    <xs:selector xpath="State"/>
    <xs:field xpath="@name"/>

And then reference this global element at multiple places in your schema. The
drawback of course is that these elements will always be named "Object".

Received on Wednesday, 10 October 2001 19:52:45 GMT

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