All,
In XML Schema, I'd like to create a complexType that contains a sequence of one of several possible simple values. 1. If I wanted to create a complexType that contained only one of several possible simple values, I could do this: <xsd:complexType name="ParameterValue"> <xsd:choice> <xsd:element name="F" type="xsd:float"/> <xsd:element name="I" type="xsd:int"/> <xsd:element name="S" type="xsd:string"/> </xsd:choice> </xsd:complexType> So an instance of ParameterValue would look like this: <aParameterValue><F>1.25</F></aParameterValue> 2. If I want ParameterValue to contain multiple simple values (not all same), I could use an unbounded choice like this: <xsd:complexType name="ParameterValue"> <xsd:choice maxOccurs="unbounded"> <xsd:element name="F" type="xsd:float"/> <xsd:element name="I" type="xsd:int"/> <xsd:element name="S" type="xsd:string"/> </xsd:choice> </xsd:complexType> So an Instance of ParameterValue would look like this: <aParameterValue><F>1.25</F><S>a test string</S></aParameterValue> But there's a problem with that: the order of the simple values is not guaranteed. 3. So I'll try this: <xsd:complexType name="ParameterValue"> <xsd:sequence maxOccurs="unbounded"> <xsd:choice> <xsd:element name="F" type="xsd:float"/> <xsd:element name="I" type="xsd:int"/> <xsd:element name="S" type="xsd:string"/> </xsd:choice> </xsd:sequence> </xsd:complexType> OK, this looks right: ParameterValue contains one or more simple values, in a specified order, and the values may be different simple types. According to other tools like Altova's XMLSpy, alternative 3 is valid. But here's the rub: VW does not appear to correctly build the corresponding Smalltalk class (ParameterValue). You'd think that ParameterValue (the Smalltalk class) would have an instVar that contains an OrderedCollection, and the OrderedCollection would hold Struct instances. (A Struct corresponds to a choice; it behaves much like a Dictionary.) But instead, the instVar is built to directly contain a Struct (i.e. a choice). So I can't put a collection of simple values in a ParameterValue, nor can I guarantee that the order in which I add them to ParameterValue is the order in which they will appear in the corresponding XML. The above is a description of what happens in VW 7.4.1. Can anyone else confirm this behavior? Is there another solution? Does VW 7.6 fix this? Chris _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
> -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On Behalf > Of Chris Winemiller > Sent: Thursday, May 08, 2008 2:17 PM > To: [hidden email] > Subject: [vwnc] XML Schema: How to define an object that accepts a > sequenceof choices > > All, > > In XML Schema, I'd like to create a complexType that contains a sequence > of one of several possible simple values. > > 1. If I wanted to create a complexType that contained only one of several > possible simple values, I could do this: > > <xsd:complexType name="ParameterValue"> > <xsd:choice> > <xsd:element name="F" type="xsd:float"/> > <xsd:element name="I" type="xsd:int"/> > <xsd:element name="S" type="xsd:string"/> > </xsd:choice> > </xsd:complexType> > > So an instance of ParameterValue would look like this: > > <aParameterValue><F>1.25</F></aParameterValue> > > 2. If I want ParameterValue to contain multiple simple values (not all > same), I could use an unbounded choice like this: > > <xsd:complexType name="ParameterValue"> > <xsd:choice maxOccurs="unbounded"> > <xsd:element name="F" type="xsd:float"/> > <xsd:element name="I" type="xsd:int"/> > <xsd:element name="S" type="xsd:string"/> > </xsd:choice> > </xsd:complexType> > > So an Instance of ParameterValue would look like this: > > <aParameterValue><F>1.25</F><S>a test string</S></aParameterValue> > > But there's a problem with that: the order of the simple values is > guaranteed. > > 3. So I'll try this: > > <xsd:complexType name="ParameterValue"> > <xsd:sequence maxOccurs="unbounded"> > <xsd:choice> > <xsd:element name="F" type="xsd:float"/> > <xsd:element name="I" type="xsd:int"/> > <xsd:element name="S" type="xsd:string"/> > </xsd:choice> > </xsd:sequence> > </xsd:complexType> > > OK, this looks right: ParameterValue contains one or more simple > values, in a specified order, > and the values may be different simple types. > > According to other tools like Altova's XMLSpy, alternative 3 is valid. > But here's the rub: VW does not appear to correctly build the > corresponding Smalltalk class (ParameterValue). You'd think that > ParameterValue (the Smalltalk class) would have an instVar that > an OrderedCollection, and the OrderedCollection would hold Struct > instances. (A Struct corresponds to a choice; it behaves much like a > Dictionary.) But instead, the instVar is built to directly contain a > Struct (i.e. a choice). So I can't put a collection of simple values in a > ParameterValue, nor can I guarantee that the order in which I add them to > ParameterValue is the order in which they will appear in the corresponding > XML. > > The above is a description of what happens in VW 7.4.1. > > Can anyone else confirm this behavior? Is there another solution? Does > VW 7.6 fix this? There is no work has been done in 7.6 to support unbounded sequences. Tamara _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Chris Winemiller
All,So, Chris, this does not look like it should behave differently to me. Would you consider the following acceptable? <ParameterValue> <S>hello</S> <F>1.1</F> <I>3</I> <F>1.4</F> <S>something</S> </ParameterValue> I think this is possible given your schema. Each of the simple elements occurs in a valid way w.r.t. its xsd:choice, but there is an unbounded number of these choice groups. According to other tools like Altova's XMLSpy, alternative 3 is valid. But here's the rub: VW does not appear to correctly build the corresponding Smalltalk class (ParameterValue). You'd think that ParameterValue (the Smalltalk class) would have an instVar that contains an OrderedCollection, and the OrderedCollection would hold Struct instances. (A Struct corresponds to a choice; it behaves much like a Dictionary.) But instead, the instVar is built to directly contain a Struct (i.e. a choice). So I can't put a collection of simple values in a ParameterValue, nor can I guarantee that the order in which I add them to ParameterValue is the order in which they will appear in the corresponding XML. _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |