GeSHi (java):
/*--------------------------------------------------------------------------
RssGrabber class
*****************
By: HappyFace http://www.engineeringserver.com
Contact: info [@] engineeringserver.com
Version: unknown
Last updated: 01/August/2008
"*****************
Note: a demo that grabs and shows rss feeds
//----------------------------------------------------------------------*/
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import com.sun.cnpi.rss.elements.Item;
import com.sun.cnpi.rss.elements.Rss;
import com.sun.cnpi.rss.parser.RssParser;
import com.sun.cnpi.rss.parser.RssParserException;
import com.sun.cnpi.rss.parser.RssParserFactory;
public class RssGrabber {
RssParser parser;
Rss rss;
public static void main(String[] args){
RssGrabber RG = new RssGrabber();
try {
RG.parser = RssParserFactory.createDefault();
RG.rss = RG.parser.parse(new URL("http://www.engineeringserver.com/blog/feed"));
RG.showBlogPost();
} catch (RssParserException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void showBlogPost(){
Collection items = rss.getChannel().getItems();
Iterator i = items.iterator();
while(i.hasNext()){
Item item = (Item)i.next();
System.out.println("Title: " + item.getTitle());
System.out.println("Link: " + item.getLink());
System.out.println("Description: " + item.getDescription());
}
}
}
Копирайты учтены.
/*--------------------------------------------------------------------------
RssGrabber class
*****************
By: HappyFace http://www.engineeringserver.com
Contact: info [@] engineeringserver.com
Version: unknown
Last updated: 01/August/2008
"*****************
Note: a demo that grabs and shows rss feeds
//----------------------------------------------------------------------*/
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import com.sun.cnpi.rss.elements.Item;
import com.sun.cnpi.rss.elements.Rss;
import com.sun.cnpi.rss.parser.RssParser;
import com.sun.cnpi.rss.parser.RssParserException;
import com.sun.cnpi.rss.parser.RssParserFactory;
public class RssGrabber {
RssParser parser;
Rss rss;
public static void main(String[] args){
RssGrabber RG = new RssGrabber();
try {
RG.parser = RssParserFactory.createDefault();
RG.rss = RG.parser.parse(new URL("http://www.engineeringserver.com/blog/feed"));
RG.showBlogPost();
} catch (RssParserException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void showBlogPost(){
Collection items = rss.getChannel().getItems();
Iterator i = items.iterator();
while(i.hasNext()){
Item item = (Item)i.next();
System.out.println("Title: " + item.getTitle());
System.out.println("Link: " + item.getLink());
System.out.println("Description: " + item.getDescription());
}
}
}
Копирайты учтены.
Комментариев нет:
Отправить комментарий