我使用
rome 1.0为我的java应用程序生成RSS.
在我的java中:
SyndFeed Feed = new SyndFeedImpl(); Feed.setFeedType( "RSS_2.0" ); Feed.setTitle( "My Site" ); Feed.setLink( "http://example.com" ); Feed.setDescription( "Test Site." ); List<SyndEntry> entries = new ArrayList<SyndEntry>(); SyndEntry entry = null; SyndContent description = null; entry = new SyndEntryImpl(); entry.setTitle( "Entry1" ); entry.setLink( "http://example.com/entry1" ); entry.setPublishedDate( new Date() ); description = new SyndContentImpl(); description.setType("text/html"); description.setValue( "This is the content of entry 1." ); entry.setDescription( description ); entries.add( entry ); Feed.setEntries(entries); Writer writer = new FileWriter("/home/jr/Desktop/stream.xml"); SyndFeedOutput output = new SyndFeedOutput(); output.output(Feed,writer); writer.close();
<?xml version="1.0" encoding="UTF-8"?> <RSS xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title>My Site</title> <link>http://example.com</link> <description>Test Site.</description> <item> <title>Entry1</title> <link>http://example.com/entry1</link> <description>This is the content of entry 1.</description> <pubDate>Fri,09 Nov 2012 01:28:57 GMT</pubDate> <guid>http://example.com/entry1</guid> <dc:date>2012-11-09T01:28:57Z</dc:date> </item> </channel> </RSS>
>项目不应包括pubDate和dc:date
>缺少原子:与rel =“self”链接
谢谢.
解决方法
在你的自定义SyndFeed类中,确保你将Date变量命名为与SyndFeed类上的名称不同(即:而不是’publishedDate’,使用类似’pubDate’的东西.这似乎解决了我的问题.
public class CustomSyndFeed extends SyndFeedImpl { protected Date pubDate; @Override public Date getPublishedDate() { return pubDate; } @Override public void setPublishedDate(final Date pubDate) { this.pubDate = new Date(pubDate.getTime()); } }