Linq 读取Xml 数据

1.xml 数据格式如下

1 <?xml version="1.0" encoding="utf-8"?>
2 <root>
3   <column>
4     <item ip="113.109.36.204" />
5     <item ip="104.195.60.89" />
6     <item ip="125.77.244.33" />
7   </column>
8 </root>

2.根据当前的IP 于XML 内容的相关的IP相匹配

             
1            bool result = false;
2 
3             string FileName = System.Web.HttpContext.Current.Server.MapPath("~/IpConfig.xml");
4             XDocument doc = XDocument.Load(FileName);
5             //获取item节点 value等于ip的value
6             var rel = from p in doc.Descendants("item") where p.Attribute("ip").Value.ToLower() == ip select p;
7             if (rel != null && rel.Count() > 0) { result = true; }

 

 

posted on 2016-05-05 15:30  潺潺水声  阅读(236)  评论(0编辑  收藏  举报

导航