开发者

XML schema restriction that allows empty elements or specific pattern

I want to define an element in XML schema that will allow for an empty string or some specific pattern, e.g.,:

<Code/> 
<Code></Code> 
<Code> </Code>
<Code>11111</Code>
<Code>111111</Code> - INVALID
<Code>AAAAA</Code> - INVALID

How can I modify my existing restriction?

<xs:element name="Code">                
<xs:simpleType>
<xs:restriction base="xs:string"> 
<xs:pattern value="[0-9]{5开发者_如何学Python}" />
</xs:restriction>
</xs:simpleType>
</xs:element>


Add \s as another choice to your regex to allow whitespace characters [#x20\t\n\r] (That is: "regular" space, tab, line feed, carriage return. Non-breaking space is not included.)

<xs:simpleType>
    <xs:restriction base="xs:string"> 
        <xs:pattern value="\s*|[0-9]{5}" />
    </xs:restriction>
</xs:simpleType>


Use "^$|pattern" it should work as ^$ matches just null values.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