The following XSD should allow for an element called OnlyWhiteSpaceElement which has a required Name attribute, and can have only whitespace content:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="OnlyWhiteSpaceType">
<xs:simpleContent>
<xs:extension base="OnlyWhiteSpaceContentType">
<xs:attribute name="Name" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="OnlyWhiteSpaceContentType">
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="MyType">
<xs:sequence>
<xs:element name="OnlyWhiteSpaceElement" type="OnlyWhiteSpaceType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="MyXml" type="MyType">
</xs:element>
</xs:schema>
The XSD is in a file called Temp.XSD, and here is the XML that is validated by it.
<?xml version="1.0" encoding="utf-8"?>
<MyXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Temp.xsd">
<OnlyWhiteSpaceElement Name="MyOnlyWhiteSpaceElement">
</OnlyWhiteSpaceElement>
</MyXml>
However the validation fails. The end tag shows an error that reads
The 'OnlyWhiteSpaceElement' element is invalid - the value ' ' is invalid according to its datatype 'OnlyWhiteSpaceType' - the actual length is not equal to the specified length.
Can anyone see what I'm doing wrong?