C# 添加编码声明
我得到运行时错误。请帮忙C# 添加编码声明,c#,C#,我得到运行时错误。请帮忙 XmlDocument doc = new XmlDocument(); XmlDeclaration decNode = doc.CreateXmlDeclaration("1.0", ENCODING, string.Empty); XmlAttribute encodeAttr = doc.CreateAttribute("encoding"); encodeAttr.InnerText = "utf-8"; decNode.Attributes.App
XmlDocument doc = new XmlDocument();
XmlDeclaration decNode = doc.CreateXmlDeclaration("1.0", ENCODING, string.Empty);
XmlAttribute encodeAttr = doc.CreateAttribute("encoding");
encodeAttr.InnerText = "utf-8";
decNode.Attributes.Append(encodeAttr);
doc.AppendChild(decNode);
doc.AppendChild(decNode);
我在你的代码中除了编码没有看到任何东西。您可以像这样传递null
XmlDeclaration decNode = doc.CreateXmlDeclaration("1.0", null, null);
或者,如果要指定一个,可以从中使用一个
你的错误是什么?
XmlDeclaration decNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);