我需要在 XML 模式中描述以下内容:一个元素必须出现 1 次或多次,但该元素的恰好一次出现必须将属性“properties”设置为值“nav”
例子:
<manifest>
<item href="example" id="02" properties="cover-image" /> <!-- optional item -->
<item href="dummy" id="sample" properties="nav" /> <!-- mandatory item with "nav" value for "properties" attribute -->
<item href="example" id="02" properties="mathlm scripted" /> <!-- optional item -->
</manifest>
我的“最佳”尝试是:
<xs:element name="manifest">
<xs:complexType>
<xs:choice>
<xs:element name="item" minOccurs="1" maxOccurs="1" ><!-- at least one (item property="nav")-->
<xs:complexType>
<xs:attribute name="href" type="xs:string" use="required" />
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="media-type" type="xs:string" use="required" />
<xs:attribute name="fallback" type="xs:string" />
<xs:attribute name="properties" type="xs:string" use="required" fixed="nav" />
<xs:attribute name="media-overlay" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="item" minOccurs="0" maxOccurs="unbounded" >
<xs:complexType>
<xs:attribute name="href" type="xs:string" use="required" />
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="media-type" type="xs:string" use="required" />
<xs:attribute name="fallback" type="xs:string" />
<xs:attribute name="properties" type="xs:string" />
<xs:attribute name="media-overlay" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="id" type="xs:string" />
</xs:complexType>
</xs:element>
不好的尝试,因为验证器给了我以下错误:
本地复杂类型:内容模型不是确定性的。
很明显,这个模式不是确定性的,因为验证器无法决定他是否应该使用该item
元素的 2 个定义中的第一个或第二个来检查遇到的元素
......但我怎样才能实现这个?这可能吗?