我有一个简单的XML结构:
<foo>
<bar row="42" column="2"></bar>
<bar row="42" column="3"></bar>
</foo>
Run Code Online (Sandbox Code Playgroud)
我想row和column中bar是唯一的一起.所以上面的例子验证了,而以下的例子没有:
<foo>
<bar row="42" column="2"></bar>
<bar row="42" column="3"></bar>
<bar row="42" column="3"></bar>
</foo>
Run Code Online (Sandbox Code Playgroud)
我一直在尝试为以下架构添加密钥,但我还没有找到解决方案.
<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:element name="bar" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="row" type="xs:positiveInteger" use="required"/>
<xs:attribute name="column" type="xs:positiveInteger" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
xan*_*xan 10
我希望以下做到这一点.
<xsd:element name="foo">
...
<xsd:unique name="rowcol">
<xsd:selector xpath="bar"/>
<xsd:field xpath="@row"/>
<xsd:field xpath="@column"/>
</xsd:unique>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)
唯一性约束在唯一性范围的元素声明中,我猜测是foo.如果你的结构实际上更像是:
<root>
<foo> ... </foo>
<foo> ... </foo>
</root>
Run Code Online (Sandbox Code Playgroud)
而且你希望唯一性是全局的,那么约束应该继续下去root.