Xml xsd:choice中两个元素的特定顺序
我有以下XSD:Xml xsd:choice中两个元素的特定顺序,xml,xsd,Xml,Xsd,我有以下XSD: <xs:complexType name="CodeTags"> <xs:choice maxOccurs="unbounded"> <xs:element name="text" minOccurs="0" maxOccurs="unbounded"> ... </xs:element> <xs:element name="reference"
<xs:complexType name="CodeTags">
<xs:choice maxOccurs="unbounded">
<xs:element name="text" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
<xs:element name="reference" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
<xs:element ref="switch" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
<xs:element ref="if" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
<xs:element ref="else" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
<xs:element ref="param" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
</xs:choice>
</xs:complexType>
...
...
...
...
...
...
我希望else
标记正好出现在if
标记之后。我怎样才能做到这一点?我已经将它们放入
顺序中,但是我仍然能够在任何地方输入else
标记,在它和if
标记之间还有其他标记
编辑:代码片段以图片形式发布,现在更改为代码块。只需将
if
和else
放在xs:sequence
中作为选项之一:
<xs:choice minOccurs="0" maxOccurs="unbounded">
<!-- ... -->
<xs:sequence>
<xs:element ref="if"/>
<xs:element ref="else"/>
</xs:sequence>
<!-- ... -->
<xs:choice>
您还可以从每个选项中删除
minOccurs
和maxOccurs
;将它们放在xs:choice
本身就足以满足您的需要。要了解如何更好地处理这种情况,我建议您首先了解您编写的CodeTags元素的含义,以及它为什么允许您不允许的元素序列。然后继续理解kjhughes提供的解决方案为什么有效。谢谢,它有效。我还可以管理,if标记可以单独使用,但是如果使用else,if标记必须在前面。为了实现这一点,我在else声明中添加了minOccurs=“0”。