1

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>

以下の XML を Eclipse とオンライン バリデーターの両方で検証すると、エラーは返されません。

 <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>

それは単純に見え、私が従った例がそこにありますが、これは私を怒らせています! :-)

何か案は?

4

2 に答える 2

4

セレクタ要素の XPath 式では、プレフィックス「tns」を使用する必要があります。

<xs:selector xpath="tns:option"/>
于 2013-02-04T10:40:34.827 に答える
0

または、xs:string の代わりに xs:ID を使用できます。xs:IDREF および xs:IDREFS も参照してください。

http://books.xmlschemata.org/relaxng/ch19-77151.html

于 2015-09-15T23:21:14.227 に答える