Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

New Developer
Posts: 13
Registered: ‎12-03-2009
My Device: Not Specified
Accepted Solution

Get an XML code from a URL in the widget

We are making a Blackberry widget to display RSS feeds. So we want to get the XMl code of the RSS feeds, say from the link,



Right now, we are directyl opening the link and showing the feeds on the browser using href in html. But we want to categorize the feeds based on the location and date, so we want to get the XML tags and then parse it using an XML parser using Javascript.


Please let us know asap.



Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Get an XML code from a URL in the widget

You should be able to retrieve the URL http://www.puuba.com/team/blog.rss in an AJAX request.  The responseXML property of the XMLHttpRequest object is an already parsed XML object.  You can then look at the contents of the XML and categorize it accordingly.


Here is an interesting article on the topic I found:


Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 13
Registered: ‎12-03-2009
My Device: Not Specified

Re: Get an XML code from a URL in the widget

I am trying to do that but I get errors using XMLHttpRequest(), xmlhttp.onreadystatechange saying the methods are not resolved.


This is the code I am using:


I have created a blackberry web project RSSXML and made files index.html which looks like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id=”viewport” content="initial-scale=1.0,user-scalable=no">
<script type="text/javascript" src="getrss.js"></script>
<title>Insert title here</title>

Select an RSS-feed:
<select onchange="showRSS(this.value)">
<option value="Google">Google News</option>
<option value="MSNBC">MSNBC News</option>

<p><div id="rssOutput">
<b>RSS-feed will be listed here...</b></div></p>


and getrss.js is as follows:


//<script language="javascript">
var xmlhttp;

function showRSS(str)
    xmlhttp=new XMLHttpRequest();
  if (xmlhttp==null)
    alert ("Your browser does not support XML HTTP Request");
  var url="getrss.php";

function stateChanged()
  if (xmlhttp.readyState==4)

function GetXmlHttpObject()
if (window.XMLHttpRequest)
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
if (window.ActiveXObject)
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
return null;



and I made a file and named it getrss.php and put it in this project.


//get the q parameter from URL

//find out which feed was selected

$xmlDoc = new DOMDocument();

//get elements from "<channel>"
$channel_title = $channel->getElementsByTagName('title')
$channel_link = $channel->getElementsByTagName('link')
$channel_desc = $channel->getElementsByTagName('description')

//output elements from "<channel>"
echo("<p><a href='" . $channel_link
  . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");

//get and output "<item>" elements
for ($i=0; $i<=2; $i++)

  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo ("<br />");
  echo ($item_desc . "</p>");



Firstly, I want to know why I am getting errors using the XMLHTTPRequest and any of its methods.

Secondly, am I allowed to use PHP like the way I am using in blackberry widgets?


Please let me know as soon as u can, m in a rush. Thanks