Jump to content
Guest chapel21

Sometimes a simpleType, sometimes a complexType

Recommended Posts

Guest chapel21

I am trying to write the schema for an xml format that has already been written (and i cannot change!).There are three possible forms/definitions of a single element. I have written my requirement such that 2 of the three possible cases are accounted for and work. However, one case eludes me.Here is some sample xml:case 1:<VALUE>stringtext</VALUE>case 2:<VALUE> <VALID_VALUES> <SELECTED>boolean</SELECTED> .. more elements </VALID_VALUES></VALUE>case 3:<VALUE> <FORMULA>stringtext</FORMULA></VALUE>I have handled for cases 2 and 3, and it works fine. But to do this I had to skip the first case.The problem is obvious, do you define the ValueType as a simpleType or complexType. My answer is it must be a complexType because it contains child elements. However, as in case 1, it can be a simpleType. You can't write a choice option for choosing between the types. So how does one tackle this? My solution, which skips case 1 was:<xsd:complexType name="ParameterType"> <!-- elements --> <xsd:sequence> <xsd:element name="VALUE" type="ValueType" minOccurs="1" maxOccurs="1" /> </xsd:sequence></xsd:complexType><xsd:complexType name="ValueType" mixed="true"> <xsd:choice minOccurs="0" maxOccurs="1"> <xsd:element name="FORMULA" type="xsd:string" minOccurs="0" maxOccurs="1"/> <xsd:element name="VALID_VALUES" type="ValidValuesType" minOccurs="0" maxOccurs="1" /> </xsd:choice></xsd:complexType>The solution simply being the choice options constraint for minOccurs="0" meaning, it doesn't have to be present, but for the requirement, yes, the VALUE element has to be there, as in case 1 2 or 3.Any ideas? Any help would be greatly apprecaited.

Share this post


Link to post
Share on other sites

Hi,What about declaring a dummy type for your VALUE element, that dummy type being a choice between three types, each one corresponding to one of your cases ?

<complextype name="dummy">  <sequence>    <choice>      <element name="VALUE" type="string"/>      <element name="VALUE" type="tns:typeCase2"/>      <element name="VALUE" type="tns:typeCase3"/>    </choice>  </sequence></complextype>

Other point, I think a ComplexType can represent an element that can look like a SimpleType, that is for example :

<complextype name="toto">  <sequence>    <element name="VALUE" type="String"/>  </sequence></complexType>

Good luck with your work,Kevin.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...