Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an RSS feed with Java?

Tags:

java

rss

rome

I'm using Java, and need to generate a simple, standards-compliant RSS feed. How can I go about this?

like image 401
Dónal Avatar asked Sep 22 '08 03:09

Dónal


People also ask

What is an RSS feed example?

An RSS (Really Simple Syndication) feed is an online file that contains details about every piece of content a site has published. Each time a site publishes a new piece of content, details about that content—including the full-text of the content or a summary, publication date, author, link, etc.

What is SyndFeed?

public interface SyndFeedextends Cloneable, CopyFrom, Extendable. Bean interface for all types of feeds. It handles all RSS versions and Atom 0.3, it normalizes all info, it may lose information.


1 Answers

I recommend using Rome:

// Feed header SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("rss_2.0"); feed.setTitle("Sample Feed"); feed.setLink("http://example.com/");  // Feed entries List entries = new ArrayList(); feed.setEntries(entries);  SyndEntry entry = new SyndEntryImpl(); entry.setTitle("Entry #1"); entry.setLink("http://example.com/post/1"); SyndContent description = new SyndContentImpl(); description.setType("text/plain"); description.setValue("There is text in here."); entry.setDescription(description); entries.add(entry);  // Write the feed to XML StringWriter writer = new StringWriter(); new SyndFeedOutput().output(feed, writer); System.out.println(writer.toString()); 
like image 67
Ben Hoffstein Avatar answered Sep 20 '22 21:09

Ben Hoffstein