C# 任意键退出 和 XML 格式化输出函数


static void Main(string[] args)
{
    // Do your work here
    Console.WriteLine("\nPress any key to exit ...");
    Console.ReadKey(true);
}


protected string GetFormattedXml(string sUnformattedXml)
{
    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.LoadXml(sUnformattedXml);
    StringBuilder sbStringBuilder = new StringBuilder();
    StringWriter swStringWriter = new StringWriter(sbStringBuilder);
    XmlTextWriter xmlTextWriter = null;
    try
    {
        xmlTextWriter = new XmlTextWriter(swStringWriter);
        xmlTextWriter.Formatting = Formatting.Indented;
        xmlTextWriter.Indentation = 4;
        xmlTextWriter.IndentChar = ' ';
        xmlDocument.WriteTo(xmlTextWriter);
    }
    finally
    {
        if (xmlTextWriter != null)
        {
            xmlTextWriter.Close();
        }
    }
    return sbStringBuilder.ToString();
}



注:本文转载自:http://www.cnblogs.com/zhangqs008/archive/2012/03/23/2498390.html


展开阅读全文

没有更多推荐了,返回首页