locked
Purpose of using minOccurs and maxOccurs in WSDL ?

    Question

  • Hi All,

    I have the following web method in WSDL,

    - <s:element name="GetAllowedAreasResponse">
    - <s:complexType>
    - <s:sequence>
    - <s:element minOccurs="0" maxOccurs="1" name="GetAllowedAreasResponse">
    - <s:complexType>
    - <s:sequence>
      <s:any namespace="AllowedAreas" />
      </s:sequence>
      </s:complexType>
      </s:element>
      </s:sequence>
      </s:complexType>
      </s:element>
     
    what is the purpose of minOccurs and maxOccurs attributes ? Is it a mandetory attribute ?
     
    Regards,
    Kailai
    Monday, June 19, 2006 7:20 AM

All replies

  • minOccurs attributes indicates the minimum number of times the element must occur inside the parent element. maxOccurs as the name suggests defines the maximum number of times the element can occur. maxOccurs can specify "unbounded" to indicate infinite number of the elements. Hence as per the above schema, I can have two versions of XML instance:

    No GetAllowedAreasResponse inside the parent. Conforms to the maxOccurs="1"
    <GetAllowedAreasResponse>
      <GetAllowedAreasResponse>
         <someElement xmlns="AllowedAreas">value</someElement>
      </GetAllowedAreasResponse>

    </GetAllowedAreasResponse>

    No GetAllowedAreasResponse inside the parent. Conforms to the minOccurs="0"
    <GetAllowedAreasResponse>
    </GetAllowedAreasResponse>

    FAILS. Not conforms to the maxOccurs="1". Has more than one occurance of GetAllowedAreasResponse element inside parent.
    <GetAllowedAreasResponse>
      <GetAllowedAreasResponse></GetAllowedAreasResponse>
      <GetAllowedAreasResponse>
         <someElement xmlns="AllowedAreas">value</someElement>
      </GetAllowedAreasResponse>

    </GetAllowedAreasResponse>

    HTH

    Monday, June 19, 2006 9:23 AM