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 List liste = new ArrayList();
72 List items = new ArrayList();
73 JSONArray feld = null;
78 SAXBuilder builder = new SAXBuilder();
81 // Die Ergebnisse "raussuchen"
82 doc = builder.build(new StringReader(rss.toString()));
83 root = doc.getRootElement();
84 channel = root.getChild("channel");
85 int tt = channel.getContentSize();
86 items = channel.getChildren("item");
87 iter = items.iterator();
88 // iter = channel.getDescendants();
89 // alle Items auslesen und die Links auslesen
90 while (iter.hasNext())
92 // Ist Item = Text dann überlesen
93 // anderenfalls die Rückgabe füllen
96 item = (Element) iter.next();
97 title = item.getChild("title");
98 link = item.getChild("link");
99 fm.setTitle(title.getText());
100 fm.setLink(link.getText());
102 fm = new FeedMessage();
104 // tmp = item.getName();
105 // if ((tmp.equals("title")) || (tmp.equals("link")))
107 // if (tmp.equals("title"))
109 // fm.setTitle(item.getValue());
111 // if (tmp.equals("link"))
113 // fm.setLink(item.getValue());
115 // fm = new FeedMessage();
122 System.out.println("test1");
124 System.out.println("test2");
128 catch (JDOMException e)
130 // TODO Auto-generated catch block
133 catch (IOException e)
135 // TODO Auto-generated catch block
140 return (ArrayList)liste;