服务热线
153 8323 9821
1 public static class PriceXML
2 {
3 ///<summary>
4 /// 新建一个XML文件
5 ///</summary>
6 ///<param name="list"></param>
7 ///<param name="description"></param>
8 ///<returns></returns>
9 public static bool AddPriceXML(List<B_Goods> list,string description)
10 {
11 if (list != null)
12 {
13 if (list.Count > 0)
14 {
15 //先创建XML,返回路径
16 XmlDocument xmldoc = new XmlDocument();
17 //加入XML的声明段落,<?xml version="1.0" encoding="gb2312"?>
18 XmlDeclaration xmldecl;
19 xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
20 xmldoc.AppendChild(xmldecl);
21 //加入一个根元素
22 XmlNode xmlelem = xmldoc.createElement_x("", "PriceMark", "");
23 xmldoc.AppendChild(xmlelem);
24 XmlNode root = xmldoc.SelectSingleNode("PriceMark");//查找<PriceMark>
25 XmlElement xe1 = xmldoc.createElement_x("Node");//创建一个<Node>节点
26 xe1.SetAttribute("name", description);//设置该节点name属性
27 foreach (var item in list)
28 {
29 XmlElement xesub1 = xmldoc.createElement_x("item");
30 xesub1.SetAttribute("pcode", item.G_AllProductID);
31 xesub1.SetAttribute("marketprice",item.G_MarketPrice.ToString());
32 xesub1.SetAttribute("sellprice", item.G_SellPrice.ToString());
33 if(item.G_IconDisplay==null)
34 xesub1.SetAttribute("icondisplay","");
35 else
36 xesub1.SetAttribute("icondisplay", item.G_IconDisplay);
37 xe1.AppendChild(xesub1);
38 }
39 root.AppendChild(xe1);//添加到<PriceMark>节点中
40 //然后在保存到源位置
41 xmldoc.AppendChild(xmlelem);
42 //保存创建好的XML文档
43 string filename = DateTime.Now.ToString("yyMMddHHmmss") + description + ".xml<
上一篇:DataTable 操作