XSD 唯一约束似乎对我不起作用。我有以下 XSD:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://beardedhen.com/form"
xmlns:tns="http://beardedhen.com/form"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:complexType name="OptionListType">
<xs:sequence>
<xs:element name="option" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="label" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="OptionList" type="tns:OptionListType">
<xs:unique name="uniqueOptionListLabel">
<xs:selector xpath="option"/>
<xs:field xpath="@label"/>
</xs:unique>
</xs:element>
</schema>
当我在 Eclipse 和在线验证器中验证下面的 XML 时,没有返回错误:
<OptionList xmlns="http://beardedhen.com/form"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="statusLevels">
<option label="Critical" value="0"/>
<option label="Warning" value="1"/>
<option label="Warning" value="1"/>
<option label="Warning" value="1"/>
<option label="Good" value="4"/>
</OptionList>
它看起来很简单,并且有一些我遵循的例子,但这让我发疯!:-)
有任何想法吗?