This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

XML data
#2
Code:
require('socket.http') forecast = {} function parsetag(parser, tag, attributes)   if tag == 'time' then     table.insert(forecast, {})   elseif tag == 'symbol' then     forecast[ #forecast ].symbol = attributes.name   elseif tag == 'precipitation' then     forecast[ #forecast ].precipitation = attributes.value   elseif tag == 'windDirection' then     forecast[ #forecast ].wind_direction = attributes.code   elseif tag == 'windSpeed' then     forecast[ #forecast ].wind_speed = attributes.mps   elseif tag == 'temperature' then     forecast[ #forecast ].temperature = attributes.value   elseif tag == 'pressure' then     forecast[ #forecast ].pressure = attributes.value   end end url = 'http://www.yr.no/place/United_Kingdom/England/Farnborough/varsel.xml' data, err = socket.http.request(url) if data then   require('lxp').new({     StartElement = parsetag   }):parse(data)   grp.update('Weather precipitation', tonumber(forecast[1].precipitation))   grp.update('Weather symbol', forecast[1].symbol)   grp.update('Weather windDirection', forecast[1].wind_direction)   grp.update('Weather windSpeed', tonumber(forecast[1].wind_speed))   grp.update('Weather temperature', tonumber(forecast[1].temperature))   grp.update('Weather pressure', tonumber(forecast[1].pressure))   --log(forecast)   else   alert('Fetch failed: ' .. tostring(err)) end
------------------------------
Ctrl+F5
Reply


Messages In This Thread
XML data - by tomnord - 18.03.2020, 08:40
RE: XML data - by Daniel - 18.03.2020, 09:01
RE: XML data - by Tokatubs - 18.03.2020, 09:10
RE: XML data - by admin - 18.03.2020, 09:29
RE: XML data - by tomnord - 18.03.2020, 10:14
RE: XML data - by Daniel - 18.03.2020, 09:33
RE: XML data - by Tokatubs - 18.03.2020, 10:05
RE: XML data - by Daniel - 18.03.2020, 10:22
RE: XML data - by tomnord - 18.03.2020, 10:28
RE: XML data - by admin - 18.03.2020, 10:38

Forum Jump: