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

----- Original Message -----
From: "Eric van der Vlist" <vdv@dyomedea.com>
To: "Gary Robertson" <gazinyork@hotmail.com>
Sent: Wednesday, October 10, 2001 5:30 PM
Subject: Re: Illegal use of unique? I need it. Microsoft supports it.
Alternatives?


> Gary Robertson wrote:
>
>
> > It sounds good but I'm having trouble. The trouble is that my objects
> > can have other objects nested with them recursively also (see my schema
> > at the end). I am trying to write a schema for an existing database
system
> > you
> > see and a car (for example) can have wheels, which can have tyres, which
can
> > have inner tubes...etc all of which are objects and thus the nesting.
I'll
> > let you
> > know how I get on with this approach, however.
>
>
> I may have missed something, but it shouldn't be a problem, elements can
> be nested using element references as well as complex type references.

Yes, sorry, the information that I did not convey was that I wanted
inheritance
_and_ identity constraints: I wanted to have both an ObjectType (from which
to
inherit other types/elements) and a global Object element (of type
ObjectType) to
attach my unique construct to (and reference at various points within my
root
element). What would be (almost) ideal would be if you were allowed this:

<xs:element name="Object">
    <xs:complexType name="ObjectType">
        <xs:complexContent>
            <xs:extension base="AbstractMooDElementType">
                <xs:sequence>
                    <xs:element ref="Object" minOccurs="0"
maxOccurs="unbounded"/>
                    <xs:element name="State" type="StateType" minOccurs="0"
maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:unique name="StateNamesUniqueWithinAnObject">
        <xs:selector xpath="State"/>
        <xs:field xpath="@name"/>
    </xs:unique>
</xs:element>

Unfortunately, name="ObjectType" is either not allowed here or ObjectType
is inaccessible elsewhere in the file (depending on whether you listen to
Microsoft or XML Spy). Anyway, I have abandoned inheritance and complex
types in favour of a global element and refs, as you suggested.

Thanks to yourself and Eddie Robertsson for your help on this one.


