By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,309 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,309 IT Pros & Developers. It's quick & easy.

Deleting XML Record from Dataset removing table?

P: n/a
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.
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"John" <jr***@patmedia.net> wrote in message news:eE*************@TK2MSFTNGP09.phx.gbl...
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
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.