如何在visual C中读取RSS提要的特定行#
我想阅读RSS提要的特定行,以便使用visual C#在标签中显示信息。下面给出的是Rss提要如何在visual C中读取RSS提要的特定行#,rss,visual-c#-express-2010,rss-reader,Rss,Visual C# Express 2010,Rss Reader,我想阅读RSS提要的特定行,以便使用visual C#在标签中显示信息。下面给出的是Rss提要 <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"><channel> <title>Weather Underground</title> <link>http://www.wunderground.com/</link> <cat
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel>
<title>Weather Underground</title>
<link>http://www.wunderground.com/</link>
<category>weather</category>
<item>
<title>Current Conditions : 28C, Mostly Cloudy - 9:10 AM IST Jun. 28</title>
<link>http://www.wunderground.com/global/stations/43466.html</link>
<description><![CDATA[Temperature: 28°C | Humidity: 79% | Pressure: 1011hPa (Steady) | Conditions: Mostly Cloudy | Wind Direction: SW | Wind Speed: 15km/h<img src="http://server.as5000.com/AS5000/adserver/image?ID=WUND-00071&C=0" width="0" height="0" border="0"/>]]>
</description>
<pubDate>Thu, 28 Jun 2012 09:10:00 IST</pubDate>
</item>
<item>
<title>Forecast for Wednesday Night as of Jun. 27 5:30 PM IST</title>
<link>http://www.wunderground.com/global/stations/43466.html</link>
<description>
Chance of a Thunderstorm. Low:26 &deg; C.
</description>
<pubDate>Wed, 27 Jun 2012 12:00:00 GMT</pubDate>
<guid isPermaLink="false">1340798400-1-night</guid>
</item>
<item>
<title>Forecast for Thursday as of Jun. 27 5:30 PM IST</title>
<link>http://www.wunderground.com/global/stations/43466.html</link>
<description>
Chance of a Thunderstorm. High:31 &deg; C.//This is the line that I need
</description>
<pubDate>Wed, 27 Jun 2012 12:00:00 GMT</pubDate>
<guid isPermaLink="false">1340884800-2-day</guid>
</item>
地下天气
http://www.wunderground.com/
天气
现状:28摄氏度,多云-6月28日上午9:10
http://www.wunderground.com/global/stations/43466.html
2012年6月28日星期四09:10:00 IST
预测6月27日星期三晚上5:30 IST
http://www.wunderground.com/global/stations/43466.html
有可能发生雷雨。低:26及;度;C
2012年6月27日星期三12:00:00 GMT
1340798400-1晚
预测截至6月27日星期四IST下午5:30
http://www.wunderground.com/global/stations/43466.html
有可能发生雷雨。高:31及;度;C.//这是我需要的线路
2012年6月27日星期三12:00:00 GMT
1340884800-2天
此XML文件中有许多项标记,如何引用所需的项标记并获取该描述标记内的文本?您可以执行类似操作将所有描述读取到列表中,然后从列表中获取特定描述
var rss = XDocument.Load("your rss file");
var items = (from c in rss.Descendants("item") select new{
Title = (string)c.Element("description")
}).ToList();
// first description
string firstitem= items[0].Title.ToString();
当我这样做时:var rss=XDocument.Load(“您的rss文件”);它表示无法将void分配给隐式类型的局部变量。请尝试此XDocument rss=XDocument.Load(“您的rss文件”);谢谢我加入了错误的重要声明,没关系。但它还说,当前上下文中不存在名称“item”:Title=(string)item.Element(“description”)