This page was last modified 20:32, 6 March 2008.
How-to use RSS in WRT widgets
From Forum Nokia Wiki
Compatibility: Web Runtime in S60 3rd Edition, Feature Pack 2
Contents |
Example code
This is example contains JavaScript example code for parsing RSS feed. As such RSS parsing is done using standard JavaScript functions - however developers should take into account the possibility of error conditions specific to mobile devices:
- No SIM inserted
- No access point available
- Connection canceled by the end user
request
function loadRSSFeed(url) {
if (null == req) {
req = new XMLHttpRequest();
}
req.onreadystatechange = ReqStateChange;
req.open("GET", url, true);
req.send(null);
document.getElementById("content").innerHTML = "Updating" + url;
}
request callback
function ReqStateChange() {
if (req.readyState == 4) {
if (req.status == 200) {
UpdateContent(req);
}
else {
/*
* if widget is totally dependent of network connection you
* might consider notifying end user. error may occur due to
* network error (GSM/3G), no SIM inserted, invalid access point etc.
* detailed information is not available.
*/
alert("error");
}
}
}
RSS parser
function UpdateContent(reqst) {
var d = null;
var el = document.getElementById("content");
document.getElementById("content").innerHTML = "Updating!";
var rss = null;
var html = "";
rss = reqst.responseXML.documentElement;
if (rss != null) {
var itemTitleNodes = rss.getElementsByTagName("title");
var itemLinkNodes = rss.getElementsByTagName("link");
var itemDescNodes = rss.getElementsByTagName("description");
var c=itemTitleNodes.length;
el.innerHTML="Displaying " + c + " items...";
if (c<=0) {
return;
};
if (c>4) c=3; // limit to four stories
for (var i = 0; i < c; i++) {
var itemLink, itemTitle, itemDesc;
if ((itemTitleNodes[i+2].childNodes[0] != null) &&
(itemLinkNodes[i+2].childNodes[0] != null) &&
(itemDescNodes[i+1].childNodes[0] != null)) {
itemTitle = itemTitleNodes[i+2].childNodes[0].nodeValue;
itemLink = itemLinkNodes[i+2].childNodes[0].nodeValue;
itemDesc = itemDescNodes[i+1].childNodes[0].nodeValue;
}
else {
itemTitle = "RSS feed missing";
itemLink = "???";
itemDesc = "RSS broken";
}
html = html + "<div class='item'><div class='linking'
onClick='widget.openURL(\"" + itemLink +
"\");'>"+itemTitle+"</div></br><div
class='description'>"+itemDesc+"</div></div></br>";
}
}
el.innerHTML = html;
html = null;
el = null;
req = null;
d = document.getElementById("lastupdate");
}
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Widget技术专题 | happywolf | Web Technologies and Multimedia Content- Web 技术和多媒体内容 | 39 | 2008-05-14 08:15 |
| Can v give reference to TRGB in .RSS File | TeachMe | General Symbian C++ | 0 | 2006-05-09 06:41 |
| 请问有人做过把2nd示例中的grid项目移植到3rd吗? | chenpeiwen | Symbian | 1 | 2007-01-12 05:05 |
| Carbide.c++ 1.1 - UI designer removes everything from RSS file | zdenko | Carbide.c++ and CodeWarrior Tools | 3 | 2006-12-21 01:02 |
| Help me,Wait dialog not displaying | yunshiwo | General Symbian C++ | 9 | 2006-11-13 09:33 |
