Simple question about ReadXml and WriteXml

T

Tony Johansson

Hello!

Assume the following :
1. I create a DataSet with some DataRelation.
2. I then use WriteXml to write the DataSet to an Xml document using
DataRelation.Nested = True
3.I then read the Xml document using ReadXml to load and create a DataSet.

Now to my question is this DataSet that was created from 3 the same DataSet
with the same structure
that existed when I wrote down using WriteXml using point 2 above.

//Tony
 
A

Alberto Poblacion

Tony Johansson said:
Assume the following :
1. I create a DataSet with some DataRelation.
2. I then use WriteXml to write the DataSet to an Xml document using
DataRelation.Nested = True
3.I then read the Xml document using ReadXml to load and create a DataSet.

Now to my question is this DataSet that was created from 3 the same
DataSet
with the same structure
that existed when I wrote down using WriteXml using point 2 above.

In step 3 you will only be sure to get an accurate duplicate of the
schema of the original dataset if you use the "WriteSchema" option when you
do the WriteXml in step 2:

myDataSet.WriteXml("file.xml", XmlWriteMode.WriteSchema);

This adds an xsd schema at the beginning of the written file, which can
then be used by ReadXml to reconstruct the original schema before loading
the data that follow. You can open the file with an editor to verify whether
the DataRelation does make its way into the schema (I believe it does).
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello!

Assume the following :
1. I create a DataSet with some DataRelation.
2. I then use WriteXml to write the DataSet to an Xml document using
DataRelation.Nested = True
3.I then read the Xml document using ReadXml to load and create a DataSet..

Now to my question is this DataSet that was created from 3 the same DataSet
with the same structure
that existed when I wrote down using WriteXml using point 2 above.

//Tony

IIRC you will have the exact same dataset. the only difference is how
the rows of the child table are created. If nested=true they are
embedded in the parent table.

honestly unless you will use the XML generated file in any other way I
would set nested to false
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top