- From: Eddie Robertsson <eddie@allette.com.au>
- Date: Thu, 11 Oct 2001 09:59:14 +1000
- 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"/> </xs:unique> 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:complexType> <xs:complexContent> <xs:extension base="AbstractElementType"> <xs:sequence> <xs:element name="State" type="StateType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:unique name="singleStatePerObject"> <xs:selector xpath="State"/> <xs:field xpath="@name"/> </xs:unique> </xs:element> 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". Cheers, /Eddie
Received on Wednesday, 10 October 2001 19:52:45 UTC