How to write an RSS feed with Java?
Asked Answered
S

1

28

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

Setiform answered 22/9, 2008 at 3:37 Comment(0)
A
41

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());
Assembler answered 22/9, 2008 at 3:39 Comment(4)
That seems like a dead project now. The example won't even compile!Dahlgren
Rome uses java classes from com.sun.syndication.* package. This solution is too old now.Stines
It is really old now? Are there any other alternatives?Menke
In 2023 this seems to work just fine. I just used it with java17 and compiles and runs perfectly. The maven package moved and 2.x requires at least java 8 com.rometools:rome:2.1.0Perceive

© 2022 - 2024 — McMap. All rights reserved.