473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Reading and Writing XML from a Dataset with Binary Data

Hi all,

I have a process, where I take a dataset from an SQL call, and need to write
an XML file from that dataset.

The data set can contain 10's of tables, each with 100's of rows, and I have
no way of knowing what the tables are, or what they contain.

I am currently using the Dataset.WriteXML method passing an XMLWriter.

This is all currently working.

However, I now have to do the same thing but some of the datasets contain
binary data. I have tried this with just a WriteXML and a ReadXML from the
containing dataset. But the dataset that is created that reads the XML, does
not contain the correct binary data.

I know it is possible to write binary data using the XMLWriter.WriteBase64
method, but that would mean I would need to code the entire dataset write
with individual XMLWriter.Writexxxxx methods, which I would like to avoid
doing.

Is there any way, using Dataset.WriteXML to have the binary data, written
out in Base64 automatically?

Possibly changing the actual data in the dataset prior to writing the XML,
or even if I really had to I could modify the output from SQL in some way.

As always, an and all help is appreciated, and thanks in advance for your
replies.

Simon.
Nov 12 '05 #1
4 7721
You might want to look into FOR XML clause if you are running MSSQL 2000 or
2005, this will do all the XML logic in the database instead, makeing it
somewhat easier for you.

"Simon" <s@v.c> skrev i melding
news:42***********************@ptn-nntp-reader01.plus.net...
Hi all,

I have a process, where I take a dataset from an SQL call, and need to
write an XML file from that dataset.

The data set can contain 10's of tables, each with 100's of rows, and I
have no way of knowing what the tables are, or what they contain.

I am currently using the Dataset.WriteXML method passing an XMLWriter.

This is all currently working.

However, I now have to do the same thing but some of the datasets contain
binary data. I have tried this with just a WriteXML and a ReadXML from the
containing dataset. But the dataset that is created that reads the XML,
does not contain the correct binary data.

I know it is possible to write binary data using the XMLWriter.WriteBase64
method, but that would mean I would need to code the entire dataset write
with individual XMLWriter.Writexxxxx methods, which I would like to avoid
doing.

Is there any way, using Dataset.WriteXML to have the binary data, written
out in Base64 automatically?

Possibly changing the actual data in the dataset prior to writing the XML,
or even if I really had to I could modify the output from SQL in some way.

As always, an and all help is appreciated, and thanks in advance for your
replies.

Simon.


Nov 12 '05 #2
Hi,

The writexml method will convert a byte array (binary data) to a
base64 string. Convert.FromBase64String will convert it back to an byte
array. Here is a link to a pocket pc app I wrote that retrieves an image
from an xml file. Hope that helps

http://www.thomscontent.com/willcode...magecolumn.zip
Ken
------------------------
"Simon" <s@v.c> wrote in message
news:42***********************@ptn-nntp-reader01.plus.net...
Hi all,

I have a process, where I take a dataset from an SQL call, and need to write
an XML file from that dataset.

The data set can contain 10's of tables, each with 100's of rows, and I have
no way of knowing what the tables are, or what they contain.

I am currently using the Dataset.WriteXML method passing an XMLWriter.

This is all currently working.

However, I now have to do the same thing but some of the datasets contain
binary data. I have tried this with just a WriteXML and a ReadXML from the
containing dataset. But the dataset that is created that reads the XML, does
not contain the correct binary data.

I know it is possible to write binary data using the XMLWriter.WriteBase64
method, but that would mean I would need to code the entire dataset write
with individual XMLWriter.Writexxxxx methods, which I would like to avoid
doing.

Is there any way, using Dataset.WriteXML to have the binary data, written
out in Base64 automatically?

Possibly changing the actual data in the dataset prior to writing the XML,
or even if I really had to I could modify the output from SQL in some way.

As always, an and all help is appreciated, and thanks in advance for your
replies.

Simon.

Nov 12 '05 #3
Thanks to both Inge, and Ken.

Inge, interesting I didn't know about the For XML clause in MSSQL. Could
prove usefull in the future.

Ken, thanks for the link, but I'm trying to just use the DataSet.WriteXml,
and ReadXml methods, as I don't want to run down all the columns, for each
table in the data set creating the elements by hand as it were.

