【发布时间】:2011-07-09 04:16:31
【问题描述】:
我正在尝试定义具有可选标记sort_expression 的 XML 模式。如果提供了该可选标签,则允许使用第二个可选标签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>
我认为下面的模式,使用两个序列的选择会起作用。不幸的是,模式本身没有验证; 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>
【问题讨论】:
标签: xml xsd schema-design