我正在创建一个xsd架构来验证某些xml 我想限制xml,因此两次输入相同的项目是不可能的: branches brancheBank/branche brancheBank/branche/branches 但是使用2个不同的项目必须是可行的: branches bra
          我想限制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”不会将其限制为只有一个值,因为’branche’标记可以出现两次.
我希望值(< branche>值< / branche>)是唯一的.
日Thnx!
请参阅有关身份约束的示例 here.类似于:<xs:element name="branches" ...>
  <xs:unique name="...">
    <xs:selector xpath="branche"/>
    <xs:field xpath="."/>
  </xs:key>
</xs:element> 
 不太确定语法,但你明白了.
