User Tools

Site Tools


courses:2009.03.18.xml.web

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:2009.03.18.xml.web [2009/03/18 03:08]
camille fixed code
courses:2009.03.18.xml.web [2009/03/18 03:17] (current)
camille
Line 1: Line 1:
 +====== march 18 2009: Data visualization,​ XML, web APIs ======
 +==== Getting weather data in Processing via XML ====
 +  * Documentation about Yahoo'​s Weather API: [[http://​developer.yahoo.com/​weather]]
 +  * More web APIs: [[http://​www.programmableweb.com]]
 +  *
 +<code java>
 +XMLElement xml;
 +
 +void setup() {
 +  size(200, 200);
 +  xml = new XMLElement(this,​ "​http://​weather.yahooapis.com/​forecastrss?​p=FRXX0076&​u=c"​);​
 +
 +  XMLElement kid = xml.getChild(0);​
 +  int numSites = kid.getChildCount();​
 +  for (int i = 0; i < numSites; i++) {
 +    ​
 +    XMLElement channel = kid.getChild(i);​
 +    //​println(channel.getName());​
 +    if(channel.getName().equals("​item"​)){
 +
 +      int numDetails = channel.getChildCount();​
 +      //​println(numDetails);​
 +      for (int j = 0; j < numDetails; j++) {
 +        ​
 +        XMLElement item = channel.getChild(j);​
 +        String condition = item.getStringAttribute("​temp"​);​
 +        ​
 +        if(item.getName().equals("​yweather:​condition"​)){
 +          println("​yweather:​condition " + condition); ​
 +        }
 +           
 +      }
 +    }
 +  }
 +}
 +</​code>​
  
courses/2009.03.18.xml.web.txt · Last modified: 2009/03/18 03:17 by camille