对于我正在创建的模式,我希望有一个唯一性约束,该约束仅在每个父节点内检查唯一性,而不是在整个模式中检查子节点的实例。我认为这是最好的示例说明,请参见下面的xml。
我正在使用的xpath针对的所有实例检查唯一性<subnode value="x">
,而我希望它仅针对的子实例检查唯一性<subnode value="x">
,这里是clencher的单独实例<globalElement>
<globalElement>
<subnode value="1" />
<subnode value="2" />
</globalElement>
<globalElement>
<subnode value="1" /> <!-- Desired error here -->
<subnode value="1" /> <!-- Desired error here -->
</globalElement>
<globalElement>
<subnode value="1" /> <!-- Error here -->
<subnode value="2" />
</globalElement>
<globalElement>
<subnode value="1" /> <!-- Error here -->
<subnode value="1" /> <!-- Error here -->
</globalElement>
<xs:element name="rootElement">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded" >
<xs:any namespace="##targetNamespace" />
</xs:choice>
</xs:complexType>
<xs:unique name="name_check">
<xs:selector xpath=".//prefix:globalElement/prefix:subnode" />
<xs:field xpath="@value" />
</xs:unique>
</element>
如果保持简单,则架构中的唯一约束非常简单。如果您希望A内的每个B对C具有唯一的值(例如,一个国家内的每个人对护照号码具有唯一的值),则应在元素A级别定义约束,选择器应选择B相对于A,并且该字段应选择相对于B的C。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句