开发者

xsd validation ERROR with both minOccurs and length used simultaneously

    <xsd:element name="CurrencyCode" minOccurs="0" type="xsd:string">
        <xsd:simpleType>
        <xsd:restriction>
        <xsd:length value="3"/>
        </xsd:restriction>
        </xsd:simpleType>
    </xsd:element>

I want my Currencycode to be an optional value and if at all there is a value it should have a length of 3 letters .. either my CurrencyCode can have Length=0 or length=3

When i use the 开发者_Python百科above code the validator returns an error when there is an empty field

xsd validation ERROR with both minOccurs and length used simultaneously

So how can i deal with this ??


Have not tried this (do not have suitable env set up on this machine) but according to the specification you can do as follows:

<xsd:element name="CurrencyCode" minOccurs="0" type="xsd:string">
   <xsd:simpleType>
      <xsd:restriction base="xsd:string">
         <xsd:pattern value="(?:^$|\w{3})"/>
      </xsd:restriction>
   </xsd:simpleType>
</xsd:element>

Regular expression (?:^$|\w{3}) matches either empty string or exactly three word characters. You can use (?:^$|[A-Z]{3}) in case you want to accept currency codes only in upper case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