From: Tony Johansson on
Hi!

Here I have a method that serialize a DataSet to a file by using xml.
private void SerializeDataSet(string filename)
{
XmlSerializer ser = new XmlSerializer(typeof(DataSet));
DataSet ds = new DataSet("myDataSet");
DataTable dt = new DataTable("myTable");
DataColumn dc = new DataColumn("thing");
dt.Columns.Add(dc); //add DataColumn to DataTable
ds.Tables.Add(dt);
DataRow row;

for (int i = 0; i < 10; i++)
{
row = dt.NewRow();
row[0] = "Thing" + i;
dt.Rows.Add(row);
}

TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, ds);
writer.Close();
}

But when I look at it using Notepad it's a xml schema and here is how it
looks like. See below
I just wonder why has it been created an xml schema and not a normal xml
file?
I mean when I using Xml to serialize an object an Xml file is created with
the data within but now when I used a DataSet
an Xml schema was created insted. I'm very surprised ?

<?xml version="1.0" encoding="utf-8"?>
<DataSet>
<xs:schema id="myDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="myDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="myTable">
<xs:complexType>
<xs:sequence>
<xs:element name="thing" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<myDataSet>
<myTable diffgr:id="myTable1" msdata:rowOrder="0"
diffgr:hasChanges="inserted">
<thing>Thing0</thing>
</myTable>
<myTable diffgr:id="myTable2" msdata:rowOrder="1"
diffgr:hasChanges="inserted">
<thing>Thing1</thing>
</myTable>
<myTable diffgr:id="myTable3" msdata:rowOrder="2"
diffgr:hasChanges="inserted">
<thing>Thing2</thing>
</myTable>
<myTable diffgr:id="myTable4" msdata:rowOrder="3"
diffgr:hasChanges="inserted">
<thing>Thing3</thing>
</myTable>
<myTable diffgr:id="myTable5" msdata:rowOrder="4"
diffgr:hasChanges="inserted">
<thing>Thing4</thing>
</myTable>
<myTable diffgr:id="myTable6" msdata:rowOrder="5"
diffgr:hasChanges="inserted">
<thing>Thing5</thing>
</myTable>
<myTable diffgr:id="myTable7" msdata:rowOrder="6"
diffgr:hasChanges="inserted">
<thing>Thing6</thing>
</myTable>
<myTable diffgr:id="myTable8" msdata:rowOrder="7"
diffgr:hasChanges="inserted">
<thing>Thing7</thing>
</myTable>
<myTable diffgr:id="myTable9" msdata:rowOrder="8"
diffgr:hasChanges="inserted">
<thing>Thing8</thing>
</myTable>
<myTable diffgr:id="myTable10" msdata:rowOrder="9"
diffgr:hasChanges="inserted">
<thing>Thing9</thing>
</myTable>
</myDataSet>
</diffgr:diffgram>
</DataSet>

//Tony


From: Arne Vajhøj on
On 07-03-2010 10:46, Tony Johansson wrote:
> Here I have a method that serialize a DataSet to a file by using xml.
> private void SerializeDataSet(string filename)
> {
> XmlSerializer ser = new XmlSerializer(typeof(DataSet));
> DataSet ds = new DataSet("myDataSet");
> DataTable dt = new DataTable("myTable");
> DataColumn dc = new DataColumn("thing");
> dt.Columns.Add(dc); //add DataColumn to DataTable
> ds.Tables.Add(dt);
> DataRow row;
>
> for (int i = 0; i< 10; i++)
> {
> row = dt.NewRow();
> row[0] = "Thing" + i;
> dt.Rows.Add(row);
> }
>
> TextWriter writer = new StreamWriter(filename);
> ser.Serialize(writer, ds);
> writer.Close();
> }
>
> But when I look at it using Notepad it's a xml schema and here is how it
> looks like. See below
> I just wonder why has it been created an xml schema and not a normal xml
> file?
> I mean when I using Xml to serialize an object an Xml file is created with
> the data within but now when I used a DataSet
> an Xml schema was created insted. I'm very surprised ?
>
> <?xml version="1.0" encoding="utf-8"?>
> <DataSet>
> <xs:schema id="myDataSet" xmlns=""
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
> <xs:element name="myDataSet" msdata:IsDataSet="true"
> msdata:UseCurrentLocale="true">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element name="myTable">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="thing" type="xs:string" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:schema>
> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
> xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
> <myDataSet>
> <myTable diffgr:id="myTable1" msdata:rowOrder="0"
> diffgr:hasChanges="inserted">
> <thing>Thing0</thing>
> </myTable>
> <myTable diffgr:id="myTable2" msdata:rowOrder="1"
> diffgr:hasChanges="inserted">
> <thing>Thing1</thing>
> </myTable>
> <myTable diffgr:id="myTable3" msdata:rowOrder="2"
> diffgr:hasChanges="inserted">
> <thing>Thing2</thing>
> </myTable>
> <myTable diffgr:id="myTable4" msdata:rowOrder="3"
> diffgr:hasChanges="inserted">
> <thing>Thing3</thing>
> </myTable>
> <myTable diffgr:id="myTable5" msdata:rowOrder="4"
> diffgr:hasChanges="inserted">
> <thing>Thing4</thing>
> </myTable>
> <myTable diffgr:id="myTable6" msdata:rowOrder="5"
> diffgr:hasChanges="inserted">
> <thing>Thing5</thing>
> </myTable>
> <myTable diffgr:id="myTable7" msdata:rowOrder="6"
> diffgr:hasChanges="inserted">
> <thing>Thing6</thing>
> </myTable>
> <myTable diffgr:id="myTable8" msdata:rowOrder="7"
> diffgr:hasChanges="inserted">
> <thing>Thing7</thing>
> </myTable>
> <myTable diffgr:id="myTable9" msdata:rowOrder="8"
> diffgr:hasChanges="inserted">
> <thing>Thing8</thing>
> </myTable>
> <myTable diffgr:id="myTable10" msdata:rowOrder="9"
> diffgr:hasChanges="inserted">
> <thing>Thing9</thing>
> </myTable>
> </myDataSet>
> </diffgr:diffgram>
> </DataSet>

