T
Tom Jastrzebski
Hello everybody,
It looks like this is a known problem, but I found no solution.
Deserialization of DataSet object from XML does not preserve white space.
The same code executed under .Net Framework 2.0 works, so apparently problem
got fixed. As a fix xml:space="preserve" attribute is being added where
appropriate.
Here are two questions:
1. Consequently, DataSet serialized under .Net Framework 2.0 does NOT
deserialize under 1.1. Is/will it be possible to maintain backwards
compatibility, so data can be exchanged between different versions of MS
..Net Framework?
2. More important to me right now: is there any way to deserialize Data set
from XML and preserve white space under .Net Famework 1.1?
Thanks,
Tom
Sample code demonstrating the problem - it passes under .Net 2.0 but fails
under 1.1
- btw, using XmlTextReader does not help
using System;
using System.Data;
using System.IO;
class Program
{
static void Main(string[] args)
{
DataSet ds1 = new DataSet();
DataTable dt = new DataTable();
ds1.Tables.Add(dt);
dt.Columns.Add("column1", typeof(string));
dt.Rows.Add(new object[] { " " }); // add row containing single
space
// serialize
MemoryStream ms = new MemoryStream();
ds1.WriteXml(ms);
// deserialize
ms.Position = 0;
DataSet ds2 = new DataSet();
ds2.ReadXml(ms);
string value = (string)ds2.Tables[0].Rows[0]["column1"];
if (value == " ") { // test if row contains single space
Console.WriteLine("passed");
} else {
Console.WriteLine("failed");
}
Console.Read();
}
}
It looks like this is a known problem, but I found no solution.
Deserialization of DataSet object from XML does not preserve white space.
The same code executed under .Net Framework 2.0 works, so apparently problem
got fixed. As a fix xml:space="preserve" attribute is being added where
appropriate.
Here are two questions:
1. Consequently, DataSet serialized under .Net Framework 2.0 does NOT
deserialize under 1.1. Is/will it be possible to maintain backwards
compatibility, so data can be exchanged between different versions of MS
..Net Framework?
2. More important to me right now: is there any way to deserialize Data set
from XML and preserve white space under .Net Famework 1.1?
Thanks,
Tom
Sample code demonstrating the problem - it passes under .Net 2.0 but fails
under 1.1
- btw, using XmlTextReader does not help
using System;
using System.Data;
using System.IO;
class Program
{
static void Main(string[] args)
{
DataSet ds1 = new DataSet();
DataTable dt = new DataTable();
ds1.Tables.Add(dt);
dt.Columns.Add("column1", typeof(string));
dt.Rows.Add(new object[] { " " }); // add row containing single
space
// serialize
MemoryStream ms = new MemoryStream();
ds1.WriteXml(ms);
// deserialize
ms.Position = 0;
DataSet ds2 = new DataSet();
ds2.ReadXml(ms);
string value = (string)ds2.Tables[0].Rows[0]["column1"];
if (value == " ") { // test if row contains single space
Console.WriteLine("passed");
} else {
Console.WriteLine("failed");
}
Console.Read();
}
}