我正在使用RSS.NET for .NET 2.0。尽我所能,我得到以下0个频道:
feed = RssFeed.Read("http://feeds.feedburner.com/punchfire?format=xml");
我注意到,对于其他饲料,例如。
feed = RssFeed.Read("http://www.engadget.com/rss.xml");
我想它必须是有效的 xml 文档。您认为我应该在我的应用程序代码中检查“.xml”,还是有任何方法可以将 RSS.NET 调整为接受 feedburner Feed?
答案 0 :(得分:2)
您无法获得任何通道节点的原因是,原子格式没有任何通道节点。检查以下
您的第二个链接是Rss Feed,其中包含如下通道节点
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Engadget</title>
<link>http://www.engadget.com</link>
.
.
.
另一方面,原子提要不使用通道节点,您可以通过以下规范链接了解。
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">dive into mark</title>
<subtitle type="html">
A <em>lot</em> of effort
went into making this effortless
</subtitle>
<updated>2005-07-31T12:29:29Z</updated>
<id>tag:example.org,2003:3</id>
<link rel="alternate" type="text/html"
hreflang="en" href="http://example.org/"/>
<link rel="self" type="application/atom+xml"
href="http://example.org/feed.atom"/>
<rights>Copyright (c) 2003, Mark Pilgrim</rights>
<generator uri="http://www.example.com/" version="1.0">
Example Toolkit
</generator>
<entry>
.
.
.
编辑:检查供稿格式
// url of the feed
string utlToload = @"http://feeds.feedburner.com/punchfire?format=xml"
// load feed
Argotic.Syndication.GenericSyndicationFeed feed =
Argotic.Syndication.GenericSyndicationFeed.Create(new Uri(urlToLoad));
// check what format is it
if (feed.Format.Equals(SyndicationContentFormat.Rss))
{
// yourlogic here
}
else if (feed.Format.Equals(SyndicationContentFormat.Atom))
{
// yourlogic here
}
else if (feed.Format.Equals(SyndicationContentFormat.NewsML))
{
// yourlogic here
}
希望有所帮助
答案 1 :(得分:1)
使用.Net 3.5+,解析Atom提要非常容易。 BTW Atom提要是我听到的RSS的新标准。
public class RssFeedDO
{
public string RssFeedUrl { get; private set; }
/// <summary>
/// Build feed processor
/// </summary>
/// <param name="feedUrl">Atom or RSS url with http in front.</param>
public RssFeedDO(string feedUrl)
{
this.RssFeedUrl = feedUrl;
}
/// <summary>
/// Will try to get RSS data from url passed in constructor. Can do atom or rss
/// </summary>
/// <returns></returns>
public SyndicationFeed GetRSSData()
{
SyndicationFeed feed = null;
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.CheckCharacters = true;
settings.CloseInput = true;
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.DtdProcessing = DtdProcessing.Prohibit;
if (!string.IsNullOrEmpty(this.RssFeedUrl))
{
using (XmlReader reader = XmlReader.Create(this.RssFeedUrl, settings))
{
SyndicationFeedFormatter GenericFeedFormatter = null;
Atom10FeedFormatter atom = new Atom10FeedFormatter();
Rss20FeedFormatter rss = new Rss20FeedFormatter();
if (reader.ReadState == ReadState.Initial)
{
reader.MoveToContent();
}
// try either atom or rss reading
if (atom.CanRead(reader))
{
GenericFeedFormatter = atom;
}
if (rss.CanRead(reader))
{
GenericFeedFormatter = rss;
}
if (GenericFeedFormatter == null)
{
return null;
}
GenericFeedFormatter.ReadFrom(reader);
feed = GenericFeedFormatter.Feed;
}
}
return feed;
}
}
现在你可以将一个对象数据源指向上面的类,然后像你这样在ListView或RadGrid中评估一些东西:
<%# Eval("Title.Text") %>
使用几个feedburner Feed进行测试,效果很好。
答案 2 :(得分:1)
我已经改进了JamesR的code,现在返回成功布尔值并接受ByRef syndicationfeed对象;
public static class FeedParser
{
public static bool Parse(string url, ref SyndicationFeed feed)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.CheckCharacters = true;
settings.CloseInput = true;
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.DtdProcessing = DtdProcessing.Prohibit;
if (string.IsNullOrEmpty(url)) return false;
using (XmlReader reader = XmlReader.Create(url, settings))
{
SyndicationFeedFormatter formatter = null;
Atom10FeedFormatter atom_formatter = new Atom10FeedFormatter();
Rss20FeedFormatter rss_formatter = new Rss20FeedFormatter();
if (reader.ReadState == ReadState.Initial) reader.MoveToContent();
if (atom_formatter.CanRead(reader)) formatter = atom_formatter;
if (rss_formatter.CanRead(reader)) formatter = rss_formatter;
if (formatter == null) return false;
formatter.ReadFrom(reader);
feed = formatter.Feed;
return true;
}
}
}
可以像;
一样使用 SyndicationFeed feed=null;
if(FeedParser.Parse(url,ref feed))
{
}
答案 3 :(得分:0)
http://feeds.feedburner.com/punchfire?format=xml似乎是Atom Feed,而不是RSS。 rss.net知道如何处理吗?