Recent Changes - Search:

Distributed Computing

This website demonstrates using wikis as teaching and learning tool.

The course instructor is also happy to share the teaching materials here with those who find it readable.

XML Processing with Java

Introduction

This is a programming task for you to practice XML processing with Java.

RSS stands for "Really Simple Syndication" and is used for the distribution of newsfeeds and podcasts. RSS feeds are merely XML files based on a version of the RSS standard. For example, the following URL is the XML file of RTHK Instant News RSS feed: http://www.rthk.org.hk/rthk/news/rss/c_expressnews.xml

There are several frameworks that allow you to work with RSS. Sun has its own RSS library named RSS utilities, which provides some APIs for you to parse RSS easily. The following article provides you more information about the RSS utilities:

I downloaded the RSS utilities form the following URL:

and put the rssutils.jar into my Java classpath.

I then write the following Java program to test the RSS parsing with Java. You can compile the program and test it yourself.

import java.io.*;
import java.net.*;
import java.util.*;
import com.sun.cnpi.rss.parser.*;
import com.sun.cnpi.rss.elements.Rss;
import com.sun.cnpi.rss.elements.Item;
import com.sun.cnpi.rss.elements.Category;

class TestRSS {

public void readRSSDocument() throws Exception{

    RssParser parser = RssParserFactory.createDefault();
    Rss rss = parser.parse(new URL("http://www.rthk.org.hk/rthk/news/rss/c_expressnews.xml"));

    //Get all XML elements in the feed

     Collection items = rss.getChannel().getItems();
        if(items != null && !items.isEmpty())
        {
        //Iterate over our main elements. Should have one for each article

            for(Iterator i = items.iterator();
                i.hasNext();
                System.out.println())
            {
                Item item = (Item)i.next();
                System.out.println("Title: " + item.getTitle());
                System.out.println("Link: " + item.getLink());
                System.out.println("Description: " + item.getDescription());
            }

        }
    //Iterate over categories if we are provided with any

        Collection categories = rss.getChannel().getCategories();
        if(categories != null && !categories.isEmpty())
        {
            Category cat;
            for(Iterator i = categories.iterator();
                i.hasNext();
                System.out.println("Category Domain: " + cat.getDomain()))
            {
                cat = (Category)i.next();
                System.out.println("Category: " + cat);
            }

        }
}

   public static void main(String A[]) {
        System.setProperty ("http.proxyHost","proxy.ouhk.edu.hk");
        System.setProperty ("http.proxyPort","8080");

        TestRSS rss = new TestRSS();
                try {
                        rss.readRSSDocument();
                        }catch(Exception e) {}
        }
}

Reference

Reading the News with Sun's RSS Utilities (by Chris Hardin on 03/21/2006) (URL: http://today.java.net/lpt/a/275)

Your Tasks

Use the Sun RSS API to write a GUI version of the above program (i.e. a RSS reader program).

You are free to design the UI for the program. However, the following suggests a way to do it.

Course Requirement and Assessment

You need to demonstrate your work to your instructor in a tutorial session. Your instructor may ask you some questions to test your knowledge.

This programming task is a part of your continuous assessment. The maximum point awarded is 20. The assessment is roughly based on the following criteria:

  1. You program constructs appropriate GUI. (5 points)
  2. Your program works and displays all the required information when RSS is inputted. (5 points)
  3. Event driven programming (the program works when a new RSS is inputted. Text area is cleaned up, etc) (5 points)

The last 5 points give those students who can enhance the above program by allowing inputting and downloading more than one RSS feeds. The program then combines two feeds contents and displays them together.

Edit - History - Print - Recent Changes - Search
Page last modified on July 18, 2007, at 02:10 PM