HighTechTalks DotNet Forums  

Saving dataset to XML and reading back gives different data

Dotnet XML microsoft.public.dotnet.xml


Discuss Saving dataset to XML and reading back gives different data in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Lucvdv
 
Posts: n/a

Default Saving dataset to XML and reading back gives different data - 12-18-2007 , 03:46 AM






This would better be described by 'serialization' than 'interop', but I
didn't find a newsgroup that seems closer on topic.

The problem in a few words: I save data with DataSet.WriteXML, but I get
different data back when I read it later with DataSet.ReadXml.



More detail:

I'm saving a dataset containing a single datatable to an XML file
(DataSet.WriteXml), and its schema to an xsd file (DataSet.WriteXmlSchema).

Then in another app, I load them back into a new empty dataset using
DataSet.readXmlSchema and DataSet.ReadXml. The schema is read first.


What's "special" is that one of the columns doesn't contain a simple text
or numeric data type, but binary data (an array of BYTE, currently fixed at
8 bytes for testing, it will be replaced by variable-length encrypted data
later).


When it is saved into the XML file, the binary data are automatically
encoded in Base64.

Now the problem is that when this is read back later, nothing gets decoded.
Instead of a copy of the original bytes I put in, I get a larger array with
the Base64 representation.



The schema as saved by WriteXmlSchema looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PasswordList" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="PasswordList" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="PasswordData">
<xs:complexType>
<xs:sequence>
<xs:element name="License" type="xs:base64Binary"
minOccurs="0" />
<xs:element name="Password" type="xs:base64Binary"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Some sample (test) data from the XML file:

<PasswordList>
<PasswordData>
<License>QjAwMDAwMg==</License>
<Password>dzB2KnQ3eGc=</Password>
</PasswordData>
<PasswordData>
<License>QjAwMzMwMA==</License>
<Password>Q0wuNko5VTQ=</Password>
</PasswordData>
.....

Reply With Quote
  #2  
Old   
Lucvdv
 
Posts: n/a

Default Re: Saving dataset to XML and reading back gives different data - 12-18-2007 , 04:04 AM






Sorry, forgot to specify: using VS2005 with all current updates, framework
2.0 SP1.

Reply With Quote
  #3  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: Saving dataset to XML and reading back gives different data - 12-18-2007 , 05:34 AM



"Lucvdv" <replace_name (AT) null (DOT) net> wrote

Quote:
This would better be described by 'serialization' than 'interop', but I
didn't find a newsgroup that seems closer on topic.

The problem in a few words: I save data with DataSet.WriteXML, but I get
different data back when I read it later with DataSet.ReadXml.



More detail:

I'm saving a dataset containing a single datatable to an XML file
(DataSet.WriteXml), and its schema to an xsd file
(DataSet.WriteXmlSchema).

Then in another app, I load them back into a new empty dataset using
DataSet.readXmlSchema and DataSet.ReadXml. The schema is read first.


What's "special" is that one of the columns doesn't contain a simple text
or numeric data type, but binary data (an array of BYTE, currently fixed
at
8 bytes for testing, it will be replaced by variable-length encrypted data
later).


When it is saved into the XML file, the binary data are automatically
encoded in Base64.

Now the problem is that when this is read back later, nothing gets
decoded.
Instead of a copy of the original bytes I put in, I get a larger array
with
the Base64 representation.



The schema as saved by WriteXmlSchema looks like this:

?xml version="1.0" encoding="utf-8"?
xs:schema id="PasswordList" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xs:element name="PasswordList" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true"
xs:complexType
xs:choice minOccurs="0" maxOccurs="unbounded"
xs:element name="PasswordData"
xs:complexType
xs:sequence
xs:element name="License" type="xs:base64Binary"
minOccurs="0" /
xs:element name="Password" type="xs:base64Binary"
minOccurs="0" /
/xs:sequence
/xs:complexType
/xs:element
/xs:choice
/xs:complexType
/xs:element
/xs:schema
What is the column.DataType of the byte[] column after you have called
ReadXmlSchema?
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer




Reply With Quote
  #4  
Old   
Lucvdv
 
Posts: n/a

Default Re: Saving dataset to XML and reading back gives different data - 12-18-2007 , 05:58 AM



On Tue, 18 Dec 2007 06:34:28 -0500, "John Saunders [MVP]" <john.saunders at
trizetto.com> wrote:

Quote:
"Lucvdv" <replace_name (AT) null (DOT) net> wrote in message
news:lq3fm3hf9e3m00jdmurkeskll1j72h68mu (AT) 4ax (DOT) com...

Then in another app, I load them back into a new empty dataset using
DataSet.readXmlSchema and DataSet.ReadXml. The schema is read first.

Now the problem is that when this is read back later, nothing gets
decoded.
Instead of a copy of the original bytes I put in, I get a larger array
with the Base64 representation.

What is the column.DataType of the byte[] column after you have called
ReadXmlSchema?
It's System.Byte[]

My original post was a little unclear about something when I re-read it
('one of the columns' wasn't accurate), so I'll fix that here: there are
two columns, each containing a byte array. The problem occurs for both.


Reply With Quote
  #5  
Old   
Lucvdv
 
Posts: n/a

Default Re: Saving dataset to XML and reading back gives different data - 12-18-2007 , 06:23 AM



On Tue, 18 Dec 2007 12:58:58 +0100, Lucvdv <replace_name (AT) null (DOT) net> wrote:

Quote:
On Tue, 18 Dec 2007 06:34:28 -0500, "John Saunders [MVP]" <john.saunders at
trizetto.com> wrote:

"Lucvdv" <replace_name (AT) null (DOT) net> wrote in message
news:lq3fm3hf9e3m00jdmurkeskll1j72h68mu (AT) 4ax (DOT) com...

Then in another app, I load them back into a new empty dataset using
DataSet.readXmlSchema and DataSet.ReadXml. The schema is read first.

Now the problem is that when this is read back later, nothing gets
decoded.
Instead of a copy of the original bytes I put in, I get a larger array
with the Base64 representation.

What is the column.DataType of the byte[] column after you have called
ReadXmlSchema?

It's System.Byte[]

My original post was a little unclear about something when I re-read it
('one of the columns' wasn't accurate), so I'll fix that here: there are
two columns, each containing a byte array. The problem occurs for both.

And now it gets really strange: I closed Visual Studio for my lunch break,
reopen it when I get back, and the problem is gone.

I now get the correct data. Where I got an array of 15 bytes containing
what looked like the BASE64 data plus a few extra before, I now get an
array of 8 bytes containing the correct data.



Reply With Quote
  #6  
Old   
Tony Gravagno
 
Posts: n/a

Default Re: Saving dataset to XML and reading back gives different data - 12-18-2007 , 01:41 PM



Lucvdv wrote:
Quote:
And now it gets really strange: I closed Visual Studio for my lunch break,
reopen it when I get back, and the problem is gone.
Which part is really strange - the part where you get a lunch break,
the part that you come back after lunch, or the part about the problem
being gone?

Tony Gravagno
Nebula Research and Development

Latest blog:
Stumped again - Strongly Typed Datasets from XML Schema
remove.munge.pleaseNebula-RnD.com/blog


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.