我有一个不同类型的序列,对于其中一些,我想确保最多使用这些元素中的一个。这里有一些例子:<Synchronisation>
和<Link>
可能会同时出现。有像<TextBox>
,<Label>
,<CheckBox>
等元素。从这些元素中最多允许一个元素。<TextBox>
、<Label>
或<CheckBox>
。
有效的XML:
<Property>
<Synchronisation/>
</Property>
<Property>
<Synchronisation/>
<Link/>
</Property>
<Property>
<Synchronisation/>
<Link/>
<TextBox/>
</Property>
<Property>
<Synchronisation/>
<Link/>
<Label/>
</Property>
由于出现<TextBox>
和<Label>
,XML无效。
<Property>
<Synchronisation/>
<Link/>
<Label/>
<TextBox/>
</Property>
我试着这样做xsd,但它不起作用:
<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>
发布于 2017-07-26 21:05:17
最后,我找到了这个问题的解决方案:
<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>
https://stackoverflow.com/questions/45323791
复制相似问题