生成XML文件,通过实体生成XML文件

前端之家收集整理的这篇文章主要介绍了生成XML文件,通过实体生成XML文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

实体

using System;@H_301_3@ using System.Collections.Generic;@H_301_3@ using System.Linq;@H_301_3@ using System.Text;@H_301_3@ using System.Xml.Serialization;//引入空间@H_301_3@ @H_301_3@ namespace Gome.OpenJob.Model@H_301_3@ {@H_301_3@ /// <summary>@H_301_3@ /// 全量索引文件@H_301_3@ /// 作者:赵亮@H_301_3@ /// 创建时间:2014、04、08@H_301_3@ /// </summary>@H_301_3@ [XmlRoot("root")]@H_301_3@ public class XMLBaiDuFullEntitys@H_301_3@ {@H_301_3@ /// <summary>@H_301_3@ /// Feed数据格式的版本号@H_301_3@ /// </summary>@H_301_3@ [XmlElement("version")]@H_301_3@ public string version { get; set; }//没有库里@H_301_3@ /// <summary>@H_301_3@ /// Feed数据文件最近修改时间@H_301_3@ /// </summary>@H_301_3@ [XmlElement("modified")]@H_301_3@ public string modifiedDate { get; set; }@H_301_3@ /// <summary>@H_301_3@ /// 结合商家创建的百度推广平台账号@H_301_3@ /// </summary>@H_301_3@ [XmlElement("seller_id")]@H_301_3@ public string seller_Name { get; set; }@H_301_3@ /// <summary>@H_301_3@ /// 商家全量推送过来的所有商品数量@H_301_3@ /// </summary>@H_301_3@ [XmlElement("total")]@H_301_3@ public string totalnumber { get; set; }@H_301_3@ /// <summary>@H_301_3@ /// 商家数据包所在的目录地址@H_301_3@ /// </summary>@H_301_3@ [XmlElement("dir")]@H_301_3@ public string dirItem { get; set; }@H_301_3@ /// <summary>@H_301_3@ /// 全量更新只允许 upload 上架商品,此处一个 outer_id 将对应 1000 个商品@H_301_3@ /// </summary>@H_301_3@ [XmlElement("item_ids")]@H_301_3@ public ItemIds ItemIds { get; set; }@H_301_3@ }@H_301_3@ /// <summary>@H_301_3@ /// 全量更新只允许 upload 上架商品,此处一个 outer_id 将对应 1000 个商品@H_301_3@ /// </summary>@H_301_3@ @H_301_3@ public class ItemIds@H_301_3@ {@H_301_3@ [XmlElement("outer_id")]@H_301_3@ public List<OutId> outIds { get; set; }@H_301_3@ }@H_301_3@ @H_301_3@ public class OutId@H_301_3@ {@H_301_3@ [XmlAttribute("action")]@H_301_3@ public string Action { get; set; }@H_301_3@ @H_301_3@ [XmlText]@H_301_3@ public string OutText { get; set; }@H_301_3@ }@H_301_3@ }@H_301_3@ ************************************

using System;@H_301_3@ using System.Collections.Generic;@H_301_3@ using System.Linq;@H_301_3@ using System.Text;@H_301_3@ using Gome.OpenJob.Model;@H_301_3@ using System.IO;@H_301_3@ using System.Xml.Serialization;@H_301_3@ using System.Xml;@H_301_3@ using System.Configuration;@H_301_3@ @H_301_3@ namespace Gome.OpenJob.Common@H_301_3@ {@H_301_3@ /// <summary>@H_301_3@ /// 生成全量@H_301_3@ /// </summary>@H_301_3@ public sealed class GenerateXML@H_301_3@ {@H_301_3@ private static XMLBaiDuFullEntitys m_humanResource = null;@H_301_3@ /// <summary>@H_301_3@ /// 用于生成详细内容@H_301_3@ /// </summary>@H_301_3@ private static XMLBaiDuGoodsDetailTest m_GoodsDetailTestResource = null;@H_301_3@ private GenerateXML() { }@H_301_3@ @H_301_3@ public static XMLBaiDuFullEntitys Get(string path)@H_301_3@ {@H_301_3@ if (m_humanResource == null)@H_301_3@ {@H_301_3@ FileStream fs = null;@H_301_3@ try@H_301_3@ {@H_301_3@ XmlSerializer xs = new XmlSerializer(typeof(XMLBaiDuFullEntitys));@H_301_3@ fs = new FileStream(path,FileMode.Open,FileAccess.Read);@H_301_3@ m_humanResource = (XMLBaiDuFullEntitys)xs.Deserialize(fs);@H_301_3@ fs.Close();@H_301_3@ return m_humanResource;@H_301_3@ }@H_301_3@ catch@H_301_3@ {@H_301_3@ if (fs != null)@H_301_3@ fs.Close();@H_301_3@ throw new Exception("Xml deserialization Failed!");@H_301_3@ }@H_301_3@ @H_301_3@ }@H_301_3@ else@H_301_3@ {@H_301_3@ return m_humanResource;@H_301_3@ }@H_301_3@ }@H_301_3@ //生成全量索引@H_301_3@ public static void Set(string path,XMLBaiDuFullEntitys humanResource)@H_301_3@ {@H_301_3@ if (humanResource == null)@H_301_3@ throw new Exception("Parameter humanResource is null!");@H_301_3@ @H_301_3@ FileStream fs = null;@H_301_3@ try@H_301_3@ {@H_301_3@ XmlSerializer xs = new XmlSerializer(typeof(XMLBaiDuFullEntitys));@H_301_3@ @H_301_3@ string path_file = SystemConfig.GetValue("pathFiles");//Open.config@H_301_3@ //生成文件的路径@H_301_3@ string strPath = path_file + "\\" + path;@H_301_3@ fs = new FileStream(strPath,FileMode.Create,FileAccess.Write);@H_301_3@ xs.Serialize(fs,humanResource);@H_301_3@ @H_301_3@ m_humanResource = null;@H_301_3@ fs.Close();@H_301_3@ }@H_301_3@ catch@H_301_3@ {@H_301_3@ if (fs != null)@H_301_3@ fs.Close();@H_301_3@ throw new Exception("Xml serialization Failed!");@H_301_3@ }@H_301_3@ }@H_301_3@ }@H_301_3@ }

***************************

/// <summary>@H_301_3@ /// 生成全量索引文件@H_301_3@ /// 作者:赵亮@H_301_3@ /// 创建时间:2014、04、08@H_301_3@ /// </summary>@H_301_3@ /// <returns></returns>@H_301_3@ public static int Notation = 0;@H_301_3@ public XMLBaiDuFullEntitys FullAmount()@H_301_3@ {@H_301_3@ XMLBaiDuFullEntitys fu = new XMLBaiDuFullEntitys();@H_301_3@ ItemIds ids = new ItemIds();@H_301_3@ ids.outIds = new List<OutId>();@H_301_3@ fu.ItemIds = ids;@H_301_3@ string sqlnum = "select distinct count(*) from VIEW_CPS v inner join gome_category r on (v.category_id=r.categoryid) where seq=0 and v.state='已上架' and v.list_price is not null and v.list_price !=0";@H_301_3@ DbCommand command = this.GetsqlStringCommand(sqlnum);@H_301_3@ object num = this.ExecuteScalar(command);@H_301_3@ int countnum = int.Parse(num.ToString()) + 1000 - 1;@H_301_3@ string count = Math.Ceiling((double)countnum / (double)1000).ToString();@H_301_3@ Notation = int.Parse(count);@H_301_3@ @H_301_3@ //实体里传值@H_301_3@ fu.version = "1.0";@H_301_3@ fu.modifiedDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");@H_301_3@ fu.seller_Name = "国美在线";@H_301_3@ fu.totalnumber = num.ToString();//商品数量@H_301_3@ fu.dirItem = "www.gome.com.cn";@H_301_3@ @H_301_3@ //int outer_idNum = aa / 1000;@H_301_3@ for (int i = 1; i <= int.Parse(count) - 2; i++)@H_301_3@ {@H_301_3@ OutId outId = new OutId();@H_301_3@ outId.Action = "upload";@H_301_3@ outId.OutText = i.ToString();@H_301_3@ fu.ItemIds.outIds.Add(outId);@H_301_3@ }@H_301_3@ return fu;@H_301_3@ }

***************************

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { BaiDuMicroPurchaseBLL abc = new BaiDuMicroPurchaseBLL(); abc.baiduFullAmount(); XMLBaiDuFullEntitys xmlList = abc.baiduFullAmount(); //全量索引文件名 string path = SystemConfig.GetValue("FullIndexName");//Open.config //调用生成xml文件 GenerateXML.Set(path,xmlList); abc.baiduCommodityInformationFile(); Console.Read(); } } }

猜你在找的XML相关文章