c# - 如何在使用 LINQ 创建的 xml 中将编码作为 ISO-8859-1

标签 c# xml linq-to-xml xml-encoding

我必须创建一个编码为

的 xml 文件
<?xml version="1.0" encoding="ISO-8859-1"?>

目前我使用 LINQ 创建的 xml 的标记为

<?xml version="1.0" encoding="UTF-8"?>

我怎样才能只使用 LINQ 来做到这一点。

最佳答案

你应该使用XDeclaration:

var d = new XDocument(new XDeclaration("1.0", "ISO-8859-1", ""), new XElement("Root",
    new XElement("Child1", "data1"),
    new XElement("Child2", "data2")
 ));

关于c# - 如何在使用 LINQ 创建的 xml 中将编码作为 ISO-8859-1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24139127/

相关文章:

c# - 出于性能考虑更新 N 行

c# - 选项卡控件,垂直对齐的选项卡和垂直对齐的文本

c# - ffmpeg 使用 c# avformat_open 运行失败

c# - 我什么时候应该读一个文件,什么时候应该逐行阅读?

xml - Bash 将子节点插入到 XML 文件

xml - JUnit 4 结果到 XML 的转换

xml - 使用 XSL 替换默认命名空间

c# - LINQ To XML 中的“Where”子句未选择任何内容

c# - Linq to XML 未获取所有节点

c# - 将 90000 个 XElement 添加到 XDocument