微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml架构检查限制枚举值是否只有一次

我正在创建一个xsd架构来验证某些xml

我想限制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>

不太确定语法,但你明白了.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。