服務(wù)熱線
153 8323 9821
1 public static class PriceXML
2 {
3 ///<summary>
4 /// 新建一個(gè)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 //先創(chuàng)建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 //加入一個(gè)根元素
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");//創(chuàng)建一個(gè)<Node>節(jié)點(diǎn)
26 xe1.SetAttribute("name", description);//設(shè)置該節(jié)點(diǎn)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>節(jié)點(diǎn)中
40 //然后在保存到源位置
41 xmldoc.AppendChild(xmlelem);
42 //保存創(chuàng)建好的XML文檔
43 string filename = DateTime.Now.ToString("yyMMddHHmmss") + description + ".xml<