using System.Xml; XmlDocument doc = new XmlDocument(); doc.LoadXml(""); // Save the document to a file XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("output.xml", settings)) { doc.WriteTo(writer); }
using System.Xml; XmlDocument doc = new XmlDocument(); doc.LoadXml("Package library: System.Xml.XmlDocument is part of the .NET Framework Class Library. No additional package library is required."); // Serialize the document to a string string xmlString; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (StringWriter stringWriter = new StringWriter()) using (XmlWriter writer = XmlWriter.Create(stringWriter, settings)) { doc.WriteTo(writer); writer.Flush(); xmlString = stringWriter.GetStringBuilder().ToString(); }