RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Develop a Mobile RSS Feed the Easy Way : Page 2

Find out how to take your basic web development skills and build a mobile J2ME application.

Your Mobile RSS Feed: Building a Connection
Now for the interesting part. You need to create an Internet connection and go get a feed. You'll use the Breeze Feature pack for internet requests and DOM manipulation and include the following lines in the index.html:

<meta name="cascada-include" content="xmlhttprequest;xmldom" optional="false" />
The above code tells the Breeze compiler that you want to include these Breeze features and that they are required for the application to work (because phones have limited resources you don't want to automatically include everything).

To keep things clean, place your JavaScript in another file called res/devx.js. Your project should now look like Figure 3.

Figure 3. Keep Your Files Organized: Place your JavaScript in another file called res/devx.js.

Now that you've included the feature packs for your application, you can create your request and result handler, called resultFunction. This function load makes the request for data over the internet, and you'll call it when your app starts up.

You'll need to put a call to the load function in my application and you might as well put that in the onload for the index.html page:

<body onload = "load('http://feeds.feedburner.com/DevxLatestWirelessContent?format=xml');">
Place the above function's definition in devx.js and define it as follows:

function load(url)
	xmlhttp=new CMXMLHttpRequest();

	if (xmlhttp!=null)
  		xmlhttp.open("GET", url );
Notice that the example sets up a result handler to deal with state changes in the request. This is where you put your code to deal with the response when it comes back:

function resultFunction()
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		xmlDoc=new CMXMLDocument();
		xmlDoc.loadXML( xmlhttp.responseText );	
//just print it in the console for now so I can see it		
This will ensure that you get your data back and can view it in the console (see Figure 4).

Figure 4. Viewing Data in the Console: The result handler deals with the returned data, allowing you to view it in the console.
Figure 5. The App in Breeze: This is what your application should look like when viewed through the Breeze Eclipse plug-in.

You'll populate the data back into your page using the DOM. First, add a function called parseFunction, that will pick data out of the response XML DOM.

To keep this a little cleaner, use some variables to reference various elements. To further keep things simple, take the first news item starting with index 0, as shown in Listing 3.

Do the same for the date and text of the article.

So what does the app look like viewed in the Breeze Eclipse plug-in? See Figure 5.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date