> >>The downside is that all your object elements must then have the same
> >>name and content model.
> >>
> >>And you've raised yet another difference between using references to
> >>global elements and references to complex types...
> >>
> >>Eric
> >>
> >>
> >>
> >>>
> >>>----- Original Message -----
> >>>From: "Eric van der Vlist" <vdv@dyomedea.com>
> >>>To: "Gary Robertson" <gazinyork@hotmail.com>
> >>>Sent: Wednesday, October 10, 2001 4:33 PM
> >>>Subject: Re: Illegal use of unique? I need it. Microsoft supports it.
> >>>Alternatives?
> >>>
> >>>
> >>>
> >>>
> >>>>Gary Robertson wrote:
> >>>>
> >>>>
> >>>>
> >>>>>Hi and thanks again Eric for your time.
> >>>>>
> >>>>>
> >>>>You're welcome. See my comments below.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>----- Original Message -----
> >>>>>From: "Eric van der Vlist" <vdv@dyomedea.com>
> >>>>>To: "Gary Robertson" <gazinyork@hotmail.com>
> >>>>>Cc: <xmlschema-dev@w3.org>
> >>>>>Sent: Wednesday, October 10, 2001 3:53 PM
> >>>>>Subject: 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>
> >>>>>>
> >>>>>Yes - that's right.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>>>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.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>I don't understand. xs:unique _is_ the direct child of the element
> >>>>>
> > whose
> >
> >>>>>name is State, isn't it? If not where should it be? XML Spy 4.01 put
it
> >>>>>here I think - it certainly isn't objecting anyway. I don't think XML
> >>>>>
> >>>>>
> >>>Spy
> >>>
> >>>
> >>>>>would allow me to put the unique anywhere else in my complex type
> >>>>>definition.
> >>>>>
> >>>>>
> >>>>Oops, sorry. I have been reading your schema too fast and have been
> >>>>mislead by the indentation. You're right, it's just where it needs to
> >>>>
> > be.
> >
> >>>>
> >>>>
> >>>>>>>    <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.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>I feared this after my last attempt at understanding the standard.
> >>>>>
> >>>>>
> >>>>:(
> >>>>
> >>>>
> >>>>>>>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 !
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>It's bad from the software engineering point of view because it
> >>>>>
> > requires
> >
> >>>the
> >>>
> >>>
> >>>>>same code to be repeated many times (making modification very error
> >>>>>prone) i.e. every time I place an element of type=ObjectType into my
> >>>>>schema I must remember to repeat the unique statement(s) that go with
> >>>>>it. This could have been avoided if the schema standard had allowed
> >>>>>constraints within a type definition. The code I showed does actually
> >>>>>work using the Microsoft parser (unless I made a typo cutting it
down)
> >>>>>so it can obviously be implemented, which makes me wonder why
> >>>>>it is illegal in the standard. I include the whole thing at the end
of
> >>>>>
> >>>>>
> >>>this
> >>>
> >>>
> >>>>>email just in case I made a typing mistake last time.
> >>>>>
> >>>>>
> >>>>Yes, one of the objections made to this unique/key/keyref is that it's
a
> >>>>layer on top of the object oriented features of W3C XML Schema which
> >>>>isn't object oriented at all but built on "physical" XPath expressions
> >>>>which are independent of the rest of the design.
> >>>>
> >>>>".." in a selector is clearly illegal which BNF is dramatically
reduced:
> >>>>
> >>>>"2.1 It must conform to the following extended BNF:
> >>>>Selector XPath expressions
> >>>>[1]    Selector    ::=    Path ( '|' Path )*
> >>>>[2]    Path    ::=    ('.//')? Step ( '/' Step )*
> >>>>[3]    Step    ::=    '.' | NameTest
> >>>>[4]    NameTest    ::=    QName | '*' | NCName ':' '*'"
> >>>>
> >>>>Eric
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>>Hope this helps
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>It has - thanks.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>>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
> >
>
>>>>>-----------------------------------------------------------------------
-
> >>>>>
> >>>>>>
> >>>>>>
> >>>>><xs:complexType name="ObjectType">
> >>>>>
> >>>>><xs:complexContent>
> >>>>>
> >>>>><xs:extension base="AbstractMooDElementType">
> >>>>>
> >>>>><xs:sequence>
> >>>>>
> >>>>><xs:element name="Object" type="ObjectType" minOccurs="0"
> >>>>>maxOccurs="unbounded"/>
> >>>>>
> >>>>><xs:element name="Attribute" type="AttributeType" minOccurs="0"
> >>>>>maxOccurs="unbounded">
> >>>>>
> >>>>><xs:unique name="AttributeNamesUniqueWithinAnObject">
> >>>>>
> >>>>><xs:selector xpath="../Attribute"/>
> >>>>>
> >>>>><xs:field xpath="@name"/>
> >>>>>
> >>>>></xs:unique>
> >>>>>
> >>>>></xs:element>
> >>>>>
> >>>>><xs:element name="Service" type="ServiceType" minOccurs="0"
> >>>>>maxOccurs="unbounded">
> >>>>>
> >>>>><xs:unique name="ServiceNamesUniqueWithinAnObject">
> >>>>>
> >>>>><xs:selector xpath="../Service"/>
> >>>>>
> >>>>><xs:field xpath="@name"/>
> >>>>>
> >>>>></xs:unique>
> >>>>>
> >>>>></xs:element>
> >>>>>
> >>>>><xs:element name="State" type="StateType" minOccurs="0"
> >>>>>maxOccurs="unbounded">
> >>>>>
> >>>>><xs:unique name="StateNamesUniqueWithinAnObject">
> >>>>>
> >>>>><xs:selector xpath="../State"/>
> >>>>>
> >>>>><xs:field xpath="@name"/>
> >>>>>
> >>>>></xs:unique>
> >>>>>
> >>>>></xs:element>
> >>>>>
> >>>>><xs:element name="ObjectContextModel" type="ObjectContextModelType"
> >>>>>minOccurs="0"/>
> >>>>>
> >>>>><xs:element name="ObjectStateModel" type="ObjectStateModelType"
> >>>>>minOccurs="0"/>
> >>>>>
> >>>>></xs:sequence>
> >>>>>
> >>>>></xs:extension>
> >>>>>
> >>>>></xs:complexContent>
> >>>>>
> >>>>></xs:complexType>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>--
> >>>>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
>
>>>>------------------------------------------------------------------------
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >>
> >>--
> >>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
> >>------------------------------------------------------------------------
> >>
> >>
> >>
> >
> >
>
>
>
> --
> 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
> ------------------------------------------------------------------------
>



> <xs:element name="Object">
> <xs:complexType>
> <xs:complexContent>
> <xs:extension base="AbstractMooDElementType">
> <xs:sequence>
> <xs:element ref="Object" minOccurs="0" maxOccurs="unbounded"/>
> <xs:element name="Attribute" type="AttributeType" minOccurs="0"
maxOccurs="unbounded"/>
> <xs:element name="Service" type="ServiceType" minOccurs="0"
maxOccurs="unbounded"/>
> <xs:element name="State" type="StateType" minOccurs="0"
maxOccurs="unbounded"/>
> <xs:element name="ObjectContextModel" type="ObjectContextModelType"
minOccurs="0"/>
> <xs:element name="ObjectStateModel" type="ObjectStateModelType"
minOccurs="0"/>
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
> <xs:unique name="ServiceNamesUniqueWithinAnObject">
> <xs:selector xpath="Service"/>
> <xs:field xpath="@name"/>
> </xs:unique>
> <xs:unique name="AttributeNamesUniqueWithinAnObject">
> <xs:selector xpath="Attribute"/>
> <xs:field xpath="@name"/>
> </xs:unique>
> <xs:unique name="StateNamesUniqueWithinAnObject">
> <xs:selector xpath="State"/>
> <xs:field xpath="@name"/>
> </xs:unique>
> </xs:element>
>
>

Received on Friday, 12 October 2001 12:49:56 UTC