public static string Convert(FileUpdateInfo filesInfo) { _XmlSystemInfo = new XmlDocument(); XmlDeclaration dec = _XmlSystemInfo.CreateXmlDeclaration("1.0", "utf-8", null); _XmlSystemInfo.AppendChild(dec); XmlElement root = _XmlSystemInfo.CreateElement("updater");//创建根节点 XmlElement element = null; element = _XmlSystemInfo.CreateElement("application"); element.SetAttribute("version", filesInfo._Version); element.SetAttribute("subsystem", ((int)filesInfo._SubsystemType).ToString()); element.SetAttribute("lastUpdate", filesInfo._ReleaseDate.ToString()); element.SetAttribute("systemName", filesInfo._SubsystemType.ToString()); element.SetAttribute("startProgram", filesInfo.startProgram); _XmlSystemInfo.AppendChild(root); //根节点 root.AppendChild(element); // element = _XmlSystemInfo.CreateElement("updateLog"); element.InnerText = filesInfo.UpdateLog; //更新日志 root.AppendChild(element); element = BuildUpdateConfigFile(filesInfo._Files); root.AppendChild(element); _XmlSystemInfo.AppendChild(root); return(_XmlSystemInfo.OuterXml); }
/// <summary> /// xml转换为更新类 /// </summary> /// <param name="filesXml"></param> /// <returns></returns> public static FileUpdateInfo Convert(string filesXml) { FileUpdateInfo fileupdate = new FileUpdateInfo(); XmlDocument doc = new XmlDocument(); doc.LoadXml(filesXml); XmlNode node = doc.SelectSingleNode("//updater/application"); fileupdate.Version = node.Attributes["version"].Value; fileupdate.SubsystemType = node.Attributes["subsystem"] != null ? (SeatManageSubsystem)int.Parse(node.Attributes["subsystem"].Value) : SeatManageSubsystem.None; fileupdate.ReleaseDate = node.Attributes["lastUpdate"] != null?DateTime.Parse(node.Attributes["lastUpdate"].Value) : DateTime.Parse("1900-1-1"); fileupdate.StartProgram = node.Attributes["startProgram"] != null ? node.Attributes["startProgram"].Value : ""; node = doc.SelectSingleNode("//updater/updateLog"); fileupdate.UpdateLog = node.InnerText; XmlNode nodelist = doc.SelectSingleNode("//updater/dir"); fileupdate._Files = BuildUpdateConfigFile(nodelist); return(fileupdate); }