/// <summary> /// 转换成XML /// </summary> /// <param name="model"></param> /// <returns></returns> public static string ToXml(PushMsssageSetting model) { //TODO:转换成xml结构的算法 //创建一个xml对象 XmlDocument xmlDoc = new XmlDocument(); //创建开头 XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.AppendChild(dec); //创建根节点 XmlElement root = xmlDoc.CreateElement("Root"); XmlElement typeNode = xmlDoc.CreateElement("MsgTypes"); foreach (var v in model.PushSetting) { XmlElement FirNode; FirNode = xmlDoc.CreateElement("Type"); FirNode.SetAttribute("TypeName", v.Key.ToString()); FirNode.SetAttribute("IsUsed", v.Value.ToString()); typeNode.AppendChild(FirNode); } root.AppendChild(typeNode); //添加根节点 xmlDoc.AppendChild(root); return(xmlDoc.OuterXml); }
/// <summary> /// 转换成Xml /// </summary> /// <param name="model"></param> /// <returns></returns> public static string ToXml(CouponsInfoItem model) { //TODO:转换成xml结构的算法 //创建一个xml对象 XmlDocument xmlDoc = new XmlDocument(); //创建开头 XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.AppendChild(dec); //创建根节点 XmlElement root = xmlDoc.CreateElement("Print"); foreach (PrintItem pItem in model.TemplateItem) { XmlElement FirNode; if (pItem.IsImage) { FirNode = xmlDoc.CreateElement("Pic"); FirNode.InnerText = pItem.ImagePath; FirNode.SetAttribute("height", pItem.ImageHeight.ToString()); FirNode.SetAttribute("width", pItem.ImageWidth.ToString()); } else { FirNode = xmlDoc.CreateElement("Content"); FirNode.InnerText = pItem.TextInfo; FirNode.SetAttribute("font", "宋体"); FirNode.SetAttribute("bold", pItem.IsBold ? "Y" : "N"); FirNode.SetAttribute("italic", pItem.IsItalic ? "Y" : "N"); FirNode.SetAttribute("size", pItem.FontSize.ToString()); } root.AppendChild(FirNode); } //添加根节点 xmlDoc.AppendChild(root); return(xmlDoc.OuterXml); }
/// <summary> /// 转换成Xml /// </summary> /// <param name="model"></param> /// <returns></returns> public static string ToXml(CouponsInfo model) { //TODO:转换成xml结构的算法 //创建一个xml对象 XmlDocument xmlDoc = new XmlDocument(); //创建开头 XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.AppendChild(dec); //创建根节点 XmlElement root = xmlDoc.CreateElement("Root"); root.SetAttribute("Num", model.Num); root.SetAttribute("Name", model.Name); root.SetAttribute("EffectDate", model.EffectDate.ToShortDateString()); root.SetAttribute("EndDate", model.EndDate.ToShortDateString()); root.SetAttribute("Station", model.Station.ToString()); root.SetAttribute("LogoImage", model.LogoImage); root.SetAttribute("Type", model.Type.ToString()); XmlElement SecNode = xmlDoc.CreateElement("PopItem"); foreach (CouponsInfoItem scItem in model.PopItemList) { XmlElement ThrNode = xmlDoc.CreateElement("Pop"); ThrNode.SetAttribute("EffectDate", scItem.EffectDate.ToShortDateString()); ThrNode.SetAttribute("EndDate", scItem.EndDate.ToShortDateString()); ThrNode.SetAttribute("PpoImagePath", scItem.PpoImagePath); ThrNode.SetAttribute("IsPrint", scItem.IsPrint.ToString()); ThrNode.SetAttribute("ID", scItem.ID.ToString()); if (scItem.IsPrint) { XmlElement ForNode = xmlDoc.CreateElement("PrintTemplate"); foreach (PrintItem pItem in scItem.TemplateItem) { XmlElement FirNode; if (pItem.IsImage) { FirNode = xmlDoc.CreateElement("Pic"); FirNode.InnerText = pItem.ImagePath; FirNode.SetAttribute("height", pItem.ImageHeight.ToString()); FirNode.SetAttribute("width", pItem.ImageWidth.ToString()); } else { FirNode = xmlDoc.CreateElement("Content"); FirNode.InnerText = pItem.TextInfo; FirNode.SetAttribute("bold", pItem.IsBold ? "Y" : "N"); FirNode.SetAttribute("italic", pItem.IsItalic ? "Y" : "N"); FirNode.SetAttribute("size", pItem.FontSize.ToString()); } ForNode.AppendChild(FirNode); } ThrNode.AppendChild(ForNode); } SecNode.AppendChild(ThrNode); } //在根节点中添加二级节点 root.AppendChild(SecNode); //需要下载的文件 XmlElement FileNode = xmlDoc.CreateElement("ImageFilePath"); foreach (string file in model.ImageFilePath) { XmlElement ThrNode = xmlDoc.CreateElement("FilePath"); ThrNode.SetAttribute("Url", file); FileNode.AppendChild(ThrNode); } root.AppendChild(FileNode); //添加根节点 xmlDoc.AppendChild(root); return(xmlDoc.OuterXml); }