As far as I can see, then it is "a schema" bit "XML with a schema".

Where the schema is used to communicate the structure of the DataSet.

If I were to use XML serialization, then I would serialize a collection
(or an array) of custom classes not a DataSet !

Arne
From: Tony Johansson on
"Arne Vajh�j" <arne(a)vajhoej.dk> skrev i meddelandet
news:4b93d93d$0$278$14726298(a)news.sunsite.dk...
> On 07-03-2010 10:46, Tony Johansson wrote:
>> Here I have a method that serialize a DataSet to a file by using xml.
>> private void SerializeDataSet(string filename)
>> {
>> XmlSerializer ser = new XmlSerializer(typeof(DataSet));
>> DataSet ds = new DataSet("myDataSet");
>> DataTable dt = new DataTable("myTable");
>> DataColumn dc = new DataColumn("thing");
>> dt.Columns.Add(dc); //add DataColumn to DataTable
>> ds.Tables.Add(dt);
>> DataRow row;
>>
>> for (int i = 0; i< 10; i++)
>> {
>> row = dt.NewRow();
>> row[0] = "Thing" + i;
>> dt.Rows.Add(row);
>> }
>>
>> TextWriter writer = new StreamWriter(filename);
>> ser.Serialize(writer, ds);
>> writer.Close();
>> }
>>
>> But when I look at it using Notepad it's a xml schema and here is how it
>> looks like. See below
>> I just wonder why has it been created an xml schema and not a normal xml
>> file?
>> I mean when I using Xml to serialize an object an Xml file is created
>> with
>> the data within but now when I used a DataSet
>> an Xml schema was created insted. I'm very surprised ?
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <DataSet>
>> <xs:schema id="myDataSet" xmlns=""
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
>> <xs:element name="myDataSet" msdata:IsDataSet="true"
>> msdata:UseCurrentLocale="true">
>> <xs:complexType>
>> <xs:choice minOccurs="0" maxOccurs="unbounded">
>> <xs:element name="myTable">
>> <xs:complexType>
>> <xs:sequence>
>> <xs:element name="thing" type="xs:string" minOccurs="0"
>> />
>> </xs:sequence>
>> </xs:complexType>
>> </xs:element>
>> </xs:choice>
>> </xs:complexType>
>> </xs:element>
>> </xs:schema>
>> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
>> xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
>> <myDataSet>
>> <myTable diffgr:id="myTable1" msdata:rowOrder="0"
>> diffgr:hasChanges="inserted">
>> <thing>Thing0</thing>
>> </myTable>
>> <myTable diffgr:id="myTable2" msdata:rowOrder="1"
>> diffgr:hasChanges="inserted">
>> <thing>Thing1</thing>
>> </myTable>
>> <myTable diffgr:id="myTable3" msdata:rowOrder="2"
>> diffgr:hasChanges="inserted">
>> <thing>Thing2</thing>
>> </myTable>
>> <myTable diffgr:id="myTable4" msdata:rowOrder="3"
>> diffgr:hasChanges="inserted">
>> <thing>Thing3</thing>
>> </myTable>
>> <myTable diffgr:id="myTable5" msdata:rowOrder="4"
>> diffgr:hasChanges="inserted">
>> <thing>Thing4</thing>
>> </myTable>
>> <myTable diffgr:id="myTable6" msdata:rowOrder="5"
>> diffgr:hasChanges="inserted">
>> <thing>Thing5</thing>
>> </myTable>
>> <myTable diffgr:id="myTable7" msdata:rowOrder="6"
>> diffgr:hasChanges="inserted">
>> <thing>Thing6</thing>
>> </myTable>
>> <myTable diffgr:id="myTable8" msdata:rowOrder="7"
>> diffgr:hasChanges="inserted">
>> <thing>Thing7</thing>
>> </myTable>
>> <myTable diffgr:id="myTable9" msdata:rowOrder="8"
>> diffgr:hasChanges="inserted">
>> <thing>Thing8</thing>
>> </myTable>
>> <myTable diffgr:id="myTable10" msdata:rowOrder="9"
>> diffgr:hasChanges="inserted">
>> <thing>Thing9</thing>
>> </myTable>
>> </myDataSet>
>> </diffgr:diffgram>
>> </DataSet>
>
> As far as I can see, then it is "a schema" bit "XML with a schema".
>
> Where the schema is used to communicate the structure of the DataSet.
>
> If I were to use XML serialization, then I would serialize a collection
> (or an array) of custom classes not a DataSet !
>
> Arne

