Weather report
From SoftIVR
Weather report
This simple IVR service prompts the user to enter a 5-digit ZIP code, uses a web service to look up the weather for that ZIP code, and tells the user what the weather is. The code is very straightforward:
answer();
say("Please enter a ZIP code.", "en-us-f");
zip = "";
while (zip.length < 5) {
zip = zip + getDTMF(5);
}
parseXML(httpGet("http://weather.yahooapis.com/forecastrss?p=" + zip));
say(getXPath("/channel/item/title") + ".", "en-us-f");
say("Conditions are " + getXPath("/channel/item/yweather:condition/text") + ".", "en-us-f");
say("It is " + getXPath("/channel/item/yweather:condition/temp") + " fahrenheit.", 'en-us-f");
Note how easy SoftIVR's XML functions make handling the XML returned from Yahoo's weather forecast feed. parseXML is used to parse the XML returned by the HTTP call to Yahoo's weather service in to an internal structure, and getXPath is used to extract items from that XML structure.
For more information, see the example code under getXPath to see how getXPath is used to extract specific items of data.