Deleting XML Record from Dataset removing table?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi All,
When I delete the last record from my dataset and then WriteXML() to the
file; the Table itself, in the xml file, is removed. I need to prevent the
table structure from being deleted if there are no more records to be
written to the XML file from the Dataset.

Any ideas here,
John.
 
John said:
When I delete the last record from my dataset and then WriteXML() to the file; the Table itself, in the xml file, is removed. I
need to prevent the table structure from being deleted

There will be no records from the empty table in the data written to the
XML instance doc, that's correct, but the table structure still exists in the
schema. If you're taking this XML from one DataSet and reconstructing
the DataSet somewhere else, then having the schema definition present
should suffice as far as creating empty DataTables in the new DataSet.

You can include the schema in your XML by calling WriteTo( ) with the
XmlWriteMode.WriteSchema argument like this,

// Dump tables in data set (with schema) to stdout.
dataSet.WriteXml( Console.Out, XmlWriteMode.WriteSchema);

Were the DataSet's XML serializer to produce an empty row with
empty values in each column to persist the empty table's "structure,"
such XML in the instance document would be indistinguishable
from a real row - all of whose columns had empty string values.

While there may be kludges to arrive at a similar effect (for instance,
custom serialization/deserialization that embeds DataTable schema info
in a comment that you do on both sides), using the XML schema
definition is the best place to hold this metainformation.


Derek Harmon
 
Back
Top