Linq 读取Xml 数据
生活随笔
收集整理的這篇文章主要介紹了
Linq 读取Xml 数据
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.xml 數(shù)據(jù)格式如下
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.根據(jù)當(dāng)前的IP 于XML 內(nèi)容的相關(guān)的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節(jié)點(diǎn) 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; }?
?
轉(zhuǎn)載于:https://www.cnblogs.com/tong775131501/p/5462098.html
總結(jié)
以上是生活随笔為你收集整理的Linq 读取Xml 数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#调用SQL Server分页存储过程
- 下一篇: android 在自定义的listvi