Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

RSS Data Dump Java code example - Click here to copy ->>>

   Can't find what you're looking for? Try our search:

Really working examples categorized by API, package, class. You can compile and run our examples right away! Not from source code for Java projects - only working examples! Copy, compile and run!

Code:

 
/*   http://www.oreilly.com/catalog/sax2/
 * SAX2
 *   By David Brownell
 *   First Edition January 2002
 *   ISBN: 0-596-00237-8
 */


 import gnu.xml.util.Resolver;
import java.io.File;
import java.util.Hashtable;
import org.xml.sax.*;
import org.xml.sax.helpers.XMLReaderFactory;
import RssChannel.RssItem;

/**
 * RSS Data Dump
 */
public class RssMain
{
    private static String featurePrefix =
   "http://xml.org/sax/features/";

    /** Invoke with one argument, a URI or filename */
    public static void main (String argv [])
    {
   if (argv.length != 1) {
       System.err.println ("Usage: RssMain [file|URL]");
       System.exit (1);
   }

   try {
       XMLReader      reader;
       RssConsumer      consumer;
       Hashtable      hashtable;
       Resolver      resolver;

       reader = XMLReaderFactory.createXMLReader ();

       consumer = new RssConsumer ();
       reader.setContentHandler (consumer);

       // handle the "official" DTD server being off-line
       hashtable = new Hashtable (5);
       hashtable.put (
      "-//Netscape Communications//DTD RSS 0.91//EN",
      Resolver.fileNameToURL ("rss-0_91.dtd"));
       resolver = new Resolver (hashtable);
       reader.setEntityResolver (resolver);

       // we rely on qNames, and 0.91 doesn't use namespaces
       reader.setFeature (featurePrefix + "namespace-prefixes", true);
       reader.setFeature (featurePrefix + "namespaces", false);

       argv [0] = Resolver.getURL (argv [0]);
       reader.parse (argv [0]);

       RssChannel      channel = consumer.getChannel ();

       System.out.println ("Partial RSS 0.91 channel info");
       System.out.println ("SOURCE = " + channel.sourceUri);
       System.out.println ();

       System.out.println ("         Title: " + channel.title);
       System.out.println ("   Description: " + channel.description);
       System.out.println ("          Link: " + channel.link);
       System.out.println ("      Language: " + channel.language);
       System.out.println ("     WebMaster: " + channel.webMaster);
       System.out.println ("ManagingEditor: " + channel.managingEditor);
       System.out.println ();

       System.out.println ("    Item Count: " + channel.items.size ());
       for (int i = 0; i < channel.items.size (); i++) {
      RssItem      item = (RssItem)
                channel.items.elementAt (i);
      System.out.println ("ITEM # " + i);
      if (item != null) {
          System.out.println ("         Title: " + item.title);
          System.out.println ("   Description: " + item.description);
          System.out.println ("          Link: " + item.link);
      }
       }

   // Good error handling is not shown here, for simplicity
   } catch (Exception e) {
       System.err.println ("Whoa: " + e.getMessage ());
       System.exit (1);
   }
   System.exit (0);
    }
}


 
 



References.

The list of classes which were used on this page you can find below. The links to Java API contain official SUN documentation about all used classes.




[ Go Back ]



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy