RandomGuy32

Aufgabe D3: Main

Nov 29th, 2019
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.net.URL;
  3. import java.net.URLConnection;
  4.  
  5. import org.xml.sax.InputSource;
  6. import org.xml.sax.SAXException;
  7. import org.xml.sax.XMLReader;
  8. import org.xml.sax.helpers.XMLReaderFactory;
  9.  
  10. public class Main {
  11.     public static void main(String[] args) {
  12.         try {
  13.             // XMLReader erzeugen
  14.             XMLReader xmlReader = XMLReaderFactory.createXMLReader();
  15.  
  16.             URL url = new URL("http://www.tagesschau.de/xml/rss2");
  17.  
  18.             URLConnection connection = url.openConnection();
  19.  
  20.             connection.setDoInput(true);
  21.  
  22.             InputStream inputStream = connection.getInputStream();
  23.  
  24.             BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
  25.  
  26.             InputSource inputSource = new InputSource(in);
  27.  
  28.             xmlReader.setContentHandler(new RSSContentHandler());
  29.  
  30.             xmlReader.parse(inputSource);
  31.  
  32.             in.close();
  33.  
  34.             for (NewsItem i: (RSSContentHandler) xmlReader.getContentHandler()) {
  35.                 System.out.println(i.getTitle());
  36.             }
  37.         }
  38.         catch (Exception e) {
  39.             e.printStackTrace();
  40.         }
  41.     }
  42. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×