none
Force DataSet to Serialize Empty Fields RRS feed

  • Question

  •  

    Is there anyway to override the default behavior when Serializing a DataSet so that empty fields are NOT dropped?

     

    For example, if I create a new DataSet, and add a Table with 2 columns to that DataSet - upon Serializing to XML - the 2 column nodes only appear in the XML if they actually contain data.

     

    I need them to be present in the XML regardless of whether or not they contain data.

     

    Is this possible?

     

    Thanks-

     

    Friday, April 25, 2008 4:03 PM

Answers

  • Found a workaround..  there's probably a better solution, but you can conditionally set the column value to String.Empty and the empty node will be serialized and visible in the XML output.

     

    It's interesting that you can set a column value to null or "" and it will NOT be serialized.. the XML serializer will completely drop it..   but if you set it to String.Empty - it will be there.

     

     

     

    Friday, April 25, 2008 7:47 PM