【发布时间】:2009-10-09 11:57:42
【问题描述】:
为什么下面的代码没有设置 XML 声明编码类型?它总是将编码设置为 utf-16。我是否遗漏了一些非常明显的东西?
var xdoc = new XDocument(
new XDeclaration("1.0", "iso-8859-1", null),
new XElement("root", "")
);
输出:
<?xml version="1.0" encoding="utf-16"?>
<root></root>
【问题讨论】:
-
检查您正在使用的
TextWriter的编码。见here。如果上面的链接不起作用,Google cache version 可能仍然可用here。
标签: c# xml encoding linq-to-xml