This is my sample XML Code:
@Kamal has given you basically right answer here. This is why - nillable
always seems to cause problems. Effectively, you can consider nillable
as meaning allow the xsi:nil
attribute on this element. The XML Schema spec describes nillable as an out of band signal - it's basically used to indicate NULL to databases.
What you want is an element that must be at least one character long as given by @Kamal
This was my favourite solution.
<xs:simpleType name="NonEmptyString">
<xs:restriction base="xs:string">
<xs:pattern value="[\s\S]*[^ ][\s\S]*"/>
</xs:restriction>
</xs:simpleType>
Try
<xs:element name="lastName" minOccurs="1" nillable="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
This is IMHO a better pattern:
<xs:simpleType name="NonEmptyString">
<xs:restriction base="xs:string">
<xs:pattern value="^(?!\s*$).+" />
</xs:restriction>
</xs:simpleType>
or
<xs:simpleType name="NonEmptyStringWithoutSpace">
<xs:restriction base="xs:string">
<xs:pattern value="\S+"/>
</xs:restriction>
</xs:simpleType>
<xsd:element name="lastName" type="NonEmptyString" nillable="false"/>
<xsd:simpleType name="NonEmptyString">
<xsd:restriction base="xs:string">
<xsd:minLength value="1" />
<xsd:pattern value=".*[^\s].*" />
</xsd:restriction>
</xsd:simpleType>