What do you mean by saying it's "a schema" bit "XML with a schema" ?

//Tony


From: Arne Vajhøj on
On 07-03-2010 11:58, Tony Johansson wrote:
> "Arne Vajh�j"<arne(a)vajhoej.dk> skrev i meddelandet
> news:4b93d93d$0$278$14726298(a)news.sunsite.dk...
>> On 07-03-2010 10:46, Tony Johansson wrote:
>>> Here I have a method that serialize a DataSet to a file by using xml.
>>> private void SerializeDataSet(string filename)
>>> {
>>> XmlSerializer ser = new XmlSerializer(typeof(DataSet));
>>> DataSet ds = new DataSet("myDataSet");
>>> DataTable dt = new DataTable("myTable");
>>> DataColumn dc = new DataColumn("thing");
>>> dt.Columns.Add(dc); //add DataColumn to DataTable
>>> ds.Tables.Add(dt);
>>> DataRow row;
>>>
>>> for (int i = 0; i< 10; i++)
>>> {
>>> row = dt.NewRow();
>>> row[0] = "Thing" + i;
>>> dt.Rows.Add(row);
>>> }
>>>
>>> TextWriter writer = new StreamWriter(filename);
>>> ser.Serialize(writer, ds);
>>> writer.Close();
>>> }
>>>
>>> But when I look at it using Notepad it's a xml schema and here is how it
>>> looks like. See below
>>> I just wonder why has it been created an xml schema and not a normal xml
>>> file?
>>> I mean when I using Xml to serialize an object an Xml file is created
>>> with
>>> the data within but now when I used a DataSet
>>> an Xml schema was created insted. I'm very surprised ?
>>>
>>> <?xml version="1.0" encoding="utf-8"?>
>>> <DataSet>
>>> <xs:schema id="myDataSet" xmlns=""
>>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
>>> <xs:element name="myDataSet" msdata:IsDataSet="true"
>>> msdata:UseCurrentLocale="true">
>>> <xs:complexType>
>>> <xs:choice minOccurs="0" maxOccurs="unbounded">
>>> <xs:element name="myTable">
>>> <xs:complexType>
>>> <xs:sequence>
>>> <xs:element name="thing" type="xs:string" minOccurs="0"
>>> />
>>> </xs:sequence>
>>> </xs:complexType>
>>> </xs:element>
>>> </xs:choice>
>>> </xs:complexType>
>>> </xs:element>
>>> </xs:schema>
>>> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
>>> xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
>>> <myDataSet>
>>> <myTable diffgr:id="myTable1" msdata:rowOrder="0"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing0</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable2" msdata:rowOrder="1"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing1</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable3" msdata:rowOrder="2"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing2</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable4" msdata:rowOrder="3"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing3</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable5" msdata:rowOrder="4"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing4</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable6" msdata:rowOrder="5"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing5</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable7" msdata:rowOrder="6"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing6</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable8" msdata:rowOrder="7"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing7</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable9" msdata:rowOrder="8"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing8</thing>
>>> </myTable>
>>> <myTable diffgr:id="myTable10" msdata:rowOrder="9"
>>> diffgr:hasChanges="inserted">
>>> <thing>Thing9</thing>
>>> </myTable>
>>> </myDataSet>
>>> </diffgr:diffgram>
>>> </DataSet>
>>
>> As far as I can see, then it is "a schema" bit "XML with a schema".
>>
>> Where the schema is used to communicate the structure of the DataSet.
>>
>> If I were to use XML serialization, then I would serialize a collection
>> (or an array) of custom classes not a DataSet !
>
> What do you mean by saying it's "a schema" bit "XML with a schema" ?

