cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

JavaScript: Cannot get @var-value from xml-file because var is reserved?

tlichtenberger-
1-Visitor

JavaScript: Cannot get @var-value from xml-file because var is reserved?

hey everyone!

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-URL: 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)

  

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:

If I add the line var iconCode = item.symbol.@var, I get the following syntax error:

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

2 REPLIES 2

Do a LoadText instead and do a search/replace before creating the XML object ( new XML(string) )

hey Carles Coll​,

I solved it this way as I wasn't able to convert the replaced string back to xml.

var iconCode = item.symbol['@var'];

Nevertheless, thank you for your suggestion!

Theresa

Announcements


Top Tags