类似如下就行
//初始化一个xml实例
XmlDocument myXmlDoc = new XmlDocument(); // 添加文档定义 myXmlDoc.AppendChild(myXmlDoc.CreateXmlDeclaration("1.0", "utf-8", "")); //生成根节点 XmlElement root = myXmlDoc.CreateElement("Computers"); //把根节点添加到xml文档里 myXmlDoc.AppendChild(root); myXmlDoc.Save("haha.xml");这样会直接将xml定位为<?xml version="1.0" encoding="UTF-8"?>