This page was last modified 12:06, 8 November 2007.
Como usar feeds RSS em Widgets WRT
From Forum Nokia Wiki
Compatibilidade: Web Run-Time na S60 3rd Edition, Feature Pack 2
Contents |
Código de exemplo
Este exemplo contém código JavaScript para fazer a leitura de feeds RSS. O parsing de feeds RSS é feito utilizando-se JavaScript padrão - entretanto desenvolvedores devem introduzir manipuladores de condições de erro para os casos em que o aparelho estiver fora da rede, sem SIM card, etc. ou a ação tenha sido cancelada pelo usuário.
Requisição
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; }
Callback da requisição
function ReqStateChange() { if (req.readyState == 4) { if (req.status == 200) { UpdateContent(req); } else { alert("error"); } } }
Interpretador de RSS
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 |
| Eliminar mensaje conexion via Bluetooth pc - movil | enjutapeich | Foro en Español (Spanish Forum) | 0 | 2008-06-22 13:06 |
| Do .loc files *have* to be compiled? | AshramArzephucque | General Symbian C++ | 6 | 2008-01-11 22:17 |
| Welcome | emulators | WRT Widget Development | 0 | 2007-06-26 17:05 |
| [Moved] .rss in .mmp file | shaista | General Symbian C++ | 5 | 2008-06-13 04:59 |
| not able to see the application on the device | krgvs | General Symbian C++ | 5 | 2008-03-10 09:22 |
