none
How can I set minOccurs="1" with out nillable="true" appear in XSD. RRS feed

  • Question

  • Hi,

    I have tried to convert an existing XSD to XmlElementAttribute on a Schema-based development mode.

    I have found that exising XSD don't have nillable="true" but having minOccurs="1". To get the minOccurs="1", got a help online to set  [System.Xml.Serialization.XmlElementAttribute(IsNullable = true,  Form = System.Xml.Schema.XmlSchemaForm.Qualified, Order = 0)] on the public property.

    The minOccurs="1" has got the solution but waiting for a solution to remove nillable="true" in the below element.

     <s:element minOccurs="1" maxOccurs="1" name="Type" nillable="true" type="s:string" />

    I am using VS2010, C#.

    Thanks,

    Manoj

    Tuesday, December 17, 2013 11:35 AM

Answers

  • Hi Manoj K,

    The Nillable attribute behavior in XSD (xmlserialzation) element declaration actually conform to the serialization support provided by .NET Framework for XML data.

    When you specify the Nullable property to true (of XML serialization attribute), the minOccurs will automatically become 1. Otherwise, if the Nullable is set to false, the minOccurs will become 0. And Nullable=true only means that this property could be represented as an empty element (with no content or child element) and that is equal to non-reference on this property (for the .NET in-memory representation)

    #Nillable Attribute Binding Support
    http://msdn.microsoft.com/en-us/library/2b314yt2(v=vs.85).aspx


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Manoj K Tuesday, April 1, 2014 4:10 AM
    Wednesday, December 18, 2013 3:41 AM
    Moderator

All replies

  • Hi Manoj K,

    The Nillable attribute behavior in XSD (xmlserialzation) element declaration actually conform to the serialization support provided by .NET Framework for XML data.

    When you specify the Nullable property to true (of XML serialization attribute), the minOccurs will automatically become 1. Otherwise, if the Nullable is set to false, the minOccurs will become 0. And Nullable=true only means that this property could be represented as an empty element (with no content or child element) and that is equal to non-reference on this property (for the .NET in-memory representation)

    #Nillable Attribute Binding Support
    http://msdn.microsoft.com/en-us/library/2b314yt2(v=vs.85).aspx


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Manoj K Tuesday, April 1, 2014 4:10 AM
    Wednesday, December 18, 2013 3:41 AM
    Moderator
  • Thank you for your reply.

    I have tried the same and is getting the same.

    If I am not wrong, the XSD given by my client don't have the nillable="true/false" attribute but have minOccurs="1", whereas when I generate the WSDL from my code, I am getting the nillable="true" and minOccurs="1".

    Please guide me on this. Also, how can I hide the <s:element> and <s:complexType> of <s:schema> <wsdl:types> in the WSDL.

    To the basic of my issue, I have been given a WSDL and XSD from a third party and need to generate a Service. From the WSDL and XSD, I have generated the "Request" and "Response" contracts with XmlElementAttribute and MessageContractAttribute and operations with XmlSerializerFormatAttribute,OperationContractAttribute.

    I was able to test the application with a .Net web app. When I check the WSDL generated (auto), I have found that even tough there's a <s:import>, importing XSD with same namespace, it is showing the XSD related <s:element> in the WSDL which is not in the provided WSDL.

    Thanks,

    Manoj.

     

    Thursday, December 19, 2013 9:16 AM