我有XML Schema應用程序的問題。第一種情況是一個序列與元素參考。這種情況有效,但我有一個請求,它允許元素main
中的一個元素onlyone
或元素problem
(不在main
元素中)中的onlyone
。我嘗試了許多解決方案,特別是將它們分解爲順序並將元素problem
作爲新定義的元素引用。這有效,但是當我將complexType
添加到元素problem
時,它會警告我爲錯誤。我需要有新的元素problem
與要求的條件。XSD驗證錯誤:cos-element-consistent:元素與元素不一致
XSD:
<xs:sequence>
<xs:sequence>
<xs:element ref="el1" minOccurs="1" maxOccurs="1"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="el2" minOccurs="0" maxOccurs="1"/>
<xs:element name="problem" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="inside1" maxOccurs="unbounded"/>
<xs:element ref="inside2" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element ref="onlyone" minOccurs="0" maxOccurs="1"/>
</xs:choice>
<xs:element ref="el3" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="el1" minOccurs="1" maxOccurs="1"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="el2" minOccurs="0" maxOccurs="1"/>
<xs:element name="problem" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="inside1" maxOccurs="unbounded"/>
<xs:element ref="onlyone" minOccurs="0" maxOccurs="1"/>
<xs:element ref="inside2" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:element ref="el3" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:sequence>
而且XMLSpy的保存時寫信給我,:
Element 'problem' is not consistent with element 'problem' a cos-element-consistent.1: Both type definitions ('{anonymous}' and '{anonymous}') must be named.