I have solved this by preprocessing the dataset, and creating a secondary
column when binary data is encountered. I can then encode the second column
a base64, and remove the original column. Then do the reverse step in the
XML file input stage.

This then negates the need to read and write the manual XML writes, and it
is all now working.

Thanks again for your replies.
Simon.
"Simon" <s@v.c> wrote in message
news:42***********************@ptn-nntp-reader01.plus.net...
Hi all,

I have a process, where I take a dataset from an SQL call, and need to
write an XML file from that dataset.

The data set can contain 10's of tables, each with 100's of rows, and I
have no way of knowing what the tables are, or what they contain.

I am currently using the Dataset.WriteXML method passing an XMLWriter.

This is all currently working.

However, I now have to do the same thing but some of the datasets contain
binary data. I have tried this with just a WriteXML and a ReadXML from the
containing dataset. But the dataset that is created that reads the XML,
does not contain the correct binary data.

I know it is possible to write binary data using the XMLWriter.WriteBase64
method, but that would mean I would need to code the entire dataset write
with individual XMLWriter.Writexxxxx methods, which I would like to avoid
doing.

Is there any way, using Dataset.WriteXML to have the binary data, written
out in Base64 automatically?

Possibly changing the actual data in the dataset prior to writing the XML,
or even if I really had to I could modify the output from SQL in some way.

As always, an and all help is appreciated, and thanks in advance for your
replies.

Simon.

Nov 12 '05 #4
Hi Simon,

I am interested in the final code you used to solve your problem. I am
using a socket connection to receive XML files (text and images) into a
buffer which I convert to a string. I am using a XMLTextReader to read the
string into a dataset, well, I have been up to now. I want to know how you
encoded your byte array when first received (I used
System.Text.Encoding.ASCII.GetString up til now) The Base64 encoding works
wonderfully when only sending the pic (without any XML).

What I would like to do is store everything in my dataset, write the pics to
their separate files, and delete that column from the datatable.

Any help would be appreciated.

Thanks,
Mariza
"Simon" wrote:
Thanks to both Inge, and Ken.

Inge, interesting I didn't know about the For XML clause in MSSQL. Could
prove usefull in the future.

Ken, thanks for the link, but I'm trying to just use the DataSet.WriteXml,
and ReadXml methods, as I don't want to run down all the columns, for each
table in the data set creating the elements by hand as it were.

I have solved this by preprocessing the dataset, and creating a secondary
column when binary data is encountered. I can then encode the second column
a base64, and remove the original column. Then do the reverse step in the
XML file input stage.

This then negates the need to read and write the manual XML writes, and it
is all now working.

Thanks again for your replies.
Simon.
"Simon" <s@v.c> wrote in message
news:42***********************@ptn-nntp-reader01.plus.net...
Hi all,

I have a process, where I take a dataset from an SQL call, and need to
write an XML file from that dataset.

The data set can contain 10's of tables, each with 100's of rows, and I
have no way of knowing what the tables are, or what they contain.

I am currently using the Dataset.WriteXML method passing an XMLWriter.

This is all currently working.

However, I now have to do the same thing but some of the datasets contain
binary data. I have tried this with just a WriteXML and a ReadXML from the
containing dataset. But the dataset that is created that reads the XML,
does not contain the correct binary data.

I know it is possible to write binary data using the XMLWriter.WriteBase64
method, but that would mean I would need to code the entire dataset write
with individual XMLWriter.Writexxxxx methods, which I would like to avoid
doing.

Is there any way, using Dataset.WriteXML to have the binary data, written
out in Base64 automatically?

Possibly changing the actual data in the dataset prior to writing the XML,
or even if I really had to I could modify the output from SQL in some way.

As always, an and all help is appreciated, and thanks in advance for your
replies.

Simon.


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
4
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have...
3
by: Hanover | last post by:
I have looked fot his solution, but Im not sure what to search for. I have an asp.net based report. I need the user to be able to download an XML file of the results so they can use the data in...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
4
by: David | last post by:
Hi, (Sorry for duplicate post, finger trouble before I finished...) using C# 1.1 I am writing a winform app that collects a dataset from a webservice. At the same time I collect the data,...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
5
by: Lucvdv | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.