I am trying to get some weather data from the openweathermap-webservice. Among the data is a the iconCode too in order to visualize the current weather condition. Here is the xml-response of the given request:
request:
http://api.openweathermap.org/data/2.5/forecast?q=linz&units=metric&type=accurate&mode=xml&APPID=ef67184baece136977466e7894b2a614
one part of the response: ( i have shortened it a bit)
<weatherdata>
<location>...</location>
<credit/>
<meta>...</meta>
<sun rise="2017-05-30T03:07:24" set="2017-05-30T18:54:07"/>
<forecast>
<time from="2017-05-30T09:00:00" to="2017-05-30T12:00:00">
<symbol number="800" name="clear sky" var="02d"/>
<precipitation/>
<windDirection deg="223" code="SW" name="Southwest"/>
<windSpeed mps="2.31" name="Light breeze"/>
<temperature unit="celsius" value="29.59" min="27.52" max="29.59"/>
</time>
<time from="2017-05-30T12:00:00" to="2017-05-30T15:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation/>
<windDirection deg="227.001" code="SW" name="Southwest"/>
</time>
I want to retrieve all iconCodes of all forecast-days. (And it works fine with the temperature, wind direction, etc...
a part of the function which should get the data from the webservice:
for each (var item in xmlPage.forecast.time) {
var row = new Object();
var from_current_value=item.@from.substring(0,10);
if(from_current_value!=from_today_value){
row.WindDirection = item.windDirection.@name;
row.WindSpeed=item.windSpeed.@mps;
row.WeatherTemp=parseFloat(item.temperature.@value);
row.WeatherHumidity=parseFloat(item.humidity.@value);
row.From=item.@from;
row.To=item.@to;
row.Title=xmlPage.location.name+" "+xmlPage.location.country;
row.Precipitation=(item.precipitation.@type+" "+item.precipitation.@value)==" "?"No Precipitation":item.precipitation.@type;
var iconCode = item.symbol.@var;
row.IconLink = "http://openweathermap.org/img/w/"+ iconCode +".png";
If I have added the line var iconCode = item.symbol.@var, I get the following syntax error:
syntax check failed: missing name after .@ (Line#33)
(line33 is the "var iconCode = item.symbol.@var" line)
I think I get the error because "var" is a reserved string in JavaScript. But how do I get the iconCode from the xmlPage then? Any suggestions?
Thank you so much in advance for helping me out! Best regards, Theresa