473,498 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use C# to write an xml document to MemoryStream, not a file?

I'm using XmlTextWriter now, but it seems it can just be used to create a
xml file, how can I do?
Thanks in advance!
Jackfan
Nov 12 '05 #1
2 36129
Jackfan wrote:
I'm using XmlTextWriter now, but it seems it can just be used to create a
xml file, how can I do?


MemoryStream ms = new MemoryStream();
XmlWriter w = new XmlTextWriter(ms, Encoding.UTF8);
w.WriteStartDocument();
w.WriteElementString("foo", "", "bar");
w.WriteEndDocument();
w.Close();

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
>I'm using XmlTextWriter now, but it seems it can just be used to create a
xml file, how can I do?


Just create the XmlTextWriter to use a STREAM instead of a file -
that's all.

MemoryStream stmMemory = new MemoryStream();
XmlTextWriter oXTW = new XmlTextWriter(stmMemory, Encoding.UTF8);

That's all there is!

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 12 '05 #3

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

Similar topics

3
15416
by: Cesar Andres Roldan Garcia | last post by:
Hi I'm trying to write an hexadecimal file... I mean not a text plain... I have to convert a float decimal number in float hexadecimal one, and that's done. That number is the one I'm gonna...
7
2709
by: Bob | last post by:
Hi, I am trying to use BULK INSERT with format file. All of our data has few bytes of header in the data file which I would like to skip before doing BULK INSERT. Is it possible to write...
20
5552
by: cylin | last post by:
Dear all, I open a binary file and want to write 0x00040700 to this file. how can I set write buffer? --------------------------------------------------- typedef unsigned char UCHAR; int...
2
8215
by: Tom | last post by:
Anytime someone wants to open a document, they have to first save it to disk. They cannot simply choose "open". If a user attempts to open the document, they are met with the error message "there was...
3
8804
by: broli85 | last post by:
I am writing an extension for Firefox 1.5. I would like to know if there is a way to write and read data to and from a file which is in the location of the extension (or somewhere in the user's...
5
4843
by: JonathanB | last post by:
Ok, so this is the scenario. I need to create a simple, no-frills XML editor for non-technical users. It doesn't have to do anything fancy, what I want is a series of text boxes with the text...
2
11310
by: =?Utf-8?B?RGFtZW9u?= | last post by:
Hi - I am attempting to write lines to a file at high volume, multiple threads. Here is my scenario: (initial "WriteToFile" object created via a parent multithreaded process, which receives...
5
1414
by: sangith | last post by:
Hi, I have a file which is in the following format: This file is classify.txt #######Alphabets######### . . . #######Numbers##########
16
4649
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
1
2217
kirubagari
by: kirubagari | last post by:
Im having issue whereby i have to filter out the data and stored in abnormal log file.my code as below and i have attach the file to give the clearer picture of the scenario.I need to filter the data...
0
7125
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
7167
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
7208
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
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
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
3095
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
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.