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

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 UTC