我有
<Account name="abc">
<Parameters type="standard"/>
</Account>
<Account name="abc">
<Parameters type="standard"/>
</Account>
我没有成功这样做
<xs:unique name="unique-Accounts">
<xs:selector xpath="ns:Account"/>
<xs:field xpath="Parameters/@type"/>
</xs:unique>
最终我想做点什么:
<xs:unique name="unique-Accounts">
<xs:selector xpath="ns:Account"/>
<xs:field xpath="@name"/>
<xs:field xpath="Parameters/@type"/>
</xs:unique>
但我的绊脚石是Parameters/@type
xpath
为什么这不起作用?
如果我尝试在@name
上使其唯一正常
答案 0 :(得分:1)
您似乎只是错过了xs:field
中的命名空间前缀。所以这有效:
XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://example.com"
xmlns:ns="http://example.com">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="Account" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Parameters">
<xs:complexType>
<xs:attribute name="type" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="unique-Accounts">
<xs:selector xpath="ns:Account"/>
<xs:field xpath="ns:Parameters/@type"/>
</xs:unique>
</xs:element>
</xs:schema>
XML:
<root xmlns="http://example.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com xsd.xsd">
<Account name="abc">
<Parameters type="standard"/>
</Account>
<Account name="abc">
<Parameters type="standard"/>
</Account>
</root>