using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml; namespace ConsoleApplication1 { class Program { public static void Main(string[] args) { var doc = new XmlDocument(); var stream = new MemoryStream(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootNode = doc.CreateElement("rexim"); rootNode.InnerText = "давлоыдаывалдыовадлы"; rootNode.SetAttribute("xmlns", "rexim:coding-team:test"); doc.InsertBefore(xmlDeclaration, doc.DocumentElement); doc.AppendChild(rootNode); XmlWriterSettings settings = new XmlWriterSettings() { Indent = true }; using( var writer = XmlWriter.Create(stream,settings)) { doc.Save(writer); } } } }