xml – cvc-pattern-valid:值’A’对于模式’^ [A-Za-z]?$’,对于类型“无论如何”

以下是验证失败的特定 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

即拿出^和$.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念