For some reason I can’t quite get nillable to work correctly with the .Net schema validator. I’m trying to find a way to make a parent node optional but at the same time prevent an empty node from passing through the validator.
Here’s the current element validator:
<xs:element name="Dates" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="From" type="datetime" minOccurs="0" maxOccurs="1" />
<xs:element name="To" type="datetime" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
I’ve tried changing the Dates element to nillable=”false” but that doesn’t work — an empty node still makes it past the validator.
I’ve also tried changing all three element nodes to nillable=”false” — which works fine for detecting an empty parent node but results in both children becoming required nodes instead of remaining optional.
So am I missing something here? Yes, I can always just throw some code at it and make it work… but I’m betting that there’s a variation here in the schema declarations that will give me what I need.
The solution in your case is “multiple choice”:
valid documents
invalid document
The simple way
Where your only way of enforcing
<From />and<To />would be using a special namespace.