如何解决使用正则表达式进行xsd字符串验证
我有一个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引发了一个例外,即“ shapeId属性无效-根据其数据类型String,该值无效。” 我在这里想念什么?
解决方法
模式必须完全匹配 。您只匹配一个字母。您缺少像*
或+
或{24}
这样的量词:
<xs:pattern value="[a-zA-Z0-9]+" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。