Reputation: 1923
I have a sequence of different types, for some of them I want to ensure, that at most one of these element is used. Here are some examples: <Synchronisation>
and <Link>
may occure one time. There are Elements like <TextBox>
, <Label>
, <CheckBox>
, etc. From these elements there is at most one allowed. Either <TextBox>
, <Label>
or <CheckBox>
.
Valid XMLs:
<Property>
<Synchronisation/>
</Property>
<Property>
<Synchronisation/>
<Link/>
</Property>
<Property>
<Synchronisation/>
<Link/>
<TextBox/>
</Property>
<Property>
<Synchronisation/>
<Link/>
<Label/>
</Property>
Invalid XML, as <TextBox>
and <Label>
occures.
<Property>
<Synchronisation/>
<Link/>
<Label/>
<TextBox/>
</Property>
I tried to do the xsd like this, but it does not work:
<xsd:complexType name="PropertyType">
<xsd:sequence minOccurs="0">
<xsd:element minOccurs="0" maxOccurs="1" name="Synchronisation" type="SynchronisationType"/>
<xsd:element minOccurs="0" maxOccurs="1" name="Links" type="LinksType"/>
<xsd:element minOccurs="0" maxOccurs="1" ref="ElementType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ElementType">
<xsd:choice>
<xsd:element name="TextBox" type="TextBoxType"/>
<xsd:element name="Label" type="TextBoxType"/>
<xsd:element name="CheckBox" type="TextBoxType"/>
</xsd:choice>
</xsd:complexType>
Upvotes: 0
Views: 183
Reputation: 1923
Finally i found a solution for the problem:
<xsd:complexType name="PropertyType">
<xsd:sequence minOccurs="0">
<xsd:element minOccurs="0" maxOccurs="1" name="Synchronisation" type="SynchronisationType"/>
<xsd:element minOccurs="0" maxOccurs="1" name="Links" type="LinksType"/>
<xsd:choice minOccurs="0" maxOccurs="1"/>
<xsd:element minOccurs="0" maxOccurs="1" name="TextBox" type="TextBoxType" />
<xsd:element minOccurs="0" maxOccurs="1" name="Label" type="LabelType" />
<xsd:element minOccurs="0" maxOccurs="1" name="CheckBox" type="CheckBoxType" />
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
Upvotes: 1