3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.StringReader;
6 import java.net.MalformedURLException;
8 import java.util.ArrayList;
9 import java.util.Iterator;
10 import java.util.List;
12 import javax.xml.parsers.ParserConfigurationException;
13 import javax.xml.parsers.SAXParser;
14 import javax.xml.parsers.SAXParserFactory;
16 import org.jdom.Document;
17 import org.jdom.Element;
18 import org.jdom.JDOMException;
20 import org.jdom.input.SAXBuilder;
22 import org.json.JSONArray;
23 import org.json.JSONException;
24 import org.json.JSONObject;
25 import org.xml.sax.InputSource;
26 import org.xml.sax.SAXException;
27 import org.xml.sax.XMLReader;
28 import org.xml.sax.helpers.DefaultHandler;
30 import android.content.Context;
31 import android.widget.Toast;
34 public class RSSFeedParser
36 static final String TITLE = "title";
37 static final String DESCRIPTION = "description";
38 static final String CHANNEL = "channel";
39 static final String LANGUAGE = "language";
40 static final String COPYRIGHT = "copyright";
41 static final String LINK = "link";
42 static final String AUTHOR = "author";
43 static final String ITEM = "item";
44 static final String PUB_DATE = "pubDate";
45 static final String GUID = "guid";
50 @SuppressWarnings("null")
51 public ArrayList readFeed(StringBuilder rss)
54 FeedMessage fm = new FeedMessage();
55 boolean isFeedHeader = true;
56 // Set header values intial to the empty string
57 String description = "";
61 String copyright = "";
71 JSONArray feld = null;
75 SAXBuilder builder = new SAXBuilder();
78 // Die Ergebnisse "raussuchen"
79 doc = builder.build(new StringReader(rss.toString()));
80 root = doc.getRootElement();
81 itemListe = root.getChild("channel");
82 iter = itemListe.getDescendants();
83 // alle Items auslesen und die Links auslesen
84 while (iter.hasNext())
86 // Ist Item = Text dann überlesen
87 // anderenfalls die Rückgabe füllen
90 item = (Element) iter.next();
92 if ((tmp.equals("title")) || (tmp.equals("link")))
94 if (tmp.equals("title"))
96 fm.setTitle(item.getValue());
98 if (tmp.equals("link"))
100 fm.setLink(item.getValue());
109 System.out.println("test1");
111 System.out.println("test2");
115 catch (JDOMException e)
117 // TODO Auto-generated catch block
120 catch (IOException e)
122 // TODO Auto-generated catch block
127 return (ArrayList)liste;