zoukankan      html  css  js  c++  java
  • XML文档操作

    主要是用XmlDocument类,XmlNode类来操作

    代码如下

     1         /// <summary>
     2         /// 从配置文件中获取ShopModel
     3         /// </summary>
     4         /// <param name="ID"></param>
     5         /// <returns></returns>
     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 <?xml version="1.0" encoding="gb2312"?>
     2 <ShopModel>
     3   <ShopID>9832C19A-1BB4-4E67-920A-04CD5E1B25B2</ShopID>
     4   <ShopName>test</ShopName>
     5   <Province>
     6   </Province>
     7   <City>
     8   </City>
     9   <District>
    10   </District>
    11   <ComputerTag>
    12   </ComputerTag>
    13   <CompanyID>10001</CompanyID>
    14   <LinkmanName>XXX</LinkmanName>
    15   <LinkmanPhone>13583125479</LinkmanPhone>
    16   <Email>yang@sina.com</Email>
    17   <Remark>
    18   </Remark>
    19 </ShopModel>
  • 相关阅读:
    在路上——7月英语
    Today is a special day for English Topic
    三级网络-不单单是学知识
    停下是为了更好的出发
    量变引发质变--【2015年计算机年终总结】
    这个月,小美很忙
    一个人牛逼不如一群人一起牛逼——致我最亲爱的程序员
    掀起你的盖头来--【2015年英语年终总结】
    平凡之路之小美
    小美的猴年年中总结,挪不开眼~
  • 原文地址:https://www.cnblogs.com/YangBinChina/p/2986008.html
Copyright © 2011-2022 走看看