XLINQ 访问 XML 文件的方法
XLINQ 的例子我们就写稍稍复杂点,通过获得博客的RSS,然后把RSS中的链接和标题打印出来:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
下面就是这个功能的演示代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using System;
using System.Linq;
using System.Xml.Linq;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public class XLINQ
{
public static void DoSomeThing()
{
XElement feed = XElement.Load(”http://blog.joycode.com/ghj/Rss.aspx”);
if (feed.Element(”channel”) == null)
return;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var rss = from item in feed.Element(”channel”).Elements(”item”)
select new
{
title = item.Element(”title”).Value,
link = item.Element(”link”).Value
};
foreach (var item in rss)
{
Console.WriteLine(item.link);
Console.WriteLine(item.title);
Console.WriteLine(”*****”);
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
XLINQ 加载数据的核心就在于 XElement.Load
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)