0

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.

Ramkumar
  • 154
  • 5
  • 11

2 Answers2

1

The regular expression website, http://www.regular-expressions.info/xml.html, which I always use as a go-to, explains that the regular expression pattern matching finds the first instance of a match. In this case, you have instructed it to match PERMANENT, and then, because you have enclosed he statement in ()*, it loops around. I do not know why your validation routine allows PERMANENTD, but the regex you show should allow PERMANENTTEMPORARY as a valid entry, and I am not sure you want that.

When I want to enumerate a specific set of permitted and mutually exclusive values in an XML schema, I use an enumeration, like so:

<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>
John Spragge
  • 172
  • 2
  • 3
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

Phil Walton
  • 963
  • 6
  • 11