草庐IT

xml - cvc 模式有效 : Value 'A' is not facet-valid with respect to pattern '^[A-Za-z]?$' for type 'whatever'

coder 2024-06-23 原文

这是验证失败的特定 XML 标记:

<MiddleName>A</MiddleName>

该标签的 XSD:

<xsd:element name="MiddleName" type="MiddleInitial" />

<xsd:simpleType name="MiddleInitial">
    <xsd:restriction base="xsd:string">
        <xsd:pattern value="^[A-Za-z]?$" />
    </xsd:restriction>
</xsd:simpleType>

我得到的错误:

cvc-pattern-valid: Value 'A' is not facet-valid with respect to pattern '^[A-Za-z]?$' for type 'MiddleInitial'.

我正在使用的验证器:

http://tools.decisionsoft.com/schemaValidate/

正则表达式看起来不错。 ^ 匹配开头、$、结尾、?是字母 A-Z 或 a-z 的零次或一次。

有什么想法吗?

最佳答案

来自 w3 规范 Regular Expressions (Appendix D) :

...expressions are matched against entire lexical representations rather than user-scoped lexical representations such as line and paragraph. For this reason, the expression language does not contain the metacharacters ^ and $, although ^ is used to express exception, e.g. [^0-9]x

即取出 ^$

关于xml - cvc 模式有效 : Value 'A' is not facet-valid with respect to pattern '^[A-Za-z]?$' for type 'whatever' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9622869/

有关xml - cvc 模式有效 : Value 'A' is not facet-valid with respect to pattern '^[A-Za-z]?$' for type 'whatever'的更多相关文章

随机推荐