实体

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;//引入空间

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

public class ItemIds
    {
        [XmlElement("outer_id")]
        public List<OutId> outIds { get; set; }
    }

public class OutId
    {
        [XmlAttribute("action")]
        public string Action { get; set; }

[XmlText]
        public string OutText { get; set; }
    }
}
************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gome.OpenJob.Model;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Configuration;

namespace Gome.OpenJob.Common
{
    /// <summary>
    /// 生成全量
    /// </summary>
    public sealed class GenerateXML
    {
        private static XMLBaiDuFullEntitys m_humanResource = null;
        /// <summary>
        /// 用于生成详细内容
        /// </summary>
        private static XMLBaiDuGoodsDetailTest m_GoodsDetailTestResource = null;
        private GenerateXML() { }

public static XMLBaiDuFullEntitys Get(string path)
        {
            if (m_humanResource == null)
            {
                FileStream fs = null;
                try
                {
                    XmlSerializer xs = new XmlSerializer(typeof(XMLBaiDuFullEntitys));
                    fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                    m_humanResource = (XMLBaiDuFullEntitys)xs.Deserialize(fs);
                    fs.Close();
                    return m_humanResource;
                }
                catch
                {
                    if (fs != null)
                        fs.Close();
                    throw new Exception("Xml deserialization failed!");
                }

}
            else
            {
                return m_humanResource;
            }
        }
        //生成全量索引
        public static void Set(string path, XMLBaiDuFullEntitys humanResource)
        {
            if (humanResource == null)
                throw new Exception("Parameter humanResource is null!");
           
            FileStream fs = null;
            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(XMLBaiDuFullEntitys));
                
                string path_file = SystemConfig.GetValue("pathFiles");//Open.config
                //生成文件的路径
                string strPath = path_file + "\\" + path;
                fs = new FileStream(strPath, FileMode.Create, FileAccess.Write);
                xs.Serialize(fs, humanResource);
                
                m_humanResource = null;
                fs.Close();
            }
            catch
            {
                if (fs != null)
                    fs.Close();
                throw new Exception("Xml serialization failed!");
            }
        }
    }
}

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

/// <summary>
        /// 生成全量索引文件
        /// 作者:赵亮
        /// 创建时间:2014、04、08
        /// </summary>
        /// <returns></returns>
        public static int Notation = 0;
        public XMLBaiDuFullEntitys FullAmount()
        {
            XMLBaiDuFullEntitys fu = new XMLBaiDuFullEntitys();
            ItemIds ids = new ItemIds();
            ids.outIds = new List<OutId>();
            fu.ItemIds = ids;
            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";
            DbCommand command = this.GetSqlStringCommand(sqlnum);
            object num = this.ExecuteScalar(command);
            int countnum = int.Parse(num.ToString()) + 1000 - 1;
            string count = Math.Ceiling((double)countnum / (double)1000).ToString();
            Notation = int.Parse(count);

//实体里传值
            fu.version = "1.0";
            fu.modifiedDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            fu.seller_Name = "国美在线";
            fu.totalnumber = num.ToString();//商品数量
            fu.dirItem = "www.gome.com.cn";

//int outer_idNum = aa / 1000;
            for (int i = 1; i <= int.Parse(count) - 2; i++)
            {
                OutId outId = new OutId();
                outId.Action = "upload";
                outId.OutText = i.ToString();
                fu.ItemIds.outIds.Add(outId);
            }
            return fu;
        }

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

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文件,通过实体生成XML文件的更多相关文章

  1. Android开发——自动生成Android屏幕适配的dimens.xml文件

    使用dimens.xml解决屏幕适配问题是Android官方解决方案,本文主要讲述了如何自动生成Android屏幕适配的dimens.xml,减少了工作量,在维护dimens.xml文件时更加省时省力 ...

  2. 如何在IJ中使用Jaxb2通过xml定义生成对应的Java Entity类的文件

    #0. 准备要转换的xml文件,在Project视界中,右击这个xml文件,在弹出的菜单上选择“Generate XSD schema from XML File...”, 按默认设置生成xsd文件. ...

  3. netbeans生成的maven工程没有web.xml文件 如何新建

    使用netbeans生成的maven工程没有web.xml 需要自己新建 步骤: 下一步,完成

  4. Java IDE 编辑器 --- IntelliJ IDEA 进阶篇 生成 hibernate 实体与映射文件

    原文:转:Java IDE 编辑器 --- IntelliJ IDEA 进阶篇 生成 hibernate 实体与映射文件 2011-04-30 12:50 很多人不知道怎么用 IntelliJ IDE ...

  5. 生成 hibernate 映射文件和实体类

    创建web工程,使用Hibernate的时候,在工程里一个一个创建实体类太麻烦,浪费时间,现在教大家如何用MyEclipse自动生成Hibernate映射文件及实体类 方法/步骤   创建数据库,创建 ...

  6. Mybatis Generator生成Mybatis Dao接口层*Mapper.xml以及对应实体类

    [前言] 使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件,Mybatis-Generator的作用就是充当了一个代码生成器的角色,使用代码生成器不仅可以简化我 ...

  7. XML文件与实体类的互相转换

    XML文件与实体类的互相转换 一.将XML文件反序列化为实体类对象 1. 通常程序的配置信息都保存在程序或者网站的专门的配置文件中(App.config/web.config).但是现在为了演示XML ...

  8. T4 模板自动生成带注释的实体类文件

    T4 模板自动生成带注释的实体类文件 - 只需要一个 SqlSugar.dll 生成实体就是这么简单,只要建一个T4文件和 文件夹里面放一个DLL. 使用T4模板教程 步骤1 创建T4模板 如果你没有 ...

  9. Intellij IDEA 通过数据库表逆向生成带注释的实体类文件超级详细步骤,附详细解决方案

    参考:https://blog.csdn.net/qq_34371461/article/details/80571281  https://blog.csdn.net/mqchenrong/arti ...

