We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › OPML/RSS/Atom Parsing
Page Index Toggle Pages: 1
OPML/RSS/Atom Parsing (Read 683 times)
OPML/RSS/Atom Parsing
Dec 5th, 2007, 9:16pm
 
Quote:


/*
* opmlparse -- parse a OPML file, extracting the Feed URLs,
* open each feed URL, display feed name, and titles
*
*  Anthony Starks, ajstarks@gmail.com
*/

import processing.xml.*;

void setup() {
 String url = "http://www.toptensources.com//topten/Jeremy-Zawodnys-Top-10/?display=.opml";
 String fu;
 String ftitle;
 XMLElement titles[];
 XMLElement feed;
 XMLElement opml = new XMLElement(this, url);
 XMLElement[] outline = opml.getChildren("body/outline");

 for (int i = 0; i < outline.length; i++) {
   fu = outline[i].getStringAttribute("xmlUrl");
   print(fu);

   try {
     feed = new XMLElement(this, fu);
     println("..Ok");
     XMLElement type = feed.getChild(0);
     if (type.getName().equals("channel"))   { /* RSS */
       ftitle = type.getChild("title").getContent();
       titles = type.getChildren("item/title");
     }
     else {
       ftitle = feed.getChild("title").getContent();
       titles = feed.getChildren("entry/title");  /* Atom */
     }
     println(ftitle);

     for (int nt=0; nt < titles.length; nt++) {
       println("  " + titles[nt].getContent());
     }
   }
   catch(Exception e){
     println("..Loading Failed");
   }
 }

}


Page Index Toggle Pages: 1