XML 架构在两个属性上以任何顺序唯一
XML Schema Unique together on two attributes in any order
我有一个简单的 xml 结构,类似于问题 XML Schema Unique Together on Two Attributes 中概述的结构,但是我想以任何顺序使它独一无二。
我已经想出如何使它一起变得独一无二,除非我反转它不起作用的值。我用了
<xsd:element name="foo">
...
<xsd:unique name="rowcol">
<xsd:selector xpath="bar"/>
<xsd:field xpath="@row"/>
<xsd:field xpath="@column"/>
</xsd:unique>
</xsd:element>
对于这种情况
<foo>
<bar row="42" column="2"></bar>
<bar row="42" column="3"></bar>
<bar row="42" column="2"></bar>
<bar row="3" column="42"></bar>
</foo>
我希望最后 2 项不能通过唯一性测试
XSD 1.0 无法做到这一点。
您可以使用 XSD 1.1 中的断言来完成。保持唯一性约束,并添加
<xsd:assert test="not(some $x in bar, $y in bar[not($y is $x)]
satisifies $x/@row = $y/@column
and $x/@column = $y/@row)"/>
我有一个简单的 xml 结构,类似于问题 XML Schema Unique Together on Two Attributes 中概述的结构,但是我想以任何顺序使它独一无二。
我已经想出如何使它一起变得独一无二,除非我反转它不起作用的值。我用了
<xsd:element name="foo">
...
<xsd:unique name="rowcol">
<xsd:selector xpath="bar"/>
<xsd:field xpath="@row"/>
<xsd:field xpath="@column"/>
</xsd:unique>
</xsd:element>
对于这种情况
<foo>
<bar row="42" column="2"></bar>
<bar row="42" column="3"></bar>
<bar row="42" column="2"></bar>
<bar row="3" column="42"></bar>
</foo>
我希望最后 2 项不能通过唯一性测试
XSD 1.0 无法做到这一点。
您可以使用 XSD 1.1 中的断言来完成。保持唯一性约束,并添加
<xsd:assert test="not(some $x in bar, $y in bar[not($y is $x)]
satisifies $x/@row = $y/@column
and $x/@column = $y/@row)"/>