xml and xml schema

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
 
A

Arne Vajhøj

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
 
T

Tony Johansson

Arne Vajhøj said:
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
 
A

Arne Vajhøj

Arne Vajhøj said:
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
 
P

Patrice

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 said:
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
 

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