Java tutorial
//package com.java2s; /** (C) Copyright 1998-2007 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * Add a RSS 2.0 Item to your channel node <channel> * Note: None of the parameter is supposed to be NULL * * @param XMLDocument the current XML Document * @param channelRoot your channel node * @param title title of your entry * @param link link to further information * @param guid globally unique identifier - same as link * @param pubDate date of the new entry * @param text text of the item */ public static void addRSSItem(Document XMLDocument, Node channelRoot, String title, String link, String guid, String pubDate, String text) { // Create <item> node Node entry = XMLDocument.createElement("item"); // Set title node beneath <item> Node subentry = XMLDocument.createElement("title"); subentry.appendChild(XMLDocument.createTextNode(title)); entry.appendChild(subentry); // Set link node beneath <item> subentry = XMLDocument.createElement("link"); subentry.appendChild(XMLDocument.createTextNode(link)); entry.appendChild(subentry); // Set guid node beneath <item> subentry = XMLDocument.createElement("guid"); subentry.appendChild(XMLDocument.createTextNode(guid)); entry.appendChild(subentry); // Set pubDate beneath <item> subentry = XMLDocument.createElement("pubDate"); subentry.appendChild(XMLDocument.createTextNode(pubDate)); entry.appendChild(subentry); // Set last message node beneath <host> subentry = XMLDocument.createElement("description"); subentry.appendChild(XMLDocument.createTextNode(text)); entry.appendChild(subentry); channelRoot.appendChild(entry); } }