I am using the below simpleType for allowing only 5 type of words. This is working fine. but the problem is, it is failing, if i appended only one character with upper case at the end of the string.
Please help me regarding this.
<xsd:simpleType name="UpdateMemberPhysicalCardTypeType">
<xsd:annotation>
<xsd:documentation>
Type for physical data type
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="([PERMANENT|TEMPORARY|NOT CARDED|RETAIL CARD|VIRTUAL CARD])*"/>
</xsd:restriction>
</xsd:simpleType>
Success Case:
<typ:PhysicalCardType>PERMANENT</typ:PhysicalCardType>
-> working fine
<typ:PhysicalCardType>PERMANENTqwer</typ:PhysicalCardType>
-> getting error. it is working fine.
Failure case:
<typ:PhysicalCardType>PERMANENTD</typ:PhysicalCardType>
-> not getting error. This is not working. it is allowing this word. It should not allow this one.
答案 0 :(得分:1)
正常表达式网站http://www.regular-expressions.info/xml.html,我总是将其作为首选,解释说 正则表达式模式匹配查找匹配的第一个实例。在这种情况下,你已经指示它匹配PERMANENT,然后,因为你在()*中包含了他的语句,它会循环。我不知道你的验证例程为什么允许PERMANENTD,但你显示的正则表达式应该允许PERMANENTTEMPORARY作为有效条目,我不确定你是否想要它。
当我想在XML模式中枚举一组特定的允许和互斥值时,我使用枚举,如下所示:
<xs:simpleType name="UpdateMemberPhysicalCardTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="PERMANENT" />
<xs:enumeration value="TEMPORARY" />
<xs:enumeration value="NOT CARDED" />
<xs:enumeration value="RETAIL CARD" />
<xs:enumeration value="VIRTUAL CARD" />
<xs:enumeration value="list-session" />
</xs:restriction>
</xs:simpleType>
答案 1 :(得分:0)
This is what you want.
<xsd:pattern value="PERMANENT|TEMPORARY|NOT CARDED|RETAIL CARD|VIRTUAL CARD"/>
Here's a useful page on the matter: http://www.regular-expressions.info/xml.html