オプションのタグを含むXMLスキーマを定義しようとしていますsort_expression
。そのオプションのタグが指定されている場合、2番目のオプションのタグalternate_sort_expression
が許可されますが、最初のタグの存在を条件とします。
たとえば、次の例を検証する必要があります。
<indication>
<label>A label for the item</label>
<sort_expression>Some Value</sort_expression>
<!-- one sort expression was provided -->
</indication>
また
<indication>
<label>A label for the item</label>
<!-- no sort expression was provided -->
</indication>
また
<indication>
<label>A label for the item</label>
<sort_expression>Some Value</sort_expression>
<alternate_sort_expression>Some Value</alternate_sort_expression>
</indication>
ただし、以下は検証に合格しないはずです。
<indication>
<label>A label for the item</label>
<!-- no main sort expression was provided -->
<alternate_sort_expression>INVALID</alternate_sort_expression>
</indication>
次のスキーマは、2つのシーケンスの選択を使用して機能すると思いました。残念ながら、スキーマ自体は検証されていません。Altova XML Spyは、「複雑な型の表示のコンテンツモデルはあいまいです。
<xs:complexType name="indication">
<xs:sequence>
<xs:element name="label" type="xs:string"/>
<xs:choice>
<xs:sequence>
<xs:element name="sort_expression" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:element name="sort_expression" type="xs:string"/>
<xs:element name="alternate_sort_expression" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
</xs:sequence>