据我所知,以下XML应该对其下面的XSD进行验证,因为所有“symbolName”值都是唯一的。但是,当我尝试验证它时,我收到以下错误
身份约束'xxxxxxsdfsdfsdfsdf'的字段'symbolName'在元素'symbols'范围内匹配9次
<levelSymbolCollection>
<levelName>Simple</levelName>
<symbols>
<symbolName>Letter-A</symbolName>
<symbolName>Letter-B</symbolName>
<symbolName>Letter-C</symbolName>
<symbolName>Letter-D</symbolName>
<symbolName>Letter-E</symbolName>
<symbolName>Letter-F</symbolName>
<symbolName>Letter-I</symbolName>
<symbolName>Letter-O</symbolName>
<symbolName>Letter-U</symbolName>
</symbols>
</levelSymbolCollection>
<xs:element name="levelSymbolCollection" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="levelName" type="requiredString"/>
<xs:element name="symbols">
<xs:complexType>
<xs:sequence>
<xs:element name="symbolName" type="requiredString" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="xxxxxxxxsdfsdfsdfsdf">
<xs:selector xpath="symbols"></xs:selector>
<xs:field xpath="symbolName"></xs:field>
</xs:unique>
</xs:element>
答案 0 :(得分:1)
将“symbolName”添加到选择器,设置字段xpath =“。”
<xs:element name="levelSymbolCollection" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="levelName" type="requiredString"/>
<xs:element name="symbols">
<xs:complexType>
<xs:sequence>
<xs:element name="symbolName" type="requiredString" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="xxxxxxxxsdfsdfsdfsdf">
<xs:selector xpath="symbolName"></xs:selector>
<xs:field xpath="."></xs:field>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
答案 1 :(得分:0)
你显然对xs的含义有一些误解:唯一。您的声明表明每个symbolName必须具有唯一值,实际上,每个symbolName都具有唯一值。