xsd 使用正则表达式验证字符串

xsd string validation with regex

我有一个xsd,这是其中的一部分:

   <xs:complexType name="Shape">
    <xs:annotation>
        <xs:documentation>
            Shape object
        </xs:documentation>
    </xs:annotation>
    <xs:complexContent>
        <xs:extension base="archimate:ViewNodeType" >                          
          <xs:attribute name="shapeId" use="required">
             <xs:simpleType>
                 <xs:restriction base="xs:string">
                   <xs:pattern value="[a-zA-Z0-9]" />
               </xs:restriction>
            </xs:simpleType>                    
            </xs:attribute> 

我需要验证来自 xml 的 shapeId。 shapeId 是一个字符串,可以包含字母和数字,例如:

 shapeId="5dad54ae0c0ba639c4a5a800" 

然而,我使用的模式正确验证了 regextester.com 中的 shapeId,此 xsd 抛出异常 'The shapeId attribute is invalid - The value in invalid according its datatype String.' 我在这里缺少什么?

模式必须完全匹配。你的只匹配一个字母。您缺少 *+{24}:

这样的量词
<xs:pattern value="[a-zA-Z0-9]+" />