DataSet to XML - Skips if is Null value
-
I try to write down a DataSet to XML. In my dataset I have a row named fe_date (datetime) that sometimes is NULL. When i write the XML file it skips that row if it have a NULL value. How can I force the writer to write the element for fe_date even if it doesn't have a value? I've tried to use myDataSet.WriteXML() and with XmlSerializer() both with the same result.
-
I try to write down a DataSet to XML. In my dataset I have a row named fe_date (datetime) that sometimes is NULL. When i write the XML file it skips that row if it have a NULL value. How can I force the writer to write the element for fe_date even if it doesn't have a value? I've tried to use myDataSet.WriteXML() and with XmlSerializer() both with the same result.
I've never had to do this, but off the top of my head, it would probably require you supply custom serializer code in your object class to support this. Possibly adding an attribute to the tag. This same code would also supply the ability to interpret the XML and convert it back to an object. Take a look at this[^] for the idea. AFAIK, there is no way to tell the standard serializer to output empty tags. NULL is not really defined in XML, so it's no surprise that it won't output an empty tag set.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007