XDocument.Save (TextWriter, SaveOptions) serialize this XDocument to a TextWriter, optionally disabling formatting.
Imports System
Imports System.Text
Imports System.Xml
Imports System.Xml.XPath
Imports System.IO
Public Class MainClass
Public Shared Sub Main()
Dim doc As XDocument = _
<?xml version="1.0" encoding="utf-8"?>
<Root><Child>content</Child></Root>
Dim sb1 As StringBuilder = New StringBuilder()
Using sr1 = New StringWriter(sb1)
doc.Save(sr1, SaveOptions.None)
Console.WriteLine(sb1.ToString())
End Using
Dim sb2 As StringBuilder = New StringBuilder()
Using sr2 = New StringWriter(sb2)
doc.Save(sr2, SaveOptions.DisableFormatting)
Console.WriteLine(sb2.ToString())
End Using
End Sub
End Class
Related examples in the same category