主要是用XmlDocument类,XmlNode类来操作
代码如下
1 ///2 /// 从配置文件中获取ShopModel 3 /// 4 /// 5 ///6 public Model.Base_ShopModel GetModelFromXML() 7 { 8 Model.Base_ShopModel model = new Model.Base_ShopModel(); 9 string filePath = AppDomain.CurrentDomain.BaseDirectory;10 string strXmlPath = System.IO.Path.GetFullPath(filePath + "ShopModel.xml");11 if (!File.Exists(strXmlPath)) 12 {13 return null;14 }15 XmlDocument xml = new XmlDocument();16 xml.Load(strXmlPath);17 XmlNode xn = xml.SelectSingleNode("ShopModel");18 model.Shop_ID = xn.SelectSingleNode("ShopID").InnerText;19 model.ShopName = xn.SelectSingleNode("ShopName").InnerText;20 model.Province = xn.SelectSingleNode("Province").InnerText;21 model.City = xn.SelectSingleNode("City").InnerText;22 model.District = xn.SelectSingleNode("District").InnerText;23 model.ComputerTag = xn.SelectSingleNode("ComputerTag").InnerText;24 model.CompanyID = xn.SelectSingleNode("CompanyID").InnerText;25 model.LinkmanName = xn.SelectSingleNode("LinkmanName").InnerText;26 model.LinkmanPhone = xn.SelectSingleNode("LinkmanPhone").InnerText;27 model.Email = xn.SelectSingleNode("Email").InnerText;28 model.Remark = xn.SelectSingleNode("Remark").InnerText;29 return model;30 }
XML文档(ShopModel.xml)
1 23 9832C19A-1BB4-4E67-920A-04CD5E1B25B2 4test 56 78 910 1112 1310001 14XXX 1513583125479 16yang@sina.com 1718 19