无序XML整理

以下代码能将无序XML内容整理成有序的XML

public static string GetSendXml(string strXml)
{
  var doc = new XmlDocument();
  doc.LoadXml(strXml);

  using (var sw = new StringWriter())
  using (var writer = new XmlTextWriter(sw))
  {
    writer.Indentation = 2; // the Indentation
    writer.Formatting = Formatting.Indented;
    doc.WriteContentTo(writer);
    return sw.ToString();  // 返回格式化后有序的XML
  }
}

posted @ 2017-09-07 15:54  Matrix博客园  阅读(389)  评论(0编辑  收藏  举报