我需要一个XML验证问题的建议。我的问题是,我需要设置一个用于XML验证的XSD,它定义了两个必填字段和两个可选字段。根据可用的数据,字段的特征切换。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>
有没有办法实现我想要做的事情?
你应该更具体一些......这是可能的XSD 1.1。典型的答案是XSD 1.0 + Schematron或者XSD 1.1 –
感谢@PetruGardea的更正。我要解决答案。我不知道XSD 1.1支持断言。这很酷。 – helderdarocha
是的,XSD 1.1中的一些功能非常酷。不幸的是,对XSD 1.1的支持不是很广泛,所以经常不能使用这个原因。 – Dijkgraaf