On Thu, 28 Jun 2007 00:03:45 -0700, Marc Gravell <ma**********@gmail.com>
wrote:
Must it be a file? Perhaps use a MemoryStream - attach the writer to
this stream using the ctor. Later, simpy rewind the stream and Read()
it. Alternatively, if you just want the xml, consider using a
StringBuilder as the target - then just call ToString().
In addition to Marc's fine suggestion, you might also consider a
StringWriter, which wraps up a StringBuilder in a TextWriter, which you
can then use to construct your XmlTextWriter instance. Maybe this is what
he means by "consider using a StringBuilder as the target", since I don't
see any direct way to actually do that (that is, I don't see anything in
XmlTextWriter that takes a StringBuilder as a direct target).
The main advantage to using the StringWriter is that you have easier
access to the resulting XML text. If that's not of concern to you, then
the MemoryStream should work just fine.
Pete