473,545 Members | 2,582 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 36141
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(m s, Encoding.UTF8);
w.WriteStartDoc ument();
w.WriteElementS tring("foo", "", "bar");
w.WriteEndDocum ent();
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(s tmMemory, Encoding.UTF8);

That's all there is!

Marc

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

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

Similar topics

3
15441
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 write in the hex file... can anybody help me 'cause i don't know how python write an hex file! Thanks!
7
2711
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 format file to skip these few bytes of header before doing BULK INSERT? For example, I have a 1 GB data file with 1000 byte header. Except for first...
20
5560
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 iFD=open(szFileName,O_CREAT|O_BINARY|O_TRUNC|O_WRONLY,S_IREAD|S_IWRITE); UCHAR buffer; //??????????? write(iFD,buffer,5);...
2
8219
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 an error opening the document the file cannot be found". Here is my C# ASP.NET web code. I am running IE 6.0. Can anyone advise. ... First...
3
8810
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 harddisk, where I can store and retrieve some data). I tried to use a write function which I found in one of these threads and tried to give it...
5
4847
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 contents of the elements pre-printed. Then the users can type their changes into the text boxes and click submit and it will load the changes in. So here...
2
11317
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 files, can call custom code for each file received - much like BizTalk) 1. Receive multiple files, each file received creates a "WriteToFile" object
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
4666
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) free hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the PHP info below shows ... Test it at:...
1
2222
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 out from that file and write into the log file..Kindly help..can be done in c or sql query. ...
0
7682
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7780
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6009
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5351
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5069
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.