Element Mandatory declaration in XSD Schema

2.6k Views Asked by At

I want to know how to make the below fields as mandatory and optional field in xsd declaration.

In the AccDetailsRequest i want USERNAME and EMAIL as mandatory field and PHONE as optional field.

<xsd:element name="AccDetailsRequest">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="USERNAME" type="xsd:string"/>
            <xsd:element name="EMAIL" type="xsd:string"/>
            <xsd:element name="PHONE" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

</xsd:element> 

Appreciate your help

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

You should use minOccurs and maxOccurs. their default values are 1. try the following:

<xsd:element name="AccDetailsRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="USERNAME" type="xsd:string"/>
                <xsd:element name="EMAIL" type="xsd:string"/>
                <xsd:element name="PHONE" type="xsd:string" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>

    </xsd:element>