2013-08-16 29 views
-3

我收到運行時錯誤。請幫忙!添加編碼聲明

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); 
+2

什麼是你得到的錯誤? – PoweredByOrange

+1

什麼是編碼? – Ehsan

回答

1

我沒有看到你的代碼要比其它編碼任何東西。你可以通過它空這樣

XmlDeclaration decNode = doc.CreateXmlDeclaration("1.0", null, null); 

,或者如果要指定一個你可以使用一個從here

XmlDeclaration decNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);