XmlManager.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using System.IO;
  8. using System.Reflection;
  9. namespace FileManager
  10. {
  11. public class XmlManager
  12. {
  13. #region 创建Xml文件,并创建根节点和属性
  14. /// <summary>
  15. /// 创建Xml文件,并创建根节点和属性
  16. /// </summary>
  17. /// <param name="xmlfullname">Xml文件的全路径</param>
  18. /// <param name="rootnode">根节点名</param>
  19. /// <param name="list_attributes">根节点的属性键值对</param>
  20. /// <returns></returns>
  21. public Boolean CreateXmlFile(String xmlfullname,String rootnode)
  22. {
  23. XmlDocument xmlDoc = new XmlDocument();
  24. //创建类型声明节点
  25. XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "");
  26. xmlDoc.AppendChild(node);
  27. //创建根节点
  28. XmlNode root = xmlDoc.CreateElement(rootnode);
  29. xmlDoc.AppendChild(root);
  30. try
  31. {
  32. xmlDoc.Save(xmlfullname);
  33. return true;
  34. }
  35. catch (Exception e)
  36. {
  37. //显示错误信息
  38. Console.WriteLine(e.Message);
  39. return false;
  40. }
  41. }
  42. #endregion
  43. }
  44. }