Monday, March 26, 2012

Stringbuilder equivalent to XMLTextWriter?

I want to write an XML file but not to a file...just into memory, so I can
then pass it to a string and stick it in a database.

Seems that XMLtextWriter requires that I write to a filestream.

What I'm looking for is the ease of writing XML that XMLTextWriter has with
the ability to just write to memory like Stringbuilder can do. Is there such
a thing?

-Darrel> What I'm looking for is the ease of writing XML that XMLTextWriter has
> with the ability to just write to memory like Stringbuilder can do. Is
> there such a thing?

Hmm...I found this article:

http://www.15seconds.com/issue/050615.htm

Which mentions:

"the XmlWriter can generate its output as a disk file, a stream, a
StringBuilder or another writer instance."

So, it looks like it can generate a stringbuilder. I just need to find an
example of that... ;o)

-Darrel
> So, it looks like it can generate a stringbuilder. I just need to find an
> example of that... ;o)

A bit more digging and I think I've figure it out:

Dim sbXML As New System.Text.StringBuilder

Dim swXML As New System.IO.StringWriter(sbXML)

Dim twXML As New System.xml.XmlTextWriter(swXML)

-Darrel

0 comments:

Post a Comment