1. First the SyndFeed instance is created, the preferred syndication format is set and the feed header info (title, link, description) is also set.
第一步,建立feed,指定类型,标题、描述、链接等内容。
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(feedType);
feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://rome.dev.java.net");
feed.setDescription("This feed has been created using ROME (Java syndication utilities");
2. Then a list for entries is created, entries are created and added to the list. Each entry is set with a title, link, published date and a description. The description for the first entry is plain test, for the third entry is HTML. After each entry is created is added to the list.
第二步指,生成feed的内容,一般来说就是列表,如rss文章列表,给每个内容指定标题,链接,正文内容等。
List entries = new ArrayList();
SyndContent description;
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("ROME v1.0");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
entry.setPublishedDate(DATE_PARSER.parse("2004-06-08"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of ROME");
// 建议不能为空,不然用ie看时会有xml错误
entry.setDescription(description);
entries.add(entry);
3. Finally the list with entries is added to the SyndFeed bean. The SyndFeed bean is now ready to be written out to a syndication feed XML document. Note that any of supported syndication formats can be set in the feedType property.
第三步,生成rss或atom等feed源的xml文件,
feed.setEntries(entries);
SyndFeed feed = ...;
Writer writer = ...;
// new FileWriter(fileName);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,writer);
writer.close();
First a SyndFeedOutput instance is created, this instance will work with any syndication feed type (RSS and Atom versions). Then the feed and the writer are given to the SyndFeedOutput instance, the SyndFeedOutput will write the syndication feed XML document represented by the SyndFeed bean to the Writer stream.




















