Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 08:03, 6 June 2008.

Web Runtime WidgetでRSSを使用する方法

From Forum Nokia Wiki


原文(英語): How-to use RSS in WRT widgets

対象となるバージョン: Web Runtime in S60 3rd Edition, Feature Pack 2

Contents

コード例

これは、RSSフィードを解析するためのJavaScriptのコード例を含んでいます。RSSの解析は通常のJavaScript関数で行えますが、開発者は、モバイル機器に特有のエラーが起こる可能性について考慮する必要があります。

  • SIMカードが挿入されていない
  • アクセスポイントが設定されていない
  • ユーザーによって接続がキャンセルされた

リクエスト操作

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; 
}

リクエストのコールバック処理

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の解析処理

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
Edit mode in AknForms akerfeldt Symbian User Interface 2 2003-10-29 09:35
RuntimeException:for Series 60 2nd Ed SDK for Symbian OS,FP2 Rameshwari Mobile Java General 3 2006-08-11 22:40
Runtime Sockets Creation ??? priya83 Symbian Networking & Messaging 3 2006-08-12 18:16
Icon Library kevin1964 Mobile Java Media (Graphics & Sounds) 2 2004-06-29 20:18
web browser pacifuentes Mobile Java General 1 2008-04-10 06:57
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX