Sean P
Sean P

Reputation: 949

XML to String value

I use an XMLWriter to manually make an XML document. Is there a way to put that in string form so I can write it to my DB?

I am coding in VB.Net

Upvotes: 0

Views: 777

Answers (2)

Fredrik Mörk
Fredrik Mörk

Reputation: 158309

You can make it write to a StringBuilder:

StringBuilder sb = new StringBuilder():
using (var writer = XmlWriter.Create(sb))
{
    // write the xml
}

string writtenXml = sb.ToString();

In VB.NET:

Dim sb As New StringBuilder()

Using writer As XmlWriter = XmlWriter.Create(sb)
    ' write the xml '
End Using

Dim writtenXml As String = sb.ToString()

Upvotes: 5

Ian Jacobs
Ian Jacobs

Reputation: 5501

You have have your XmlWriter wrap a StringWriter. Then you process it as you already are. when you want to access the string itself call StringWriter.ToString().

Upvotes: 0

Related Questions