private static String XML_INDENT = "\t";
public static void write(RSSFeed rssfeed, Writer out) throws Exception {
XMLOutputFactory output = XMLOutputFactory.newInstance();
XMLEventWriter writer = output.createXMLEventWriter(out);
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent endSection = eventFactory.createDTD(XML_BLOCK);
StartDocument startDocument = eventFactory.createStartDocument();
writer.add(startDocument);
writer.add(endSection);
StartElement rssStart = eventFactory.createStartElement("", "", "rss");
writer.add(rssStart);
writer.add(eventFactory.createAttribute("version", "2.0"));
writer.add(endSection);
writer.add(eventFactory.createStartElement("", "", "channel"));
writer.add(endSection);
RSSHeader header = rssfeed.getHeader();
createNode(writer, "title", header.getTitle());
createNode(writer, "link", header.getLink());
createNode(writer, "description", header.getDescription());
createNode(writer, "language", header.getLanguage());
createNode(writer, "copyright", header.getCopyright());
createNode(writer, "pubDate", header.getPubDate());
Iterator<RSSEntry> iterator = rssfeed.getEntries().iterator();
while (iterator.hasNext()) {
RSSEntry entry = iterator.next();
writer.add(eventFactory.createStartElement("", "", "item"));
writer.add(endSection);
createNode(writer, "title", entry.getTitle());
createNode(writer, "description", entry.getDescription());
createNode(writer, "link", entry.getLink());
createNode(writer, "guid", entry.getGuid());
createNode(writer, "pubDate", entry.getPubDate());
writer.add(eventFactory.createEndElement("", "", "item"));
writer.add(endSection);
}
writer.add(endSection);
writer.add(eventFactory.createEndElement("", "", "channel"));
writer.add(endSection);
writer.add(eventFactory.createEndElement("", "", "rss"));
writer.add(endSection);
writer.add(eventFactory.createEndDocument());
writer.close();
}