Advertisement
Guest User

Untitled

a guest
Mar 20th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. import org.w3c.dom.Document;
  2. import org.w3c.dom.NodeList;
  3.  
  4. import javax.xml.parsers.DocumentBuilder;
  5. import javax.xml.parsers.DocumentBuilderFactory;
  6. import java.net.URL;
  7.  
  8. public class RSSParser {
  9.  
  10.     private Feed feed = new Feed();
  11.     private URL url;
  12.     private String noteName;
  13.  
  14.     public RSSParser(URL url) {
  15.         this.url = url;
  16.     }
  17.  
  18.     public void RSSFeed() {
  19.         try {
  20.             DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  21.             Document doc = builder.parse(url.openStream());
  22.  
  23.             NodeList object = doc.getElementsByTagName("item");
  24.             NodeList partOfObject = doc.getElementsByTagName(noteName);
  25.             for(int i = 0; i<object.getLength(); i++){
  26.                 noteName = "title";
  27.                 feed.setTitle(partOfObject.item(0).getFirstChild().getNodeValue());
  28.                 noteName = "description";
  29.                 feed.setDescription(partOfObject.item(0).getFirstChild().getNodeValue());
  30.                 noteName = "author";
  31.                 feed.setAuthor(partOfObject.item(0).getFirstChild().getNodeValue());
  32.                 noteName = "link";
  33.                 feed.setAuthor(partOfObject.item(0).getFirstChild().getNodeValue());
  34.                 feed.entries.add(feed.toString());
  35.             }
  36.         } catch (Exception e) {
  37.             System.out.println("Blad przy parsowaniu adresu URL.");
  38.             System.out.println(e.getMessage());
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement