在XSD 1.0,你唯一的选择是记录在散文的约束。 (例如,在架构模式中,元素声明具有类似的约束)。
在XSD 1.1中,您可以使用断言来记录和强制执行约束。 Modfying通过彼得鲁杜米特Gardea提出了一个位架构文档,我们有:
<xs:schema targetNamespace="http://example.com/colors"
xmlns:tns="http://example.com/colors"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="flowerColor">
<xs:restriction base="xs:normalizedString">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="flowerVariantC">
<xs:sequence>
<xs:element name="color"
type="tns:flowerColor"
minOccurs="0"/>
</xs:sequence>
<xs:attribute name="color"
type="tns:flowerColor"
use="optional"/>
<xs:assert test="(./tns:color or ./@color)
and not(./tns:color and ./@color)"/>
</xs:complexType>
<xs:element name="flower" type="tns:flowerVariantC"/>
<xs:element name="test"/>
</xs:schema>
鉴于刚刚展示的模式文档和下面的实例,撒克逊人拒绝第一和第四花朵元素为无效。
<test xmlns="http://example.com/colors"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/colors colors.xsd">
<flower/>
<flower color="red"/>
<flower><color>blue</color></flower>
<flower color="blue"><color>blue</color></flower>
</test>
(这就是说,我的本能是反对这项建议设计过于复杂:选择使颜色的属性,还是选择让孩子的事实,每一个都是合理的设计确实不。意味着允许它在文档内变化是一种合理的设计。)