Consuming RSS Feeds Exceptions

D

dkode

I built an asp.net usercontrol that consumes rss feeds that I specify
the url for.

Some of them (MVP blogs, google news) consumes the feeds just fine. and
other times (75%) it chokes on stream.length and stream.position with
an Exception of type System.NotSupportException.

It seems as if with some RSS feeds, they are not formatted correctly?
What can I do to get these to work properly.

One that is giving me problems is the slashdot rss :
http://rss.slashdot.org/Slashdot/slashdot

I will put error reporting in there so if the feed is bad, it won't
consume it, but i'm just trying to figure out why it would choke on
these feeds. The RSS xml looks ok, so I dont really understand what the
problem is.

Any help would be greatly appreciate. here is a snippet of code i'm
using to consume the feed:

WebRequest request;

WebResponse response;

Stream stream;

XmlTextReader reader;

XmlDocument xmldoc;

request = WebRequest.Create(url);

response = request.GetResponse();

stream = response.GetResponseStream(); <--CHOKES HERE

// Create new XmlTextReader and XmlDoc

reader = new XmlTextReader(stream); <-- AND SOMETIMES HERE

xmldoc = new XmlDocument();

xmldoc.Load(reader);

Xml pageXML = new Xml();

pageXML.Document = xmldoc;

pageXML.TransformSource = "~/style/RSSReader.xsl";

// Add to plFeeds placeholder

this.plFeeds.Controls.Add(pageXML);

reader.Close();

stream.Close();

request = null;

response = null;

stream = null;

reader = null;

xmldoc = null;
 
D

David Hogue

dkode said:
I built an asp.net usercontrol that consumes rss feeds that I specify
the url for.

Some of them (MVP blogs, google news) consumes the feeds just fine. and
other times (75%) it chokes on stream.length and stream.position with
an Exception of type System.NotSupportException.

It looks like the stream that is returned is a ConnectStream which
doesn't support the Length and Position properties. (This has got to
violate some principle of OO design...)

The XmlTextReader might be seeing invalid xml and trying to recover by
looking ahead or behind. You could try copying the stream to a
MemoryStream or saving to a file for debugging purposes and then loading
it. XmlTextReader might give some a more useful error message that way.
It seems as if with some RSS feeds, they are not formatted correctly?
What can I do to get these to work properly.

There are a lot of feeds that are not valid out there. I refreshed the
Slashdot feed in Firefox a few times and it was usually valid, but not
always. 9 out of 10 it was valid though.
One that is giving me problems is the slashdot rss :
http://rss.slashdot.org/Slashdot/slashdot

The Slashdot rss only works sometimes for me, so something is at the
very least odd with the feed.


Some quick and dirty code to copy the stream into a new MemoryStream:

MemoryStream memoryStream = new MemoryStream();
StreamReader streamReader = new StreamReader(stream);
StreamWriter streamWriter = new StreamWriter(memoryStream);
while(!streamReader.EndOfStream)
{
string line = streamReader.ReadLine();
streamWriter.WriteLine(line);
}
memoryStream.Position = 0;
 
D

dkode

Where can I find more information on RSS 2.0, 1.0 and RDF and the
differences between these and how they correlate.

I see that the slashdot rss has an opening tag of <rdf:RDF, while other
feeds have an opening tag of <rss version="2.0"

Do I have to apply a different xsl to format rdf feeds?

This is my first time working with RSS feeds in dotnet and I think I
need to read some information on the actual specification and
differences in these feeds.

Upon further investigation I can take the RSS feed from this newsgroup
via google groups and display it without a problem. At the worst case
scenario, I will just tell the user the feed is not valid. Is there any
exception I can catch to watch for an invalid feed, so that way I dont
have to output non-formattable rss?

thanks for the info!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top