i'm using weather.com web service request current conditions location, , parsing current temperature, feels temp , current condition icon flash application. current temperature , feels temperature nodes nested within nowitems -> nowitem while weathertoday further along in feed. i've written following in as3:
public class main extends movieclip { public function main() { var urlrequest:urlrequest = new urlrequest("webserviceurl"); var urlloader:urlloader=new urlloader(); urlloader.addeventlistener(event.complete, onxmlloaded); urlloader.load(urlrequest); } private function onxmlloaded(event:event):void { xml.ignorewhitespace = true; var urlloader:urlloader = event.currenttarget urlloader; var resultxml:xml = xml(urlloader.data); trace(resultxml.nowitems.nowitem.current temperature.value); trace(resultxml.nowitems.nowitem.feels like.value); trace(resultxml.weathertoday.icon); var lowtemp_label :textfield = new textfield(); addchild(lowtemp_label); var hitemp_label :textfield=new textfield(); addchild(hitemp_label); var condicon_label :textfield=new textfield(); addchild(condicon_label); lowtemp_label.text = resultxml.mintemp; hitemp_label.text= resultxml.maxtemp; condicon_label.text=resultxml.icon; } }
here's of xml:
<rss version="2.0" xmlns:a10="http://www.w3.org/2005/atom"> <channel> <title>weatherscape</title> <link>http://www.weatherchannel.com.au/</link> <description>weatherscape data</description> <category>weather</category> <item> <guid ispermalink="false">18b88e0b-b53f-41a3-bdfb-0762ae440f60</guid> <link>http://www.weatherchannel.com.au/</link> <title>weather</title> <description><?xml version="1.0" encoding="utf-16"?> <localweather xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <areatype>suburb</areatype> <areaid>555</areaid> <areaname>sydney</areaname> <utcoffset>600</utcoffset> <forecastcreated>2011-04-29t17:10:25z</forecastcreated> <observationscreated>2011-04-29t17:00:00z</observationscreated> <nowitems> <nowitem> <label>current temperature</label> <value>16.7</value> <units>°c</units> <change>steady</change> </nowitem> <nowitem> <label>feels like</label> <value>16.9</value> <units>°c</units> <change>steady</change> </nowitem> <nowitem> <label>dew point</label> <value>16</value> <units>°c</units> <change>down</change> </nowitem> <nowitem> <label>humidity</label> <value>96</value> <units>%</units> </nowitem> <nowitem> <label>wind speed</label> <value>9</value> <units>km/h</units> <change>steady</change> <direction>sw</direction> </nowitem> <nowitem> <label>wind gusts</label> <value>15</value> <units>km/h</units> </nowitem> <nowitem> <label>pressure</label> <value>1022</value> <units>hpa</units> <change>steady</change> </nowitem> <nowitem> <label>rain since 9am</label> <value>9</value> <units>mm</units> <change>n/a</change> </nowitem> <nowitem> <label>fire danger level</label> <value>unavailable</value> <units>n/a</units> </nowitem> </nowitems> <wmoid>94768</wmoid> <siteid>66062</siteid> <weatherstation>sydney</weatherstation> <weathertoday> <icon>fewshowers</icon> <friendlyname>few showers</friendlyname> <precis>few showers.</precis> <maxtemp>22</maxtemp> <mintemp>17</mintemp> <units>°c</units> <morningicon>showers</morningicon> <afternoonicon>fewshowers</afternoonicon> <eveningicon>showers</eveningicon> <morningprecis>showers</morningprecis> <afternoonprecis>few showers</afternoonprecis> <eveningprecis>showers</eveningprecis> </weathertoday>
i compiler errors on lines requesting current temperature , feels like, have spaces in them? syntax use reference these nodes given have spaces? correct way reference these nodes, or there simpler methods? when reference nodes in label text (last 3 lines), use qualified node in trace statements?
thanks much!!
inside of description node xml string not xml
need description node convert xml parse it
[edit]
ok, have in example 2 xml files 1 inside other.
need parse out description node can learn how here , here example of loader
once have obtained contents of description node have unescape data because has been converted html friendly format.(pretty sure unescape function handle if not post question on here how convert - sorry no time test right now)
example:
< should converted <
after string has been converted create new xml: object off of , access node want did when parsed server response.
Comments
Post a Comment