2017-04-13 16 views
0

我想从一个RSS feed链接,像这样:试图从一个RSS feed链接与Syndicationitem

<item> 
<title> 
Mothers CAN wear the same clothes as their daughters 
</title> 
<link> 
http://www.dailymail.co.uk/femail/article-4408430/Mothers-wear-clothes-daughters.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490 
</link> 
<description> 
Stylist Trinny, 53, appeared on This Morning in a pair of white striped culottes from Urban Outfitters that she bought after admiring them on her 13-year-old daughter, Lyla Elichaoff. 
</description> 
<enclosure url="http://i.dailymail.co.uk/i/pix/2017/04/13/13/3F36FB3200000578-0-image-a-58_1492086235218.jpg" type="image/jpeg" length="9078"/> 
<pubDate>Thu, 13 Apr 2017 13:38:02 +0100</pubDate> 
<guid> 
http://www.dailymail.co.uk/femail/article-4408430/Mothers-wear-clothes-daughters.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490 
</guid> 
<media:description/> 
<media:thumbnail url="http://i.dailymail.co.uk/i/pix/2017/04/13/13/3F36FB3200000578-0-image-a-58_1492086235218.jpg" width="154" height="115"/> 
<media:credit scheme="urn:ebu">Ken McKay/ITV/REX/Shutterstock</media:credit> 
<media:content type="image/jpeg" url="http://i.dailymail.co.uk/i/pix/2017/04/13/13/3F36FB3200000578-0-image-a-58_1492086235218.jpg"/> 
</item> 

通过RSS订阅源项目我的代码回路

private void button2_Click(object sender, EventArgs e) 
    { 
     string url = textBox1.Text; 
     XmlReader reader = XmlReader.Create(url); 
     SyndicationFeed feed = SyndicationFeed.Load(reader); 
     reader.Close(); 
     foreach (SyndicationItem item in feed.Items) 
     { 
      String subject = item.Links. 
      articletext.Text = subject; 
     } 
    } 

我已尝试'item.links.tostring();'和'item.link'并且都没有工作,我怎么能得到RSS饲料的链接?

+0

你在'reader'和'feed'变量中获得什么?注意xml中的节点是'items'而不是'items',对于'links'是相同的 –

+0

如果我使用Item.Link.ToString();我得到以下几点:System.ServiceModel.Syndication.NullNotAllowedCollection'1 [System.ServiceModel.Syndication.SyndicationLink] – 4334738290

+0

如果调试正常,你可以很容易地检查你得到什么响应。和你需要写什么来获取值。逐步检查检查他们添加的值。 –

回答

3

,您可以访问像这样的链接:

foreach (SyndicationItem item in feed.Items) 
{ 
    string link = item.Links[0].Uri.ToString(); 
    string text = item.Summary.Text; 
}