我希望文档只包含苹果或橙子。我正在创建一个XML模式,如下所示:
<element name="fruit" type="myns:fruitType"></element>
<complexType name="fruitType">
<choice minOccurs="1" maxOccurs="1">
<sequence>
<element name="apple" type="string" minOccurs="0" maxOccurs="unbounded"></element>
<element name="orange" type="string" minOccurs="0" maxOccurs="0"></element>
</sequence>
<sequence >
<element name="orange" type="string" minOccurs="0" maxOccurs="unbounded"></element>
<element name="apple" type="string" minOccurs="0" maxOccurs="0"></element>
</sequence>
</choice>
</complexType>
但是接受以下内容作为有效元素。
<fruit>
<apple> apple1 </apple>
<orange> orange1 </orange>
<orange> orange2 </orange>
<apple> apple2 </apple>
</fruit>
我只希望以下内容有效:
<fruit>
<apple> apple1 </apple>
<apple> apple2 </apple>
.
.
<apple> appleN </apple>
</fruit>
OR
<fruit>
<orange> orange1 </orange>
<orange> orange2 </orange>
.
.
<orange> orangeN </orange>
</fruit>
知道怎么做吗?
答案 0 :(得分:0)
<complexType name="fruitType">
<choice minOccurs="1" maxOccurs="1">
<sequence>
<element name="apple" type="string" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
<sequence >
<element name="orange" type="string" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
</choice>
</complexType>
答案 1 :(得分:0)
正确的架构应该是:
<complexType name="fruitType">
<choice minOccurs="1" maxOccurs="1">
<sequence>
<element name="apple" type="string" **minOccurs="1"** maxOccurs="unbounded">
</element>
</sequence>
<sequence >
<element name="orange" type="string" **minOccurs="1"** maxOccurs="unbounded">
</element>
</sequence>
</choice>
</complexType>