making an element optional using xsd -cvc-length-valid ERROR -


<xs:element name="currencycode" minoccurs="0">   <xs:simpletype>     <xs:restriction base="xs:string">       <xs:length value="3" />     </xs:restriction>   </xs:simpletype> </xs:element> 

but if value empty returns error

cvc-length-valid: value '' length = '0' not facet-valid respect length '3' type '#anontype_currencycodeserviceservicelist'.

so how can deal ?

your schema allows omitt currencycode element if present value must string 3 characters length.

you weaken restriction allow 0-length values specifying min , max length:

<xs:element name="currencycode" minoccurs="0">     <xs:simpletype>         <xs:restriction base="xs:string">             <xs:minlength value="0" />             <xs:maxlength value="3" />         </xs:restriction>     </xs:simpletype> </xs:element> 

this allow values "eu " not valid currency code.


a different approach be, specify list of valid currency code values , include empty string valid code:

<xs:element name="currencycode" minoccurs="0">     <xs:simpletype>         <xs:restriction base="xs:string">             <xs:enumeration value=""/>             <xs:enumeration value="usd"/>             <xs:enumeration value="gbp"/>             <xs:enumeration value="eur"/>             <!-- add currency codes need -->         </xs:restriction>     </xs:simpletype> </xs:element> 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -