472,129 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 35866
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

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.