一个或多个元素,至少一个具有给定值的属性
问题描述:
我需要在XML模式中描述以下内容:一个元素必须出现一次或多次,但是该元素的一次出现必须具有该属性“属性” 设置值 “导航”一个或多个元素,至少一个具有给定值的属性
例子:
<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>
坏尝试虽然,因为验证给了我以下错误:
local complex type: The content model is not determinist.
很显然,这个模式是不确定的,因为如果他是应该与第一检查中遇到item
元素验证不能决定或者这个元素的2个定义中的第二个......
......但是我怎么能做到这一点呢?这可能吗?
答
这是使用XSD 1.0无法实现的,它需要XSD 1.1和断言。我不认为你在PHP中的默认模式验证器将支持XSD 1.1。
+0
然后,我要放弃这个测试,或者我会尝试像第一个XSLT-step转换item [@properties ='nav']'到'item_nav'中,然后第二个XSD-step验证这个需要'item_nav'元素和x可选的'item'元素......对于我认为是一个简单的需求来说,似乎相当长的一段路:-( – fpierrat
你可以使用模式1.1吗?在这种情况下,你可以使用断言('')。 – potame
@potame我现在找不到答案,但我认为我不能(在PHP中使用'DOMDocument :: schemaValidate()')。几个月前我有另一个问题(条件子元素取决于“type”属性我记得我发现的答案是:当php集成模式1.1时,这将是可能的......我将在那个方向进一步搜索。 – fpierrat