2 Replies Latest reply on Jan 28, 2009 3:38 AM by MF100

    RSS FEEDS

    MF100
      Hi All,

      Sorry not an expert here, so please bear with me.

      I am creating a Director Presentation which will be running in a reception area. I would liek to incorporate the BBC RSS News feed as scroller along the bottom, is this possible and if so how?

      I have search the forum for RSS but nothing comes back.

      Thanks in advance.
        • 1. Re: RSS FEEDS
          Production Monkey Level 3
          Retrieving data from an RSS feed and displaying it requires the following steps:

          1. Use "getNetText()" to make a call to a server.
          2. Monitor the network operation for completion.
          3. Convert the returned text into XML and then into an xml Property list.
          4. Navigate the xml property list to pull useful data out it.
          5. Format the data and display in text members.

          Most of that is fairly straight forward, but pulling data out of the xml property list that Director generates is a bit of a pain.

          To help the community out, I took a few hours and wrote a generic, basic RSS object that makes pulling data from an RSS feed much, much easier. The caveat is that I just wrote it and have not done extensive testing. The four samples I provide work well and hopefully it will work just as well for other feeds.

          The RSS object is a Parent script which I will attach at the end of this post. The following is a Behavior script designed to demonstrate how to use the RSS object. Paste the following script into a behavior script member and attach it to a Text member sprite with scrolling enabled:

          -- RSS Demo

          -- These globals should be Properties.
          -- For Demo purposes they are globals, thus you can easily look at them in the Object inspector and analyze their data structures.
          global gYahoo, gDirector, gYouTube, gGoogleUK

          Property pMe -- this sprite

          on beginSprite me
          pMe = sprite(me.spriteNum)
          pMe.member.text = "" -- clear text display

          gGoogleUK = script("Basic RSS").new(" http://news.google.com/news", ["ned":"uk","topic":"n","output":"atom"], me, #showNetData)
          gGoogleUK.start()

          -- gDirector = script("Basic RSS").new(" http://www.adobe.com/cfusion/webforums/forum/rss.cfm", ["forumid":"11","catid":"186"], me, #showNetData)
          -- gDirector.start()

          -- gYouTube = script("Basic RSS").new(" http://gdata.youtube.com/feeds/base/standardfeeds/recently_featured", ["client":"ytapi-youtube-browse","alt":"rss"], me, #showNetData)
          -- gYouTube.start()

          -- gYahoo = script("Basic RSS").new(" http://rss.news.yahoo.com/rss/topstories", [], me, #showNetData)
          -- gYahoo.start()
          end beginSprite


          on showNetData me, Error, ErrorMsg, RssObject
          if Error then
          pMe.member.text = "There was a network error." & return & return & ErrorMsg
          else
          if RssObject = gGoogleUK then -- show sample of using the RssObject to display entry node data for the Google UK feed.
          -- The content returned from google is in HTML format so we will utilize the html capabilities of this text sprite.
          aString = "<html><body>"

          -- add the "title" and "content" for each entry to aString.
          repeat with Entry in RssObject.entries
          put Entry.title & "<br>" & Entry.content & "<p>" after aString
          end repeat

          put "</html></body>" after aString
          pMe.member.html = aString

          else -- display source text returned from server
          pMe.member.text = RssObject.source
          end if
          end if
          end showNetData
          -------------------------------------------------------------------------------------

          You will need a "go the frame" script to keep director running. And, you will need to paste the script below into a Parent script called "Basic RSS".

          Hit play and within a couple seconds the latest news from Google UK should appear.

          The behavior created a global RSS object called "gGoogleUK". I used a global here for demonstration purposes. In the real world you would probably want to use a script property to store the RSS object.

          In the Object Inspector type "gGoogleUK" under the "Name" column. Hit enter.

          The object inspector is the best tool for exploring what information the RSS object provides. The information will be different for each object/feed. Begin exploring by clicking on the "ancestor" property. Keep clicking and expanding. This is a property list version of the xml data that was sent from the server. Unfortunately it is complicated. To display the title of the first “entry” node, you need the following code:

          put gGoogleUK[1][2][9]["title"][2]

          Not pretty, and the code will change as the feed data changes.

          The RSS object simplifies things. The code is:

          put gGoogleUK.entries[1].title

          The object automatically creates a list of all of the “entries”. If you go to the “entries” property in the Object inspector you can see the available data. In the behavior I show how this greatly simplifies placing data into a text sprite. I.e.

          repeat with Entry in RssObject.entries
          put Entry.title & "<br>" & Entry.content & "<p>" after aString
          end repeat


          The RSS object provides four short cut properties: “feed”,”channel”,”entries”,”items”. Most of the time those four properties will contain the data that you want to display. Not all of these properties will contain information at the same time. The properties that contain useful data depends upon the type of feed that the object connects to. The Google UK feed uses ATOM and therefore only “feed” and “entries” contain data. If you don’t know what properties your feed will populate, well that is where the object inspector comes in handy.

          So, you are asking, “What if I need a different set of xml node data ?”

          I provide a method for retrieving the data associated with any node type. This method alone makes dealing with the xml data very simple. It traverses the entire XML document/list and returns a list of the data for each node with a matching node name. Lets say you want a list of all the “titles”

          Titles = gGoogleUK.getNodes("title")

          Or, more useful you want to know who is contributing the most videos to YouTube.

          YouTubeAuthors = gYouTube.getNodes("author")

          You will have to un-comment the youtube code in the behavior to see that work.

          That is the basics. I tried to hide all the complexity. To get a feel for how to work with the object, un-comment all of the sample feeds in the behavior and look at the object structures in the Object Inspector. All four feeds can run simultaneously.

          Take a look a the Public methods of the “Basic RSS” script for additional information and methods; and certainly look at all of the code in the behavior to see how to create and work with the rss object.

          One note:

          You can not destroy the RSS object just by setting the variable holding it to void. You must call “stop()” first, otherwise it will still hang around and possibly cause problems.

          gGoogleUK.stop()
          gGoogleUK = void
          • 2. Re: RSS FEEDS
            MF100 Level 1
            Blimey - thank you very much - I am starting this project in a couple of weeks so will let you know how it goes :-)