Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <item>
  2. <title>Caldes col&#183;loca quatre desfibril&#183;ladors en llocs p&#250;blics</title>
  3. <description><p>Not&#237;cia emesa a l'informatiu del dia 21 de novembre de 2014.</p></description>
  4. <enclosure type="image/jpeg" url="image.jpg" length="16003"/>
  5. <enclosure type="text/html" url=" URL THAT I WANT " length="0"/>
  6. <pubDate>Fri, 21 Nov 2014 18:26:00 +0000</pubDate>
  7. <link>http://url1</link>
  8. <guid>http://url2</guid>
  9. </item>
  10.  
  11. headlines = new ArrayList();
  12. links = new ArrayList();
  13.  
  14. try {
  15. URL url = new URL("RSS URL");
  16.  
  17. XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  18. factory.setNamespaceAware(false);
  19. XmlPullParser xpp = factory.newPullParser();
  20.  
  21. xpp.setInput(getInputStream(url), "UTF_8");
  22.  
  23. boolean insideItem = false;
  24.  
  25. // Returns the type of current event: START_TAG, END_TAG, etc..
  26. int eventType = xpp.getEventType();
  27. while (eventType != XmlPullParser.END_DOCUMENT) {
  28. if (eventType == XmlPullParser.START_TAG) {
  29.  
  30. if (xpp.getName().equalsIgnoreCase("item")) {
  31. insideItem = true;
  32. } else if (xpp.getName().equalsIgnoreCase("title")) {
  33. if (insideItem)
  34. headlines.add(xpp.nextText()); //extract the headline
  35. } else if (xpp.getName().equalsIgnoreCase("link")){ //link
  36. if (insideItem)
  37. links.add(xpp.nextText()); //extract the link of article
  38.  
  39. }
  40. }else if(eventType== XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
  41. insideItem=false;
  42. }
  43.  
  44. eventType = xpp.next(); //move to next element
  45. }
  46.  
  47. } catch (MalformedURLException e) {
  48. e.printStackTrace();
  49. } catch (XmlPullParserException e) {
  50. e.printStackTrace();
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement