How do I write an XML string to a file?

前端 未结 4 1404
一生所求
一生所求 2020-12-06 04:20

I have a string and its value is:


    qwerty
    adsf 
    The text of the samp         


        
4条回答
  •  有刺的猬
    2020-12-06 04:53

    I know you said C# but have you tried VB.NET for XML Literals. Amazing stuff.

    Public Class Program
        Public Shared Sub Main()
            Dim myKeyBoardStyle = "dvorak"
    
            Dim myXML As XElement = 
                                    qwerty
                                    <%= myKeyBoardStyle.ToUpper() %>
                                        adsf
                                        The text of the sample element2
                                    
    
            Console.WriteLine(myXML.ToString())
    
            myXML.Save(".\fileFromXElement.xml")
        End Sub
    End Class
    

    Notice the neat element which injects the result of code in into the output:

    
    
                                    qwerty
                                    DVORAKadsfThe text of the sample element2
    

    snip [removed opinions]

提交回复
热议问题