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

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

From: Eric van der Vlist <vdv@dyomedea.com>
Date: Wed, 10 Oct 2001 16:53:42 +0200
Message-ID: <3BC460F6.8090707@dyomedea.com>
To: Gary Robertson <gazinyork@hotmail.com>
Cc: xmlschema-dev@w3.org
Hi,

Gary Robertson wrote:

> I want to have a type "Object" that contains multiple "State" elements.
> I want the state names to be unique within each object instance but
> not globally. This is an example of a very common real world
> requirement. 


Which means, if I get it right:

<root>
  <object>
    <State name="foo"/>
    <State name="bar"/>
  </object>
  <object>
    <State name="foo"/>
  </object>
</root>

> Praise to Microsoft's MSXML4 beta 2 for letting me
> achieve my aims like so:
> 
> <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 !

Hope this helps

Eric


> 
> --
> Gaz
> 

-- 
Rendez-vous  Paris pour une visite guidee de la nebuleuse XML.
                                           http://dyomedea.com/formation/
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
http://xsltunit.org      http://4xt.org           http://examplotron.org
------------------------------------------------------------------------
Received on Wednesday, 10 October 2001 10:53:20 GMT

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