在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
数据库表内信息 表名为CP
1 public void CreateXmlFile() 2 { 3 using (ws1DataContext con = new ws1DataContext()) 4 { 5 6 XmlDocument xmlDoc = new XmlDocument(); 7 //创建类型声明节点 8 XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", ""); 9 xmlDoc.AppendChild(node); 10 11 12 List<CP> clist = new List<CP>(); 13 clist = con.CP.ToList(); 14 int ii = clist.Count; 15 //创建根节点 16 XmlNode root = xmlDoc.CreateElement("User"); 17 18 xmlDoc.AppendChild(root); 19 for (int i = 0; i < ii; i++) 20 { 21 CreateNode(xmlDoc, root, "Ids", clist[i].Ids.ToString()); 22 CreateNode(xmlDoc, root, "Id", clist[i].ID.ToString()); 23 CreateNode(xmlDoc, root, "PC", clist[i].PJ.ToString()); 24 } 25 try 26 { 27 xmlDoc.Save("c://data2.xml"); 28 } 29 catch (Exception e) 30 { 31 //显示错误信息 32 Console.WriteLine(e.Message); 33 } 34 //Console.ReadLine(); 35 36 } 37 } 38 /// <summary> 39 /// 创建节点 40 /// </summary> 41 /// <param name="xmldoc"></param> xml文档 42 /// <param name="parentnode"></param>父节点 43 /// <param name="name"></param> 节点名 44 /// <param name="value"></param> 节点值 45 /// 46 public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value) 47 { 48 XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null); 49 node.InnerText = value; 50 parentNode.AppendChild(node); 51 }
无敌!
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论