How can I force XDocument to output “UTF-8” in the declaration line?

前端 未结 3 1813
误落风尘
误落风尘 2020-12-20 13:46

The following code produces this output:



  
    

        
3条回答
  •  無奈伤痛
    2020-12-20 14:49

    You can use the following code as an example

    XDocument doc = GetXmlDoc();
    using (var stream = new MemoryStream())
    {
        doc.Save(stream, SaveOptions.DisableFormatting);
        var docBytes = stream.ToArray();
        File.WriteAllBytes("fileName.xml", docBytes);
    }
    

提交回复
热议问题