在 XSD 中的限制中指定多个模式 [英] Specifying multiple patterns in a restriction in a XSD

查看:29
本文介绍了在 XSD 中的限制中指定多个模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 XSD 元素:

I have following XSD element:

<xsd:element name="password">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <!-- Length check -->
            <xsd:pattern value=".{9,12}" />
            <!-- Format check -->
            <xsd:pattern value=".*\d{2,}.*" />
            <xsd:pattern value=".*[A-Z]{1,}.*" />
            <xsd:pattern value=".*[a-z]{1,}.*" />
            <xsd:pattern value=".*\p{Punct}.*" />
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

我想分别应用这些模式中的每一个.它应该首先检查长度是否合适.如果是这样,请检查它是否至少有 2 位数字等等.相反,它将所有表达式连接在一起并尝试将它们应用在一起.

I want to apply each of those patterns individually. It should first check that length is proper. If so then check that it has at least 2 digits and so on. Instead, it concatenates all the expressions together and tries to apply them together.

这是非常糟糕的设计.如果只允许一种模式, 应定义 的基数为 1.允许多个 给人的印象是支持多个模式.

This is very poor design. If only one pattern is allowed <xsd:restriction> should define the cardinality of <xsd:pattern> to be 1. Allowing multiple <xsd:pattern> gives the impression that multiple patterns are supported.

有没有办法将多个模式应用于一个 XSD 元素?

推荐答案

每个限制支持多个模式,但它们并不意味着 AND;他们的意思是:

Multiple patterns per restriction are supported, but they do not mean AND; they mean OR:

注意:包含多个 元素的 XML 在集合中产生一个单一的·正则表达式;这·常规表达式· 是·正则表达式· 的或",它们是 元素的内容.

Note: An XML <restriction> containing more than one <pattern> element gives rise to a single ·regular expression· in the set; this ·regular expression· is an "or" of the ·regular expressions· that are the content of the <pattern> elements.

如果您希望同时应用多个正则表达式约束,请将它们写在一个 中.

If you want multiple regex constraints to apply concurrently, write them in a single <pattern>.

对于最小/最大长度限制,请考虑使用 个方面.

For min/max length constraints, rather than using <pattern>, consider using <minLength> and <maxLength> facets.

这篇关于在 XSD 中的限制中指定多个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