Create XDocument class with the specified XDeclaration and content.
Imports System Imports System.IO Imports System.Xml Imports System.Xml.XPath Public Class MainClass Public Shared Sub Main() Dim srcTree As XDocument = _ <?xml version="1.0" encoding="utf-8" standalone="yes"?> <!--This is a comment--> <Root> <Child1>data1</Child1> <Child2>data2</Child2> <Child3>data3</Child3> <Child2>data4</Child2> <Info5>info5</Info5> <Info6>info6</Info6> <Info7>info7</Info7> <Info8>info8</Info8> </Root> Dim doc As XDocument = _ <?xml version="1.0" encoding="utf-8" standalone="yes"?> <!--This is a new comment--> <Root> <%= From el In srcTree.<Root>.Elements _ Where CStr(el).StartsWith("data") _ Select el %> </Root> doc.Save("Test.xml") Console.WriteLine(File.ReadAllText("Test.xml")) End Sub End Class