Wed, 4 Aug 2004 12:13:00 CEST There are a lot of empty elements, but you can see you have the makings of a reasonable feed. How It Works The way Relaxer works internally is well beyond the scope of this book (it s quite well documented with the download, if you re interested) but the use of the files it generated is somewhat easier to explain. Essentially, a class has been generated for each of the higher-level elements found in the sample feed: Rss, Channel, Item. Each of these classes has been provided with appropriate get and set methods corresponding to each kind of material the XML elements can contain. To create a feed using these classes is as easy as can be, as you can see from the code example here. The code actually starts by setting up a date class to match the RSS 2.0 formatting: import java.text.SimpleDateFormat; import java.util.Date; public class Rss2Create { public static final SimpleDateFormat RFC822 = new SimpleDateFormat( EEE, d MMM yyyy HH:mm:ss z ); The code that will run is contained in this class s main method. It begins by creating a new instance of the Rss class. The version is set to 2.0 by a call to a method in that class which has been auto-generated by Relaxer: public static void main(String[] args) { try { Rss rss = new Rss(); rss.setVersion(2.0F); Every RSS 2.0 feed must have a channel element, and that s easy to provide here by creating a Channel object. Before assigning the channel to the Rss, its title is set: Channel channel = new Channel(); channel.setTitle( A Demo Channel ); rss.setChannel(channel); The interesting parts of a feed are its items, and objects that model these can be created using the Item class. In this example, a single item is created and the value of a couple of its contained elements are set before the item is added to the channel: Item item = new Item(); item.setTitle( One Item ); String date = RFC822.format(new Date()); item.setPubDate(date); channel.addItem(item); 263 Modeling Feed Data
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.
This entry was posted
on Saturday, August 25th, 2007 at 5:55 pm and is filed under j2ee.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.