Saving a Linq to Xml file as ANSI instead of UTF-8 in C# (Ivy)

点点圈 提交于 2019-12-01 07:33:43

XDocument.Save has a number of overloads.

Writing via a properly constructed XmlWriter allows us to choose the ASCII encoding.

var doc = XDocument.Parse( "<foo>&#160;bar&#7800;baz</foo>" );

XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new ASCIIEncoding();
using (var writer = XmlWriter.Create( "xelement.xml", settings )) {
    doc.Save( writer );
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!