I’m receiving xml data in these two forms from an external company
<currencydate>20110910</currencydate>
<currencydate/>
I want to verify using a pattern that this date indeed has the format YYYYMMDD like this
<xs:element name="currencydate" type="dateType"/>
<xs:simpleType name="dateType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-2][0-9]{3}[0-1][0-9][0-3][0-9]"/>
</xs:restriction>
</xs:simpleType>
This works fine. But the validation breaks on the empty element
So I added the minOccurs like this
<xs:element name="currencydate" type="dateType" minOccurs="0"/>
No success so I added nillable
<xs:element name="currencydate" nillable="true" type="dateType" minOccurs="0"/>
No success, I guess the element is there so it checks the pattern. So I changed the pattern
<xs:pattern value="[0-2][0-9]{3}[0-1][0-9][0-3][0-9]|"/>
I only added the pipe indicating the value can be empty. But still no success.
So my question is: how can I check the data pattern but also allow the value
<currencydate/>
Please note I’m receiving this data from an external company which does not provide an xsd nor are they willing to change anything for me.
Did you already try
as suggested in how to validate empty string value tag in xsd?
I only tried it in VS 2010 Express but it seems to work even if a comment in the linked post tells otherwise.