可以在模式级别强制使用不同名称的两个属性的唯一值吗?
<xs:complexType name="exampleType">
<xs:attribute name="first" type="xs:integer" use="required"/>
<xs:attribute name="second" type="xs:integer"/>
</xs:complexType>
如果first
为 1,则second
需要为其他值。
编辑:我正在使用 xsd 1.0。
正如我在评论中所说,这仅在first
并且second
是元素(不是属性)时才有效。|
xpath 运算符就像节点的联合。
<xs:element name="exampleElement" type="exampleType">
<xs:unique name="firstAndSecondDifferent">
<xs:selector xpath="first | second" />
<xs:field xpath="." />
</xs:unique>
</xs:element>
<xs:complexType name="exampleType">
<xs:sequence>
<xs:element name="first" type="xs:integer" />
<xs:element name="second" type="xs:integer" minOccurs="0" />
</xs:sequence>
</xs:complexType>
以下元素是有效的(first
并且second
具有不同的值):
<exampleElement>
<first>1</first>
<second>5</second>
</exampleElement>
以下元素有效(不存在second
元素):
<exampleElement>
<first>1</first>
</exampleElement>
以下元素无效(first
并且second
具有相同的值):
<exampleElement>
<first>1</first>
<second>1</second>
</exampleElement>
这不能用属性来完成,因为selector xpath
不允许使用属性,所以"@first | @second"
它不是选择器的 xpath 属性的有效值。