Jyoti Singh

Jyoti Singh

  • NA
  • 45
  • 2.3k

XSD Validation for all zeros and special characters

May 14 2021 7:53 PM
Please find the requirement and xml and xsd i tried.
 
<FAXNUMBER>! $ % . _^ * ~ , : ; ‘ # | & “ < ></FAXNUMBER>:-Should not accept
<FAXNUMBER>00000</FAXNUMBER>:-Should not accept
<FAXNUMBER>test</FAXNUMBER>:-Should accept
<FAXNUMBER>test1111</FAXNUMBER>:-Should accept
<FAXNUMBER>123445</FAXNUMBER>:-Should accept
<FAXNUMBER></FAXNUMBER>:-Should accept
<FAXNUMBER>122@()\/{}?-+=[]</FAXNUMBER>:-any special character other than restricted one(! $ % . _^ * ~ , : ; ‘ # | & “ < >) Should accept
 
XSD i tried:Its is restricting 122@()\/{}?-+=[] scenario also
 
<!-- 21.06 Turkey June Start -->
<xs:simpleType name="String1">
<xs:restriction base="xs:string">
<xs:pattern value="(^([\d]*[A-Za-z1-9]+[\d]*)$)"/>
<xs:maxLength value="30"/>
<xs:whiteSpace value="replace"/>
</xs:restriction>
</xs:simpleType>
<!-- Allowed for empty or null value and restrict special characters-->
<xs:simpleType name="emptyString1">
<xs:restriction base="xs:string">
<xs:enumeration value=""/>
<xs:enumeration value="(^[^!$%^*._~,:;''#|/&amp;\\&quot;&gt;&lt;]+$)?" />
</xs:restriction>
</xs:simpleType>
<!-- Union both to allow FAXNUMBER-->
<xs:element name="FAXNUMBER" nillable="true">
<xs:simpleType>
<xs:union memberTypes="String1 emptyString1"/>
</xs:simpleType>
</xs:element>
<!--21.06 Turkey June-End-->
 
XML:
 
<SHIPPINGDETAILS>
<DROPSHIP>
<COMPANYNAME>Comp Name</COMPANYNAME>
<COMPANYNAMEINENGLISH></COMPANYNAMEINENGLISH>
<STREET1>1 Microsoft Way</STREET1>
<STREET2></STREET2>
<CITY_DISTRICT>REDMOND</CITY_DISTRICT>
<STATE></STATE>
<ZIPCODE>98052-8300</ZIPCODE>
<COUNTRY>US</COUNTRY>
<PHONE>4233323564</PHONE>
<FAXNUMBER>0000000</FAXNUMBER>
</DROPSHIP>
</SHIPPINGDETAILS>