Guest chapel21 Posted October 25, 2005 Share Posted October 25, 2005 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. Link to comment Share on other sites More sharing options...
Zukero Posted May 3, 2006 Share Posted May 3, 2006 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now