/// <summary> /// 创建XmlDocument对象 /// </summary> /// <param name="xmlFilePathList">数据文件路径</param> /// <param name="xmlFileOpType">文件相关操作类型</param> /// <param name="datetime">账目年月</param> public XmlOperate(IList <string> xmlFilePathList, XmlFileOpType xmlFileOpType, DateTime datetime) { foreach (string item in xmlFilePathList) { init(item, xmlFileOpType, datetime); } }
/// <summary> /// 初始化Document对象 /// </summary> /// <param name="xmlFilePath">Xml文件路径</param> /// <param name="xmlFileOpType">文件相关操作类型</param> /// <param name="datetime">账目年月</param> private void init(string xmlFilePath, XmlFileOpType xmlFileOpType, DateTime datetime) { FileInfo xmlfile = new FileInfo(xmlFilePath); if (xmlfile.Exists) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlFilePath); xmlDocList.Add(xmldoc); } else { if (xmlFileOpType == XmlFileOpType.存在则创建) { XmlDocument xmldoc = new XmlDocument(); XmlElement xe = xmldoc.CreateElement("datas"); xe.SetAttribute("date", datetime.ToString("yyyy-MM")); xe.SetAttribute("path", ResolvePath(xmlFilePath)); xmldoc.InsertBefore(xmldoc.CreateXmlDeclaration("1.0", "utf-8", null), xmldoc.DocumentElement); xmldoc.AppendChild(xe); xmldoc.Save(xmlfile.FullName); xmlDocList.Add(xmldoc); } } }
/// <summary> /// 创建XmlDocument对象 /// </summary> /// <param name="xmlFilePath">数据文件路径</param> /// <param name="xmlFileOpType">文件相关操作类型</param> /// <param name="datetime">账目年月</param> public XmlOperate(string xmlFilePath, XmlFileOpType xmlFileOpType, DateTime datetime) { init(xmlFilePath, xmlFileOpType, datetime); }