验证整数或空

时间:2015-05-24 22:44:42

标签: xml xsd

我有以下xsd元素:

<xs:element name="Runtime" type="xs:integer" minOccurs="0"/>

如何更改它以使其接受正整数或空?

<Runtime>1</Runtime>
<Runtime></Runtime> <-- This will currently fail -->

1 个答案:

答案 0 :(得分:0)

一种选择是:

<xs:element name="Runtime">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:pattern value="\d{1,}|"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>