このコードを使用できます-に基づいてXmlTextWriter class
XmlTextWriter textWriter = new XmlTextWriter("yourpath", null);
// Opens the document
textWriter.WriteStartDocument();
textWriter.WriteStartElement("root");
textWriter.WriteAttributeString("xmlns", "x", null, "urn:1");
// Write comments
textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
textWriter.WriteEndElement();
// Ends the document.
textWriter.WriteEndDocument();
// close writer
textWriter.Close();
リンク: http://msdn.microsoft.com/fr-fr/library/system.xml.xmltextwriter.aspx
LINQ To XML を使用することもできます
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("This is a test"),
new XElement("root")
);
var root = doc.CreateElement("Test");
....
リンク: http://msdn.microsoft.com/en-us/library/bb387098.aspx