XmlWriter encoding UTF-8 using StringWriter in C#

后端 未结 2 1893
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 16:37

I\'m using C# to output an xml file and Im trying to set the xml encoding value to UTF-8 but its currently outputting:


<         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-12 17:19

    Just use the output file name for the XmlWriter instead of the StringWriterWithEncoding:

    var settings = new XmlWriterSettings
    {
        Encoding = Encoding.UTF8,
        Indent = true
    };
    
    using (var writer = XmlWriter.Create(filePathName, settings))
    {
        ...
    

提交回复
热议问题