Search code examples
xmlxsdxsd-validationxml-validationxsd-1.1

XSD enumeration plus empty string?


I have the XML node paymentStatus, and I just want to restrict it using these three entries 'approved', 'pending' and 'completed'. This field is optional and can also contain empty string.

 <xs:element name="paymentStatus" minOccurs="0">
           <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="completed"/>
              <xs:enumeration value="approved"/>
              <xs:enumeration value="pending"/>
            </xs:restriction>
         </xs:simpleType>
        </xs:element>
    </xs:sequence>

It is working fine for all cases but it is not allowing empty string. How can I achieve this?

<ns4:paymentStatus></ns4:paymentStatus>

Solution

  • Simply add an enumeration that allows the empty string:

    <xs:enumeration value=""/>