【发布时间】:2014-02-27 12:34:06
【问题描述】:
我需要关于 xml 验证问题的建议。我的问题是我需要为 XML 验证设置一个 XSD,它定义了两个必填字段和两个可选字段。根据现有数据,字段的特性会发生变化。
如果满足上述任一情况,则 XML 应有效。
- 应该可以填写 AAA 和 BBB 字段。填写这些字段后,CCC 和 DDD 可能为空。
- 当填写CCC和DDD字段时,字段AAA和BBB应该是可选的。
我正在考虑类似以下的结构,但我无法使用我的 ALTOVA XMLSPY 2012 保存它。它说内容模型不是唯一的。
<xs:complexType name="ZZZType">
<xs:annotation>
<xs:documentation>Selection</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="XXX" type="xs:string" nillable="true" minOccurs="0"/>
<xs:choice>
<xs:sequence>
<xs:element name="AAA" type="AAAType" nillable="false"/>
<xs:element name="BBB" type="BBBType" nillable="false"/>
<xs:element name="CCC" type="CCCType" nillable="false" minOccurs="0"/>
<xs:element name="DDD" type="DDDType" nillable="false" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:element name="AAA" type="AAAType" nillable="false" minOccurs="0"/>
<xs:element name="BBB" type="BBBType" nillable="false" minOccurs="0"/>
<xs:element name="CCC" type="CCCType" nillable="false"/>
<xs:element name="DDD" type="DDDType" nillable="false"/>
</xs:sequence>
</xs:choice>
</xs:sequence>
</xs:complexType>
有没有办法实现我想做什么?
【问题讨论】: