Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to interpret default values of primitive types in XSD when minoccurs=0
    primarykey
    data
    text
    <p>Inside an xs:complexType, there are elements: </p> <p>Running .NET tools like SvcUtil.exe, you will get a class decorated with DataContractAttribute containing properties: public string RegistrationNumber {get;set;} public DateTime ExpiryDate {get;set;} public DateTime? RegistrationEndDate {get;set;}</p> <p>What puzzle me is: if the XML instance received does not contact these 3 elements, apparently default values will be used though default values are not explicitly defined in XSD. What default values for string and Datetime?</p> <p>To refresh my deem memory, I have a look at</p> <h1><a href="http://www.w3.org/TR/xmlschema-0/" rel="nofollow">http://www.w3.org/TR/xmlschema-0/</a></h1> <p>2.2.1</p> <h1>In summary, the differences between element and attribute defaults can be stated as: Default attribute values apply when attributes are missing, and default element values apply when elements are empty.</h1> <p>So what if the default value is no explicitly defined and an element is empty/absent?</p> <p>The standard does not seem to define for such scenario, but apparently this will be at the mercy of the implementation of the receiver. </p> <p>For data type like integer and boolean, the default values are obvious: 0 and false. Well defined since day 1 of electronic computing.</p> <p>But for string and datetime, the situation is a bit tricky, largely because different languages have different structures and conventions for string and datetime.</p> <p>Do you think my understanding is correct?</p> <p>In MSDN about DataMemberAttribute.EmitDefaultValue, there is a statement:</p> <p>"Setting the EmitDefaultValue property to false is not a recommended practice. It should only be done if there is a specific need to do so (such as for interoperability or to reduce data size). "</p> <p>Can you tell me why this is not a recommended practice? say, sound like MS recommend emitting every elements regardless if minOccurs=0 in XML message?</p> <p>Thanks</p> <p>Andy</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload