SHARE
TWEET

Aufgabe D3: Main

RandomGuy32 Nov 29th, 2019 (edited) 100 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top