Search code examples
xmlxsdxml-validation

How do I define an element that can either contain an integer or nothing at all?


The question says it all! I want to have an XSD definition that makes it either possible to create an element like this

<Element>12345</Element>

or like this

<Element></Element>

How do I do that?

I already tried using the nillable attribute and changing the element's type to xs:string but it didn't work.


Solution

  • I solved my problem creating a xs:simpleType and a xs:restriction with base xs:string concerning the xs:minLength with a value of 1.

    <xs:simpleType name="type">
        <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
        </xs:restriction>
     </xs:simpleType>