Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <item>
- <title>Caldes col·loca quatre desfibril·ladors en llocs públics</title>
- <description><p>Notícia emesa a l'informatiu del dia 21 de novembre de 2014.</p></description>
- <enclosure type="image/jpeg" url="image.jpg" length="16003"/>
- <enclosure type="text/html" url=" URL THAT I WANT " length="0"/>
- <pubDate>Fri, 21 Nov 2014 18:26:00 +0000</pubDate>
- <link>http://url1</link>
- <guid>http://url2</guid>
- </item>
- headlines = new ArrayList();
- links = new ArrayList();
- try {
- URL url = new URL("RSS URL");
- XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
- factory.setNamespaceAware(false);
- XmlPullParser xpp = factory.newPullParser();
- xpp.setInput(getInputStream(url), "UTF_8");
- boolean insideItem = false;
- // Returns the type of current event: START_TAG, END_TAG, etc..
- int eventType = xpp.getEventType();
- while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG) {
- if (xpp.getName().equalsIgnoreCase("item")) {
- insideItem = true;
- } else if (xpp.getName().equalsIgnoreCase("title")) {
- if (insideItem)
- headlines.add(xpp.nextText()); //extract the headline
- } else if (xpp.getName().equalsIgnoreCase("link")){ //link
- if (insideItem)
- links.add(xpp.nextText()); //extract the link of article
- }
- }else if(eventType== XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
- insideItem=false;
- }
- eventType = xpp.next(); //move to next element
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (XmlPullParserException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement