2010-11-24 15 views
4

私はいくつかのXMLXMLスキーマは、その制限列挙値は一度だけ

の検証のためのXSDスキーマを作成していoccrusチェックし、私はそれが二度同じ項目を入力するかのうではありませんので、XMLを制限したいと思います:

<branches> 
    <branche>Bank</branche> 
    <branche>Bank</branche> 
</branches> 

しかし、2つの異なるアイテムを使用することがかのうである必要があります。

:だから私は、次のコードを持って

<branches> 
    <branche>Bank</branche> 
    <branche>Insurance</branche> 
</branches> 

<!-- definition of simple elements --> 
    <xs:simpleType name="branche"> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="Bank" maxOccurs="1"/> 
      <xs:enumeration value="Insurance" maxOccurs="1"/> 
     </xs:restriction> 
    </xs:simpleType> 

    <xs:element name="branches" minOccurs="0"> <!-- minOccurs becouse i want it to be posible to leave out the whole <branches> tag --> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="branche" type="branche" minOccurs="0" maxOccurs="2" /> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

maxOccurs="1"10を使用しても、「branche」タグが2回発生する可能性があるため、値を1つに限定することはできません。

値(<branche>value</branche>)を一意にします。

thnx!

答えて

4

ID制約hereの例を参照してください。次のようなものがあります。

<xs:element name="branches" ...> 
    <xs:unique name="..."> 
    <xs:selector xpath="branche"/> 
    <xs:field xpath="."/> 
    </xs:key> 
</xs:element> 

構文についてはわかりませんが、あなたはそのアイデアを得ます。次のコードを使用して、それを修正

+0

で私を指しているため

<xs:element name="branches" minOccurs="0"> <xs:complexType> <xs:sequence> <xs:element name="branche" type="branche" minOccurs="0" maxOccurs="2" /> </xs:sequence> </xs:complexType> <xs:unique name="brancheUnique"> <xs:selector xpath="branche"/> <xs:field xpath="."/> </xs:unique> </xs:element> 

のthnx lexicoreを私は基本的なアイデアを得るが、それは動作しません。 私はセレクタが間違っていると思うし、子要素を持っているので、ブランチはcomplexTypeでなければなりません。私はまだこれを修正しようとしています。あなたの投稿を続ける – FLY

3

:右方向

関連する問題