Too many thumbs on the keyboard.

it is not "a schema" but "XML with a schema"

Arne

From: Patrice on
A dataset stores arbitrary tables and their data. So writing some
information about those tables is needed. Actually as a DataSet was (is ?) a
privileged way to move db data back and forth, those xml features are also
exposed explictely. See :
http://msdn.microsoft.com/en-us/library/84sxtbxh(VS.80).aspx
for details...

--
Patrice

"Tony Johansson" <johansson.andersson(a)telia.com> a �crit dans le message de
news:eYiaF1gvKHA.4752(a)TK2MSFTNGP04.phx.gbl...
> Hi!
>
> Here I have a method that serialize a DataSet to a file by using xml.
> private void SerializeDataSet(string filename)
> {
> XmlSerializer ser = new XmlSerializer(typeof(DataSet));
> DataSet ds = new DataSet("myDataSet");
> DataTable dt = new DataTable("myTable");
> DataColumn dc = new DataColumn("thing");
> dt.Columns.Add(dc); //add DataColumn to DataTable
> ds.Tables.Add(dt);
> DataRow row;
>
> for (int i = 0; i < 10; i++)
> {
> row = dt.NewRow();
> row[0] = "Thing" + i;
> dt.Rows.Add(row);
> }
>
> TextWriter writer = new StreamWriter(filename);
> ser.Serialize(writer, ds);
> writer.Close();
> }
>
> But when I look at it using Notepad it's a xml schema and here is how it
> looks like. See below
> I just wonder why has it been created an xml schema and not a normal xml
> file?
> I mean when I using Xml to serialize an object an Xml file is created with
> the data within but now when I used a DataSet
> an Xml schema was created insted. I'm very surprised ?
>
> <?xml version="1.0" encoding="utf-8"?>
> <DataSet>
> <xs:schema id="myDataSet" xmlns=""
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
> <xs:element name="myDataSet" msdata:IsDataSet="true"
> msdata:UseCurrentLocale="true">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element name="myTable">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="thing" type="xs:string" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:schema>
> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
> xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
> <myDataSet>
> <myTable diffgr:id="myTable1" msdata:rowOrder="0"
> diffgr:hasChanges="inserted">
> <thing>Thing0</thing>
> </myTable>
> <myTable diffgr:id="myTable2" msdata:rowOrder="1"
> diffgr:hasChanges="inserted">
> <thing>Thing1</thing>
> </myTable>
> <myTable diffgr:id="myTable3" msdata:rowOrder="2"
> diffgr:hasChanges="inserted">
> <thing>Thing2</thing>
> </myTable>
> <myTable diffgr:id="myTable4" msdata:rowOrder="3"
> diffgr:hasChanges="inserted">
> <thing>Thing3</thing>
> </myTable>
> <myTable diffgr:id="myTable5" msdata:rowOrder="4"
> diffgr:hasChanges="inserted">
> <thing>Thing4</thing>
> </myTable>
> <myTable diffgr:id="myTable6" msdata:rowOrder="5"
> diffgr:hasChanges="inserted">
> <thing>Thing5</thing>
> </myTable>
> <myTable diffgr:id="myTable7" msdata:rowOrder="6"
> diffgr:hasChanges="inserted">
> <thing>Thing6</thing>
> </myTable>
> <myTable diffgr:id="myTable8" msdata:rowOrder="7"
> diffgr:hasChanges="inserted">
> <thing>Thing7</thing>
> </myTable>
> <myTable diffgr:id="myTable9" msdata:rowOrder="8"
> diffgr:hasChanges="inserted">
> <thing>Thing8</thing>
> </myTable>
> <myTable diffgr:id="myTable10" msdata:rowOrder="9"
> diffgr:hasChanges="inserted">
> <thing>Thing9</thing>
> </myTable>
> </myDataSet>
> </diffgr:diffgram>
> </DataSet>
>
> //Tony
>
>