T
Tony Johansson
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
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