Mega Code Archive

 
Categories / VB.Net / XML
 

XElement WriteTo writes this element to an XmlWriter

Imports System Imports System.IO Imports System.Text Imports System.Xml Imports System.Xml.XPath Public Class MainClass     Public 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 content</GrandChild>                 </Child>             child1.WriteTo(xw)             Dim child2 As XElement = _                  <AnotherChild>                     <GrandChild>different content</GrandChild>                 </AnotherChild>             child2.WriteTo(xw)             xw.WriteEndElement()         End Using                  Console.WriteLine(sb.ToString())     End Sub End Class