Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To remove the 'null' values (i.e., the values that have i:nil set to true), you need to set the "EmitDefaultValue" on the DataMemberAttribute of those data members to false. In the .NET Framework, types have a concept of default values. For example, for any reference type the default value is null, and for an integer type it is 0.</p> <p>Here's an example:</p> <pre><code>[DataContract] public class Employee { // The CLR default for as string is a null value. // This will be written as &lt;employeeName xsi:nill="true" /&gt; [DataMember] public string EmployeeName = null; // This will be written as &lt;employeeID&gt;0&lt;/employeeID&gt; [DataMember] public int employeeID = 0; // The next three will not be written because the EmitDefaultValue = false. [DataMember(EmitDefaultValue = false)] public string position = null; [DataMember(EmitDefaultValue = false)] public int salary = 0; [DataMember(EmitDefaultValue = false)] public int? bonus = null; // This will be written as &lt;targetSalary&gt;57800&lt;/targetSalary&gt; [DataMember(EmitDefaultValue = false)] public int targetSalary = 57800; } </code></pre> <p>I'd make sure you think carefully before you do this. The reason is that when EmitDefaultValue is set to false, it is represented in the schema as an annotation specific to Windows Communication Foundation (WCF). There is no interoperable way to represent this information. In particular, the "default" attribute in the schema is not used for this purpose, the minOccurs attribute is affected only by the IsRequired setting, and the nillable attribute is affected only by the type of the data member.</p> <p>As for removing the various other extraneous XML attributes, you can never <em>totally</em> remove it, but something like the following code may help you ensure that it is emitted only once at the top level:</p> <p>Notice how the highlighted namespace was defined five times, creating a lot of bloat when it could just be defined once at the top-level. To fix this issue, you can use the following code:</p> <pre><code>ser.WriteStartObject(writer, o); writer.WriteAttributeString("xmlns", "p", null, "some-reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally-long-namespace.com/"); ser.WriteObjectContent(writer, o); ser.WriteEndObject(writer); </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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