XNode.WriteTo writes this node to an XmlWriter.
Imports System Imports System.Text Imports System.Xml Imports System.Xml.Schema Class MainClass Shared Sub Main() Dim sb As StringBuilder = New StringBuilder() Dim xws As XmlWriterSettings = New XmlWriterSettings() xws.OmitXmlDeclaration = True xws.Indent = True Using xw = XmlWriter.Create(sb, xws) xw.WriteStartElement("Root") Dim child1 As XElement = <Child> <GrandChild>some</GrandChild> </Child> child1.WriteTo(xw) Dim child2 As XElement = <AnotherChild> <GrandChild>different</GrandChild> </AnotherChild> child2.WriteTo(xw) xw.WriteEndElement() End Using Console.WriteLine(sb.ToString()) End Sub End Class