开发者

XML to String value

开发者 https://www.devze.com 2022-12-20 13:48 出处:网络
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开发者_如何学C my DB?

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开发者_如何学C my DB?

I am coding in VB.Net


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()


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().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号