如下
XmlTextWriter xmlWriter = new XmlTextWriter(filename,null);//不添加utf-8 BOM
xmlWriter.Formatting = Formatting.Indented;
// This will output the XML declaration
xmlWriter.WriteStartDocument(true);//添加standalone="yes"
//xmlWriter.Formatting = Formatting.None;//这句让xml失去任何缩进等格式
xmlWriter.WriteStartElement("DocumentElement");
xmlWriter.WriteStartElement("Table");
//xmlWriter.WriteAttributeString("id", "01");//添加之后类似于xmlWriter.WriteElementString("Att1","value1");
xmlWriter.WriteElementString("Att2","value2");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
这样下来就是不带utf-8的,如果不添加下面这句xmlWriter.WriteStartDocument(true);//添加standalone="yes",那么文件头只有一个xml1.0的版本申明