Gadget behavior on spaces vs live.com?

I am still working on my first gadget and noticed things work really different on live.com compared to spaces. If you want to load what I have so far and see what I mean, the manifest can be found at http://www.incendy.com/MyRSS/rssgadget3.xml

Basically the css is very different and also the function that rebuilds the list does not really work on Spaces and you have to manually refresh the page to get the new feed. Just curious if others have experienced this and have advice on what I should be doing differently.

The function getfeed gets called but the content seems to be cached on Spaces where it works fine on live.com!



Answer this question

Gadget behavior on spaces vs live.com?

  • ctrahan

    Did you just recently make the change Your browser may have cached the old code. In IE, you need to either stop and restart the browser or set it to always fetch the page (Tools->Options, General tab, Browsing History section, Settings in IE7, set "Check for new versions of stored pages" to "Every time I visit the webpage"). Firefox doesn't clear the cache on restart so you'll have to clear manually (Tools->Options, Privacy tab, Clear Now, uncheck everything but Cache). If you're sure you're seeing the correct code but it's still not behaving correctly even with the random bits then I have no clue what's going on. Adding random bits to smash the cache has always worked for me.

    No idea on your border issue. I've mostly had problems with font sizing and list positioning, not so much with borders and colors/sizes.


  • alwz_nikhil

    Thank you Todd0s! I do use the random link, however even with the random link spaces seems to cache the rss feed. I suppose I could get rid of this all together as long as I let the user know that once they refresh they will see the updated feed. Just thought is was weird that spaces did not update the content like I expected it to. As for the xml and xpath I am not too familiar:)

    The one thing about css that really surprised me on live.com was my borders which are specific colors get overridden although they show exactly as I pictured on Spaces. Thanks again for the feedback, I really appreciate it!


  • James Mayer

  • Nightman28

    Thanks for all the help on this, it was a life saver! I do have a question that is probably a no brainer, but I was wondering if it is better to generate an rss feed as the datasource or can you consume a dataset from a web service
  • Onslaught_2000

    Strange.  I just checked out couple gadgets of my own that do the same thing to break the cache and they work just fine up on Spaces.  I tested both the generic proxy and the RSS proxy and saw no difference.  The only difference is that my gadgets pull apart the RSS feeds using XPaths while yours uses Start.Parser.RssParseResponse, so perhaps the caching is happening in the parser.  Try some simple alert()-style debugging.  In OnFeedReceived, do an alert(response.responseXML.documentElement.text); and copy the output for several refreshes (you can ctrl+c on the alert() message box).  Save the output into different files and run a diff on them (using a tool like windiff, if you have it).  If they're different but you're still getting the same output as if it's cached then something's going on in Start.Parser.RssParseResponse and it's time to look into parsing on your own :).

    Here's a link to the w3c.org XPath spec.  That's a little dry reading but it covers XPath syntax fairly well.  You can also lookup the selectNodes() and selectSingleNode() methods for the javascript XML document as those are the functions you'll use to apply XPaths (the former returns an array of nodes that match the XPath, the latter returns only the first matching node).

    Here's an example of code to parse an RSS feed using XPaths.

    var items = response.responseXML.documentElement.selectNodes("//rss/channel/item");

    if (items != null && items.length > 0)

    {

    m_videoItems = new Array(items.length);

    var len = Math.min(items.length, 25);

    for (var i = 0; i < len; i++)

    {

    var link = items[ i ].selectSingleNode("link").text;

    var guid = link.substring(link.indexOf("vid=") + 4);

    var imgSrc = items[ i ].selectSingleNode("media:content/media:thumbnail").attributes.getNamedItem("url").value;

    var title = items[ i ].selectSingleNode("title").text;

    }

    }


  • Lon Lundgren

    It looks like Flickr uses a different "media" namespace than Soapbox (the sample code I posted was from parsing Soapbox RSS feeds). In this case, Flickr's thumbnail ("media:thumbnail") is under "item" directly rather than under "media:content" (that is, if you want to pull the thumbnail as your code seems, you should use "media:thumbnail" in your selectSingleNode() call rather than "media:content/media:thumbnail").

    Also, a word of warning: I have had problems getting Firefox to parse XPaths with namespaces in them ("media:thumbnail" is prefixed by a namespace, "//rss/channel/item" is not) when the feed is pulled through the rss proxy. This is very odd, since the error is thrown from the Atlas compatibility layer. I have no idea why a compatibility layer would be needed to handle XPaths on Firefox, since Firefox arguably has a more robust and complete XML and XPath implementation than IE. Anyway, the upshot of this is that you need to pull your feeds using the generic proxy. BUT if you do that, you have to make sure your feeds are of type "text/plain" or you won't be able to retrieve them from Spaces. Spaces may have changed that restriction recently, but I haven't checked to fidn out.


  • Joe D8

    Thank you Todd0s! That did the trick and generic proxy seems to work, so I went ahead and submitted it so I guess I will find out. Thank you so much for the help! I am now able to use web services and rss to get data all because of you! I really do appreciate your help so much
  • inzel

    Return your data however you like. RSS is a little bit easier to understand than the XML serialization representation of a .NET DataSet, but since you'll pull either apart with XPath queries it doesn't really matter how you represent your data. Your Xpath strings will be different for RSS vs. serialized DataSet, but the rest of your logic will be identical.
  • Philippe Cand

    no, I have been using a random number before I ever tried it on spaces, not sure why it caches it either
  • Scott Croisdale

    Hi!

    Thanks for your example code ToddOs! It helped me a lot.
    But still I have the question, that where can I find a correct API reference documentation for the response.responseXML.documentElement
    , and for the classes,properties,methods related to it
    Because I searched the msdn's HTML and DHTML reference and the msdn2's XmlNode reference , but neither matches 100%.






  • John Mears

    Some bits:

    • Yes, CSS is different between live.com, gallery's preview, and Spaces. You're just going to have to deal with it. "Dealing with it" generally means explicitly setting a lot more attributes than you'd usually expect because you can't rely on inheriting values from the default CSS. Hopefully that gets fixed at some point (they used to be the same until the June update, IIRC).
    • Since you're starting with the RSS sample, you're using the Start.* RSS parser. Don't do that. Start.* namespace items are undocumented and not guaranteed to work at all. Parse your RSS yourself using XPaths. If you need a primer on XPaths, let me know and I'll dig up some links (or you can hit w3c.org and poke around yourself).
    • The caching issue is probably a function of the proxy used by Web.Network.createRequest. In fact I'm surprised that live.com doesn't seem to cache for you, as it's always cached for me. The unsupported, ugly work-around is to add a random number to your URL string ("http://foo.example.com/service.asmx uid=yourid&f=" + Math.random().toString();). Pick a variable name that your server app doesn't care about ("f" in the example I used) which will then be ignored by your service. Live.com/Spaces caching happens on a per-URL basis so by adding a bit of randomness to your URL you will force the proxy to download the "new" url. This isn't the best idea ever since it causes more load on both the live.com/spaces proxy as well as your web service, but it Just Works(tm). I'd only use this if you're working with a data feed that frequently changes. For static or almost-static data, chances are your end user will leave the page with the gadget before they need to refresh the data, and so you shouldn't try breaking the cache. Code not guaranteed to work, use at your own risk, standard disclaimers, etc.


  • ChrisMcCabe

    Todd0sI am trying to use your example to parse the rss from flickr and show it but am having problems. I know the feed works, so it seems something is wrong in the area where I check for the items. If you have the time to take a look maybe it is something really obvious! Thank you!

    function GetFeed()

    {

    var r = Web.Network.createRequest(

    Web.Network.Type.XML,

    m_feedUrl,

    {proxy:"rss", numItems:m_numItems},

    OnFeedReceived);

    r.execute();

    }

    function OnFeedReceived(response)

    {

    m_el.className = "main";

    m_headlinesEl = document.createElement("ul");

    m_headlinesEl.className = "rssList";

    m_el.appendChild(m_headlinesEl);

    var items = response.responseXML.documentElement.selectNodes("//rss/channel/item");

    if (items != null && items.length > 0)

    {

    m_videoItems = new Array(items.length);

    var len = Math.min(items.length, 25);

    for (var i = 0; i < len; i++)

    {

    var link = itemsIdea.selectSingleNode("link").text;

    var imgSrc = itemsIdea.selectSingleNode("media:content/media:thumbnail").attributes.getNamedItem("url").value;

    li = document.createElement("li");

    li.className = "rssItem";

    m_headlinesEl.appendChild(li);

    var aEl = document.createElement("a");

    li.appendChild(aEl);

    aEl.href = link;

    aEl.target = "top";

    aEl.innerHTML = "<img src=" + imgSrc + ">";

    }

    }

    }


  • Alchemy_Mgt

    responseXML is an XMLDocument, while documentElement is the root XMLNode in the document. The documentation you reference should be similar enough to what's available on the javascript object, or you can look at MSXML's IXMLDocument and IXMLNode interfaces (similar to, but not quite the same as, the .NET XML code).
  • Gadget behavior on spaces vs live.com?