Visualize the Yahoo weather data using simpleML. Following is part of the code to get you started. This is the XML in case you forgot:

<yweather:condition text=“Fair” code=“34” temp=“35” date=“Mon, 20 Feb 2006 3:51 pm EST”/>
import simpleML.*;
// Variables for temperature and weather
int temperature = 0;
String weather = "";
void setup() {
  // FILL THIS IN HOWEVER YOU LIKE!
}
void draw() {
  // FILL THIS IN HOWEVER YOU LIKE!
}
// Function that makes the weather request with a Zip Code
void getWeather(String zip) {
  String url = "http://xml.weather.yahoo.com/ forecastrss?p="+zip;
  XMLRequest req = new XMLRequest(this,url);
  req.makeRequest();
}
void netEvent(XMLRequest ml) { // Get the specific XML content we want
  temperature = int(ml.__________("_________","_________"));
  weather = ml.___________("__________","__________");
}

One possible solution:


import simpleML.*;

// Variables for temperature and weather
int temperature = 0;
String weather = "";

void setup() {
  size(200,200);
  XMLRequest xreq = new XMLRequest(this,"http://xml.weather.yahoo.com/forecastrss?p=10025");
  xreq.makeRequest();
  // FILL THIS IN HOWEVER YOU LIKE!
  textFont(createFont("Arial",16,true));
}
void draw() {
  background(255);
  // FILL THIS IN HOWEVER YOU LIKE!

  textAlign(CENTER);
  fill(0);
  text(temperature + "\n" + weather,100,50);

}
// Function that makes the weather request with a Zip Code
void getWeather(String zip) {
  String url = "http://xml.weather.yahoo.com/ forecastrss?p="+zip;
  XMLRequest req = new XMLRequest(this,url);
  req.makeRequest();
}
void netEvent(XMLRequest ml) { // Get the specific XML content we want
  temperature = int(ml.getElementAttributeText("yweather:condition","temp"));
  weather = ml.getElementAttributeText("yweather:condition","text");
  println(temperature);
  println(weather);
}
  • JZ

    What’s the purpose of having the function that makes the weather request with a Zip Code? Without it, this “one possible solution” sketch runs fine. Is it for possible interactivity, such as mousePressed()?

  • Anonymous

    yes, this is demonstrating how you could ask for the weather for any zip code and that zip code could come from any source or interaction.

  • Swimuniversity

    Is there a directory where I may receive the information definitions of their classification for xml?