28

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

Shog9
  • 156,901
  • 35
  • 231
  • 235
Dónal
  • 185,044
  • 174
  • 569
  • 824

1 Answers1

40

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());
approxiblue
  • 6,982
  • 16
  • 51
  • 59
Ben Hoffstein
  • 102,129
  • 8
  • 104
  • 120