System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(@"<Root><Version>1.0.0.0</Version><name></name><age></age></Root>");
//Create an XML declaration.
System.Xml.XmlDeclaration xmldecl;
xmldecl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
//Add the new node to the document.
System.Xml.XmlElement root = doc.DocumentElement;
doc.InsertBefore(xmldecl, root);
string aXMLPath = Environment.CurrentDirectory + "\\TEST.XML";
doc.Save(@aXMLPath);
生成的XML文件如下:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Version>1.0.0.0</Version>
<name>
</name>
<age>
</age