How to print <?xml version=“1.0”?> using XDocument

后端 未结 6 1051
暗喜
暗喜 2020-11-29 02:16

Is there any way to have an XDocument print the xml version when using the ToString method? Have it output something like this:

         


        
6条回答
  •  死守一世寂寞
    2020-11-29 02:54

    VB.NET Solution CODE

    Code

       Dim _root As XElement = 
       Dim _element1 As XElement = i am element one
       Dim _element2 As XElement = i am element one
       _root.Add(_element1)
       _root.Add(_element2)
       Dim _document As New XDocument(New XDeclaration("1.0", "UTF-8", "yes"), _root)
       _document.Save("c:\xmlfolder\root.xml")
    

    Output Note(please open output in notepad )

     
     
       i am element one
       i am element one
    
    

提交回复
热议问题