We have an app that uses the XmlTextWriter to write XML to the local disk. It
works and it's great. Now they want to write it to the database instead. Is
there a way that I can just get the XML out of the XmlTextWriter? I looked at
the XmlTextWriter class and can't seem to figure out how to take the XML out
of it. I want to do this
dim x as string
x = XmlTextWriter.XML
Thanks in advance, Rob
Bjoern Hoehrmann - 31 Mar 2008 17:12 GMT
* SneakyMonki wrote in microsoft.public.dotnet.xml:
>We have an app that uses the XmlTextWriter to write XML to the local disk. It
>works and it's great. Now they want to write it to the database instead. Is
>there a way that I can just get the XML out of the XmlTextWriter? I looked at
>the XmlTextWriter class and can't seem to figure out how to take the XML out
>of it.
Instead of writing to a file, write to a MemoryStream or equivalent. The
Writer does not buffer the generated XML code, so that is the only way.

Signature
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Alex Meleta - 31 Mar 2008 17:14 GMT
Hi SneakyMonki,
You can do it by writing to the other buffer.
StringBuilder output = new StringBuilder();
XmlTextWriter writer = new XmlTextWriter(new StringWriter(output));
output,ToString() will contain your text then
Regards,
Alex Meleta
[Tech Blog: http://devkids.blogspot.com]
S> We have an app that uses the XmlTextWriter to write XML to the local
S> disk. It works and it's great. Now they want to write it to the
S> database instead. Is there a way that I can just get the XML out of
S> the XmlTextWriter? I looked at the XmlTextWriter class and can't seem
S> to figure out how to take the XML out of it. I want to do this
S>
S> dim x as string
S> x = XmlTextWriter.XML
S> Thanks in advance, Rob
S>
Bjoern Hoehrmann - 31 Mar 2008 18:36 GMT
* Alex Meleta wrote in microsoft.public.dotnet.xml:
>You can do it by writing to the other buffer.
>StringBuilder output = new StringBuilder();
>XmlTextWriter writer = new XmlTextWriter(new StringWriter(output));
You need to pay special attention to character encoding issues in
that case though, like correcting the XML declaration as necessary.

Signature
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/