PC Review


Reply
Thread Tools Rate Thread

Deserializing DataSet With White Space - How To?

 
 
Tom Jastrzebski
Guest
Posts: n/a
 
      12th Jun 2005
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();

}
}


 
Reply With Quote
 
 
 
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      12th Jun 2005
Tom,

Look up "DatasetSurrogate" - that does not have this issue, and it will work
with .NET 1.1 (plus it has a few other advantages like much better
performance).

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Tom Jastrzebski" <(E-Mail Removed)> wrote in message
news:M0Qqe.8283$(E-Mail Removed)...
> 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();
>
> }
> }
>
>



 
Reply With Quote
 
Tom Jastrzebski
Guest
Posts: n/a
 
      14th Jun 2005
Sahil,

Thank you for your answer.
However, I am not sure it helps solves my problem. It looks like
DatasetSurrogate is designed to serialize data to/from binary format, while
I am only interested in XML. Am I missing something?

Tom


"Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Tom,
>
> Look up "DatasetSurrogate" - that does not have this issue, and it will
> work with .NET 1.1 (plus it has a few other advantages like much better
> performance).
>
> - Sahil Malik [MVP]
> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
> ----------------------------------------------------------------------------
>
> "Tom Jastrzebski" <(E-Mail Removed)> wrote in message
> news:M0Qqe.8283$(E-Mail Removed)...
>> 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();
>>
>> }
>> }
>>
>>

>
>



 
Reply With Quote
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      14th Jun 2005
Actually you aren't missing anything. I figured that due to the
serialization/deserialization process your data is getting mangled - which
the datasetsurrogate will prevent. But I think you want the final output as
XML - right?

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Tom Jastrzebski" <(E-Mail Removed)> wrote in message
news:3gpre.773$(E-Mail Removed)...
> Sahil,
>
> Thank you for your answer.
> However, I am not sure it helps solves my problem. It looks like
> DatasetSurrogate is designed to serialize data to/from binary format,
> while I am only interested in XML. Am I missing something?
>
> Tom
>
>
> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Tom,
>>
>> Look up "DatasetSurrogate" - that does not have this issue, and it will
>> work with .NET 1.1 (plus it has a few other advantages like much better
>> performance).
>>
>> - Sahil Malik [MVP]
>> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
>> ----------------------------------------------------------------------------
>>
>> "Tom Jastrzebski" <(E-Mail Removed)> wrote in message
>> news:M0Qqe.8283$(E-Mail Removed)...
>>> 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();
>>>
>>> }
>>> }
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Tom Jastrzebski
Guest
Posts: n/a
 
      14th Jun 2005
Right, my data hast to be serialized to XML - that's a requirement.
What causes the problem is actually deserialization, rather than
serialization.
I guess it is one of those bugs which will never be fixed due to low
exposure.

Tom


"Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Actually you aren't missing anything. I figured that due to the
> serialization/deserialization process your data is getting mangled - which
> the datasetsurrogate will prevent. But I think you want the final output
> as XML - right?
>
> - Sahil Malik [MVP]
> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
> ----------------------------------------------------------------------------
>
> "Tom Jastrzebski" <(E-Mail Removed)> wrote in message
> news:3gpre.773$(E-Mail Removed)...
>> Sahil,
>>
>> Thank you for your answer.
>> However, I am not sure it helps solves my problem. It looks like
>> DatasetSurrogate is designed to serialize data to/from binary format,
>> while I am only interested in XML. Am I missing something?
>>
>> Tom
>>
>>
>> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Tom,
>>>
>>> Look up "DatasetSurrogate" - that does not have this issue, and it will
>>> work with .NET 1.1 (plus it has a few other advantages like much better
>>> performance).
>>>
>>> - Sahil Malik [MVP]
>>> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
>>> ----------------------------------------------------------------------------
>>>
>>> "Tom Jastrzebski" <(E-Mail Removed)> wrote in message
>>> news:M0Qqe.8283$(E-Mail Removed)...
>>>> 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();
>>>>
>>>> }
>>>> }
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      14th Jun 2005
I think this is a hard problem to solve. I believe SQL Server,
XmlSerialization etc - all just ignore whitespace, but in those there are
methods to tell not to discard whitespace, I am not quite sure what you'd
have to do with a Dataset.

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------
---------------

"Tom Jastrzebski" <(E-Mail Removed)> wrote in message
news:ndtre.814$(E-Mail Removed)...
> Right, my data hast to be serialized to XML - that's a requirement.
> What causes the problem is actually deserialization, rather than
> serialization.
> I guess it is one of those bugs which will never be fixed due to low
> exposure.
>
> Tom
>
>
> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Actually you aren't missing anything. I figured that due to the
> > serialization/deserialization process your data is getting mangled -

which
> > the datasetsurrogate will prevent. But I think you want the final output
> > as XML - right?
> >
> > - Sahil Malik [MVP]
> > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync

>
> --------------------------------------------------------------------------

--
> >
> > "Tom Jastrzebski" <(E-Mail Removed)> wrote in message
> > news:3gpre.773$(E-Mail Removed)...
> >> Sahil,
> >>
> >> Thank you for your answer.
> >> However, I am not sure it helps solves my problem. It looks like
> >> DatasetSurrogate is designed to serialize data to/from binary format,
> >> while I am only interested in XML. Am I missing something?
> >>
> >> Tom
> >>
> >>
> >> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>> Tom,
> >>>
> >>> Look up "DatasetSurrogate" - that does not have this issue, and it

will
> >>> work with .NET 1.1 (plus it has a few other advantages like much

better
> >>> performance).
> >>>
> >>> - Sahil Malik [MVP]
> >>> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync

>
>>> ------------------------------------------------------------------------

----
> >>>
> >>> "Tom Jastrzebski" <(E-Mail Removed)> wrote in message
> >>> news:M0Qqe.8283$(E-Mail Removed)...
> >>>> 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();
> >>>>
> >>>> }
> >>>> }
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Deserializing DataSet Schema When Enum Column Uses Default Value PeterWellington Microsoft Dot NET 9 11th Mar 2006 08:11 AM
deserializing a dataset into a class, is it possible? Greg Merideth Microsoft C# .NET 0 16th Aug 2004 10:26 PM
Serializing-Deserializing Extended Dataset Javed Microsoft ADO .NET 3 15th Jul 2004 08:10 PM
Serializing/Deserializing a typed DataTable existing in a DataSet Venugopal Mallarapu Microsoft ADO .NET 1 4th Dec 2003 09:18 AM
How to maintain XML element sequence when serializing/deserializing using DataSet Atul Agarwal Microsoft ADO .NET 2 17th Nov 2003 05:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 PM.