Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.w3c.dom.Document;
- import org.w3c.dom.NodeList;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import java.net.URL;
- public class RSSParser {
- private Feed feed = new Feed();
- private URL url;
- private String noteName;
- public RSSParser(URL url) {
- this.url = url;
- }
- public void RSSFeed() {
- try {
- DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document doc = builder.parse(url.openStream());
- NodeList object = doc.getElementsByTagName("item");
- NodeList partOfObject = doc.getElementsByTagName(noteName);
- for(int i = 0; i<object.getLength(); i++){
- noteName = "title";
- feed.setTitle(partOfObject.item(0).getFirstChild().getNodeValue());
- noteName = "description";
- feed.setDescription(partOfObject.item(0).getFirstChild().getNodeValue());
- noteName = "author";
- feed.setAuthor(partOfObject.item(0).getFirstChild().getNodeValue());
- noteName = "link";
- feed.setAuthor(partOfObject.item(0).getFirstChild().getNodeValue());
- feed.entries.add(feed.toString());
- }
- } catch (Exception e) {
- System.out.println("Blad przy parsowaniu adresu URL.");
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement