This will generate an RSS XML document using the supplied
JDOM Document
.
StringBuffer rss = new StringBuffer();
rss.append("<?xml version=\"1.0\"?>\n")
.append("<!DOCTYPE rss PUBLIC ")
.append("\"-//Netscape Communications//DTD RSS 0.91//EN\" ")
.append("\"http://my.netscape.com/publish/formats/rss-0.91.dtd\">\n")
.append("<rss version=\"0.91\">\n")
.append(" <channel>\n")
.append(" <title>Technical Books</title>\n")
.append(" <link>http://newInstance.com/javaxml/techbooks</link>\n")
.append(" <description>\n")
.append(" Your online source for technical materials, computers, ")
.append("and computing books!\n")
.append(" </description>\n")
.append(" <language>en-us</language>\n")
.append(" <image>\n")
.append(" <title>mytechBooks.com</title>\n")
.append(" <url>")
.append("http://newInstance.com/javaxml/techbooks/images/techbooksLogo.gif")
.append("</url>\n")
.append(" <link>http://newInstance.com/javaxml/techbooks</link>\n")
.append(" <width>140</width>\n")
.append(" <height>23</height>\n")
.append(" <description>\n")
.append(" Your source on the Web for technical books.\n")
.append(" </description>\n")
.append(" </image>\n");
// Add an item for each new title with Computers as subject
List books = doc.getRootElement().getChildren("book");
for (Iterator i = books.iterator(); i.hasNext(); ) {
Element book = (Element)i.next();
if (book.getAttribute("subject")
.getValue().equals("Computers")) {
// Output an item
rss.append("<item>\n")
// Add title
.append(" <title>")
.append(book.getChild("title").getContent())
.append("</title>\n")
// Add link to buy book
.append(" <link>")
.append("http://newInstance.com/javaxml/techbooks/buy.xsp?isbn=")
.append(book.getChild("saleDetails")
.getChild("isbn")
.getContent())
.append("</link>\n")
.append(" <description>")
// Add description
.append(book.getChild("description").getContent())
.append("</description>\n")
.append("</item>\n");
}
}
rss.append(" </channel>\n")
.append("</rss>");
return rss.toString();