Search code examples
xmlxsdxsd-validationxml-validation

xsd empty string validation


Based on that xsd schema:

<xs:simpleType name="TextType">
    <xs:restriction base="xs:string">
        <xs:minLength value="1"/>
        <xs:maxLength value="50"/>
    </xs:restriction>
</xs:simpleType>
...
<xs:element maxOccurs="10" minOccurs="0" name="MyText" type="TextType"/>

should empty space values like this be valid or not and why?

<MyText>  </MyText>

Solution

  • Yes, it's valid. The value can be any string between 1-50 characters in length, and this is a string whose length is between those limits.

    If you want to eliminate whitespace before applying the length checks, you could consider using the xs:whiteSpace facet, or using a derived type such as xs:token.