Esempio n. 1
0
        private static string FormatXml(System.Xml.XmlDocument xmlDoc)
        {
            try
            {
                System.IO.StringWriter sw = new System.IO.StringWriter();
                using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(sw))
                {
                    //与xml序列化返回相同的encoding
                    writer.Indentation = 2;  // the Indentation
                    writer.Formatting = System.Xml.Formatting.Indented;
                    xmlDoc.WriteContentTo(writer);
                    writer.Close();
                }
                return sw.ToString();
            }
            catch
            {
                throw;
            }

        }
	    /// <summary>
		/// Writes the single files.
		/// </summary>
		/// <param name="document">The document.</param>
		/// <param name="filename">The filename.</param>
		private void WriteSingleFiles(System.Xml.XmlDocument document, string filename)
		{
			try
			{
				//document.Save(filename);
				XmlTextWriter writer = new XmlTextWriter(filename, System.Text.Encoding.UTF8);
				writer.Formatting = Formatting.None;
				document.WriteContentTo( writer );
				writer.Flush();
				writer.Close();
			}
			catch(Exception)
			{
				throw;
			}
		}