开发者

XML schema restriction that allows empty elements or specific pattern

开发者 https://www.devze.com 2023-03-08 02:49 出处:网络
I want to define an element in XML schema that will allow for an empty string or some specific pattern, e.g.,:

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

精彩评论

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