469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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 35522
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Cesar Andres Roldan Garcia | last post: by
20 posts views Thread by cylin | last post: by
5 posts views Thread by JonathanB | last post: by
2 posts views Thread by =?Utf-8?B?RGFtZW9u?= | last post: by
16 posts views Thread by Hans Fredrik Nordhaug | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.