Sign In/My Account | View Cart  
advertisement

Article:
 Pull Parsing in C# and Java
Subject: Returning a RSS Block
Date: 2006-10-20 03:58:05
From: Phil_WBC

I've changed the code to use a specific URL and return the RRS Feed as a block to a page however I don't think I've done it correctly, can anyone tell me where I might have gone wrong? Thank you in advance!


string url = "http://rss.news.yahoo.com/rss/topstories";
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting = Formatting.Indented;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
WebResponse resp = wr.GetResponse();
Stream stream = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(stream);
reader.XmlResolver = null; // ignore the DTD
reader.WhitespaceHandling = WhitespaceHandling.None;
strRSS = rssreader.RSSToHtml(reader, writer);


return strRSS;


Previous Message Previous Message   Next Message No Next Message


Titles Only Titles Only Newest First
  • Returning a RSS Block
    2006-10-20 06:15:41 Niel Bornstein

    The problem with this approach is that rssreader.RSSToHtml() does not return anything. It expects to place its output in the XmlWriter that is passed in.


    What you want to do is have the XmlWriter write to a StringWriter instead of the console:


    ...
    StringWriter sw = new StringWriter();
    XmlTextWriter writer = new XmlTextWriter(sw);
    ...
    rssreader.RSSToHtml(reader, writer);
    return sw.ToString();

    • Returning a RSS Block
      2006-10-24 01:52:23 Phil_WBC

      Thanks, this works perfectly. It's only returning one result (the top one) from the URL though, is it possible to return more?

      • Returning a RSS Block
        2006-10-25 08:28:24 Niel Bornstein

        That could be a problem with the specific RSS feed or some bug in my code. RSS is really under-specified, so there's no way a small snippet like this could handle all the variants that are out there. Your best bet is find another RSS library that handles everything gracefully.

        • Returning a RSS Block
          2006-10-25 09:08:26 Phil_WBC

          Oh, OK. It seems to do the same for all RSS Feeds, just display the top item.


Sponsored By: