You must Sign In to post a response.
  • Category: ASP.NET

    How to declare optional date field in XSD

    Hi All,

    I was using XSD to validate my incoming XML elements. It was throwing Invalid date field error.

    Below XSD File

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.rg/2001/XMLSchema"
    xmlns:tns="http://xxxy/ervices/V0"
    targetNamespace="http://xxxy/ervices/V" elementFormDefault="qualified"
    attributeFormDefault="unqualified" >

    <xs:complexType name="FailType">
    <xs:sequence>
    <xs:element name="ConDt" type="xs:date" minOccurs="0" maxOccurs="1" nillable="true"/>
    <xs:element name="PreEn" type="xs:string" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>

    XML File

    <Pat xmlns="http://xxxy/ervices/V">
    <ConDt></ConDt>
    </Pat>

    Please help me to resolve this.
  • #763235
    Finally I found answer from google.

    Below code will allow us to declare optional date field in XSD file.

    <xs:element name="ConDt" maxOccurs="unbounded" minOccurs="0">
    <xs:simpleType>
    <xs:union>
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="0" />
    <xs:maxLength value="0" />
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleType>
    <xs:restriction base="xs:date" />
    </xs:simpleType>
    </xs:union>
    </xs:simpleType>
    </xs:element>


Sign In to post your comments