Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[4597] RSS Feed Helper Class

Last post 12-19-2006 4:20 AM by sandoftime. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [4597] RSS Feed Helper Class

    This thread is for discussions of RSS Feed Helper Class.

    • Post Points: 20
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 08-17-2004 5:45 PM In reply to

    Too damm useful

    Very nice wrapper
    Digitally Yours,

    Thushan Fernando
    • Post Points: 0
  • 08-19-2004 8:23 AM In reply to

    • shesta
    • Not Ranked
    • Joined on 08-19-2004
    • New Member
    • Points 5

    thanks! and quick item pruner

    thanks for this it helped a lot!  Here's a simple pruning function which would remove past ttl items from the rss feed once its up.  NOTE: i don't correct for time zones if specified at the end of <pubDate>, though you easily could in the for loop.

    Code:

    /// <summary>
       /// Attempts to remove items past their time to live value by opening the RSS feed as an xml document and remove the elements with expired ttl
       /// </summary>
       /// <param name="XmlFileStream">a System.IO.Stream of the feed xml</param>
       /// <returns>updated document as System.IO.Stream</returns>
       public System.IO.Stream PrunePastTtl_getStream(System.IO.Stream XmlFeed)
       {
           XmlDocument        feedDoc    = new XmlDocument();
           XmlNode            docfrag;
           XmlNodeList        nodelist;
           int                prunettl;

           DateTime        TargetPruneDt;
           TimeSpan        ttlTime;

           try
           {
               feedDoc.Load(XmlFeed);

               nodelist = feedDoc.GetElementsByTagName("channel");            
               docfrag = nodelist.Item(0);

               
               string ttlstring = docfrag.InnerXml;

               int begin = ttlstring.IndexOf("<ttl>") + 5;
               int end = ttlstring.IndexOf(@"</ttl>");

               ttlstring = ttlstring.Substring(begin,(end - begin));

               
               prunettl = Convert.ToInt32(ttlstring);
               ttlTime = new TimeSpan(prunettl,0,0,0);
               
               TargetPruneDt = DateTime.Now.Subtract(ttlTime);

               // at this point should know the ttl so process <item>s
           
               for(int i=0; i< docfrag.ChildNodes.Count; i++)
               {
                   if(docfrag.ChildNodes.Item(i).Name == "item")
                   {

                       string blobOXml = docfrag.ChildNodes.Item(i).InnerXml;
                       int pubbegin = blobOXml.IndexOf("<pubDate>") + 9;
                       int pubend = blobOXml.IndexOf("</pubDate>");
                   
                       string pubdate = blobOXml.Substring(pubbegin,(pubend - pubbegin));
                   
                       if(pubdate.IndexOf("+") != -1)
                       {
                           pubdate = pubdate.Remove(pubdate.IndexOf("+"),(pubdate.Length - pubdate.IndexOf("+")));
                       }
                       else if(pubdate.IndexOf("-") != -1)
                       {
                           pubdate = pubdate.Remove(pubdate.IndexOf("-"),(pubdate.Length - pubdate.IndexOf("-")));
                       }

                       DateTime publishDate = DateTime.Parse(pubdate);

                       if(publishDate.Ticks < TargetPruneDt.Ticks)
                       {
                           docfrag.RemoveChild(docfrag.ChildNodes.Item(i));
                           i--;  // if we remove one dont want to skip one as we iterate through
                       }
                   }
               }
           
               System.IO.Stream returnval = new System.IO.MemoryStream();
               feedDoc.Save(returnval);
               returnval.Position = 0;

                       return returnval;
           }
           catch(Exception appEx)
           {
               Exception AppEx = new ApplicationException("Unable to load correctly - " + appEx.Message,appEx);
               throw AppEx;
           }

       }
    • Post Points: 0
  • 12-19-2006 4:20 AM In reply to

    Re: [4597] RSS Feed Helper Class

    When I run the sample, I got this error :

     

    The XML page cannot be displayed

    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


    Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource 'http://localhost/TestLibrary/Default.aspx...

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    ----------^

     

     

    Please anyone advise me to solve the problem, thanks in advance.

    • Post Points: 5
Page 1 of 1 (4 items)