随机推荐

  1. cocos2d-x, protobuf, no config.h, #error "No suitable threading library available."

    在用cocos2d-x3.2 + protobuf编译Android项目的时候,protobuf出现了两个问题: 1. 首先是config.h找不到,查阅自后说是通过命令或工具生成的,里面的内容根据不 ...

  2. javascript——马步之Array篇

    数组 Array == 1.建立数组==* 通过变量赋值为[]来建立数组 var arr = []; // arr 是一个数组 * 需要注意数组的下标是从0开始中的 ==2.获取数组长度== * 通过 ...

  3. 沈逸老师ubuntu速学笔记(2)-- ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展

    1.编译安装apache2.4.20 第一步: ./configure --prefix=/usr/local/httpd --enable-so 第二步: make 第三步: sudo make i ...

  4. ASP.NET MVC 4 批量上传文件

    上传文件的经典写法: <form id="uploadform" action="/Home/UploadFile" method="post& ...

  5. CentOS(八)--crontab命令的使用方法

    crontab命令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于"crontab"文件中,以供之后读取和执行. 在 ...

  6. C# WPF 连接数据库Sqlhelper类

    从视频上学习到的WPF连接数据库的方法 需要配置一个 configuration 文件,包含 SQL instance 的相关信息 using System; using System.Collect ...

  7. 关于Winform发布时,资源文件缺失的解决方案

    今天和大家分享一下,我这几天一直困惑的问题,今天不经意间解决了这个问题,接下来描述一下这个问题: 问题: 最近公司给人家做二次开发,是C/S结构的,我在做Winform时发现,当我选择一个项目发布时, ...

  8. 从零单排Linux – 1 – 简单命令

    从零单排Linux – 1 – 简单命令 Posted in: Linux 从零单排Linux – 1 一.Linux的简单命令: 1.忘记root密码: 读秒时按任意键进入 – e – ↓选择第二个 ...

  9. Linux 命令 - printenv: 打印全部或部分环境信息

    命令格式 printenv [OPTION]... [VARIABLE]... 命令参数 -0, --null 以空字符而非换行符结束每一输出行. --help 显示帮助信息. --version 显 ...

  10. ios Swift 国外资源

    Swift国外资源汇总(No.1) 此类分享贴暂定每2天更新一次,主要目的是让大家能跟国外开发者们同步,共享知识和共同提高. 对于一些非常有价值的文章,大家有兴趣可以自行翻译(回贴跟我说一声,避免重复 ...