Groups | Blog | Home
all groups > dotnet xml > july 2004 >

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



Jackfan
7/20/2004 9:57:03 AM
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

Oleg Tkachenko [MVP]
7/20/2004 10:03:22 AM
[quoted text, click to view]

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]
Marc Scheuner [MVP ADSI]
7/20/2004 10:48:45 AM
[quoted text, click to view]

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!
AddThis Social Bookmark Button