XElement.Save (String, SaveOptions) serialize element to a file, optionally disabling formatting.
Imports System Imports System.IO Imports System.Xml Imports System.Xml.XPath Public Class MainClass Public Shared Sub Main() Dim str As String Dim root As XElement = <Root><Child> Text </Child></Root> root.Save("Root.xml", SaveOptions.DisableFormatting) str = File.ReadAllText("Root.xml") Console.WriteLine(str) root.Save("Root.xml", SaveOptions.None) str = File.ReadAllText("Root.xml") Console.WriteLine(str) End Sub End Class