473,480 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to write XML to a string

I have successfully been using XMLTextWriter to write XML to a file.

But how to I write XML to a string which I can then use to store in a
database?
Tosch
Nov 20 '05 #1
3 1240
Hi,
One option it to use the StringWriter as the base for your XmlTextWriter
(use the XmlTextWriter contructor that takes a TextWriter as its parameter).
After your are done with all your XML writing, simply call the ToString() on
the StringWriter to get the string representation of the XML.

"Tosch" <to**********@swissonline.ch> wrote in message
news:oo********************************@4ax.com...
I have successfully been using XMLTextWriter to write XML to a file.

But how to I write XML to a string which I can then use to store in a
database?
Tosch
Nov 20 '05 #2
Tosh,

In addition to Shiva, when it is a dataset it can easily with this, (The
same as Shiva said with a XML document, however even shorter)

Serialize
\\\\
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.tostring
///
Deserialize
\\\
Dim sr As New System.IO.StringReader(mystring)
Dim ds2 As New DataSet
ds2.ReadXml(sr)
///
I hope this helps a little bit?

Cor
But how to I write XML to a string which I can then use to store in a
database?
Tosch

Nov 20 '05 #3
Tosch,
As the others have suggested, you can use a StringWriter, however be careful
as the StringWriter will assume UTF-16.

Dim buffer As New System.IO.StringWriter
Dim writer As New XmlTextWriter(buffer)

If you want or need the string stored in a different encoding (UTF-8) then
you may want to consider a MemoryStream instead... Or create a class that
inherits from StringWriterwhich overrides the StringWriter.Encoding property
and return the Encoding of your choice.

Hope this helps
Jay

"Tosch" <to**********@swissonline.ch> wrote in message
news:oo********************************@4ax.com...
I have successfully been using XMLTextWriter to write XML to a file.

But how to I write XML to a string which I can then use to store in a
database?
Tosch

Nov 20 '05 #4

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

Similar topics

0
1734
by: hari krishna | last post by:
hi all, My requirement is to generate xl reports throu Asp.Net without installing xl on web server computer. i am using Response object and wrtifile method as below. i dont know whether it is...
4
2929
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
9
8262
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
3
15652
by: Mads Westen | last post by:
Hi, I'm making some changes to my program, because I need to write with Codepage 850. Before I used FileStream, but I found code to use with StreamWriter instead. My problem is, that I don't...
5
3633
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
11
16188
by: Vmusic | last post by:
Hi, I am trying to write out an array of string variables to Notepad. I can't get SendKeys to accept the string variable only literal quoted strings. I DO NOT want the hassle of writing to a...
0
3540
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
0
789
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
14027
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
8
28305
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found...
0
6915
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
7097
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
6993
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...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.