vb.net - Getting Specific Data from XML -


i 'm kind of new vb , .net, , i'm having trouble trying setup weather widget. i'm pulling yahoos rss feeds, storing xml file, , reading xml file. first couple of things pull in fine, yahoo's feed sends list of days/temps/highs/lows. (see below)

<rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0"> <channel> <title>yahoo! weather - lincoln, ne</title> <link>...</link> <description>yahoo! weather lincoln, ne</description> <language>en-us</language> <lastbuilddate>fri, 31 jan 2014 12:53 pm cst</lastbuilddate> <ttl>60</ttl> <yweather:location city="lincoln" region="ne" country="us"/> <yweather:units temperature="f" distance="mi" pressure="in" speed="mph"/> <yweather:wind chill="13" direction="80" speed="7"/> <yweather:atmosphere humidity="43" visibility="10" pressure="30.08" rising="2"/> <yweather:astronomy sunrise="7:37 am" sunset="5:43 pm"/> <image>...</image> <item> <title>conditions lincoln, ne @ 12:53 pm cst</title> <geo:lat>40.8</geo:lat> <geo:long>-96.67</geo:long> <link> http://us.rd.yahoo.com/dailynews/rss/weather/lincoln__ne/*http://weather.yahoo.com/forecast/usne0283_f.html </link> <pubdate>fri, 31 jan 2014 12:53 pm cst</pubdate> <yweather:condition text="cloudy" code="26" temp="22" date="fri, 31 jan 2014 12:53 pm cst"/> <description> <![cdata[...]]> </description> <yweather:forecast day="fri" date="31 jan 2014" low="18" high="25" text="few snow showers" code="14"/> <yweather:forecast day="sat" date="1 feb 2014" low="5" high="31" text="am clouds/pm sun" code="30"/> <yweather:forecast day="sun" date="2 feb 2014" low="11" high="27" text="sunny" code="32"/> <yweather:forecast day="mon" date="3 feb 2014" low="18" high="36" text="partly cloudy" code="30"/> <yweather:forecast day="tue" date="4 feb 2014" low="-3" high="21" text="snow showers" code="14"/> <guid ispermalink="false">usne0283_2014_02_04_7_00_cst</guid> </item> </channel> </rss> 

the area i'm having trouble

<yweather:forecast day="fri" date="31 jan 2014" low="18" high="25" text="few snow showers" code="14"/> <yweather:forecast day="sat" date="1 feb 2014" low="5" high="31" text="am clouds/pm sun" code="30"/> <yweather:forecast day="sun" date="2 feb 2014" low="11" high="27" text="sunny" code="32"/> <yweather:forecast day="mon" date="3 feb 2014" low="18" high="36" text="partly cloudy" code="30"/> <yweather:forecast day="tue" date="4 feb 2014" low="-3" high="21" text="snow showers" code="14"/> 

as can see, gives list of dates , values back. i'm having trouble reading values variables/labels. example i've been trying

mydoc.selectsinglenode("/rss/channel/item/yweather:forecast[day='" + _dayofweek + "']/@low", nsmgr).innertext 

to try , low each _dayofweek -- keep getting xpathexceptions, unclosed strings, sounds path take has full string no ' + _dayofweek ' - gonig have create subroutines each different day of week???

please let me know if can see dumb i'm doing, here's code reference

public class ctrlweatherwidget     readonly _zip = 68508     'in future, may want include options view multiple locations, in case won't read     dim _conditions     dim _dayofweek string      public sub update()          dim rssurl = "http://xml.weather.yahoo.com/forecastrss?p=" + _zip.tostring()         dim rssrequest net.webrequest = net.webrequest.create(rssurl)          dim rssresponse net.webresponse = rssrequest.getresponse()         dim rssstream io.stream = rssresponse.getresponsestream()          dim rssdoc new xml.xmldocument         rssdoc.load(rssstream)          dim nodes xml.xmlnodelist         nodes = rssdoc.selectnodes("/rss/channel")          lblcitystate.text = replace(nodes.item(0).selectsinglenode("title").innertext, "yahoo! weather - ", "")          dim nsmgr = new xml.xmlnamespacemanager(rssdoc.nametable)         nsmgr.addnamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0")          'find conditions , display correct image current weather          _conditions = rssdoc.selectsinglenode("/rss/channel/item/yweather:condition/@code", nsmgr).innertext          picconditions.backgroundimage = getconditions()          'get current days highs , lows , picture          lblcurrenttemp.text = rssdoc.selectsinglenode("rss/channel/item/yweather:condition/@temp", nsmgr).innertext          lbllownow.text = rssdoc.selectsinglenode("/rss/channel/item/yweather:forecast[day='" + _dayofweek + "']'/@low", nsmgr).innertext         'tabel/member[naam='ghostbullet93']/kills"         lblhighnow.text = rssdoc.selectsinglenode("/rss/channel/item/yweather:forecast[day='" + _dayofweek + "']'/@high", nsmgr).innertext          'set 3 days in future information below, , lows highs, picture          getday(1)         lbldayone.text = _dayofweek         _conditions = rssdoc.selectsinglenode("rss/channel/yweather:condition/@temp", nsmgr).innertext         picdayone.backgroundimage = getconditions()         lblhighone.text = string.format("h: {0}", rssdoc.selectsinglenode("rss/channel/yweather:atmosphere/@humidity", nsmgr).innertext)         lbllowone.text = string.format("l: {0}", rssdoc.selectsinglenode("rss/channel/yweather:atmosphere/@humidity", nsmgr).innertext)          getday(2)         lbldaytwo.text = _dayofweek         _conditions = rssdoc.selectsinglenode("rss/channel/yweather:condition/@temp", nsmgr).innertext         picdaytwo.backgroundimage = getconditions()         lblhightwo.text = string.format("h: {0}", rssdoc.selectsinglenode("rss/channel/yweather:atmosphere/@humidity", nsmgr).innertext)         lbllowtwo.text = string.format("l: {0}", rssdoc.selectsinglenode("rss/channel/yweather:atmosphere/@humidity", nsmgr).innertext)          getday(3)         lbldaythree.text = _dayofweek         _conditions = rssdoc.selectsinglenode("rss/channel/yweather:condition/@temp", nsmgr).innertext         picdaythree.backgroundimage = getconditions()         lblhighthree.text = string.format("h: {0}", rssdoc.selectsinglenode("rss/channel/yweather:atmosphere/@humidity", nsmgr).innertext)         lbllowthree.text = string.format("l: {0}", rssdoc.selectsinglenode("rss/channel/yweather:atmosphere/@humidity", nsmgr).innertext)          lblupdated.text = string.format("last updated {0}", replace(nodes.item(0).selectsinglenode("rss/channel/item/title").innertext, "conditions ", ""))      end sub      public sub getday(byval offset integer)         dim day integer          day = date.now.dayofweek          if (day + offset) > 7             day = day + offset             day = day - 7         end if          select case day             case 1                 _dayofweek = "mon"             case 2                 _dayofweek = "tue"             case 3                 _dayofweek = "wed"             case 4                 _dayofweek = "thu"             case 5                 _dayofweek = "fri"             case 6                 _dayofweek = "sat"             case 7                 _dayofweek = "sun"         end select     end sub      public function getconditions() image         if (_conditions >= 0 andalso _conditions <= 4) or (_conditions >= 9 andalso _conditions <= 12) or (_conditions >= 37 andalso _conditions <= 40) or _conditions = 45 or _conditions = 47             return my.resources.raining         elseif (_conditions >= 5 andalso _conditions <= 8) or (_conditions >= 13 andalso _conditions <= 16) or (_conditions >= 41 andalso _conditions <= 43) or _conditions = 46             return my.resources.snow         elseif _conditions = 26             return my.resources.overcast_sky         elseif _conditions = 27 or _conditions = 29             return my.resources.night_partlycloudy         elseif _conditions = 28 or _conditions = 30 or _conditions = 44             return my.resources.day_partlycloudy         elseif _conditions = 31 or _conditions = 33             return my.resources.moon         elseif _conditions = 32 or _conditions = 34 or _conditions = 36             return my.resources.day_clear         else             return my.resources.overcast_sky         end if     end function      private sub btnupdate_click(sender system.object, e eventargs) handles btnupdate.click         update()     end sub  end class 

if above real code, think problem single quotes around closing square bracket :

lbllownow.text = rssdoc.selectsinglenode( _                     "/rss/channel/item/yweather:forecast[day='" + _                         _dayofweek + "']'/@low", nsmgr _                     ).innertext 

i suspect should instead :

lbllownow.text = rssdoc.selectsinglenode( _                     "/rss/channel/item/yweather:forecast[day='" + _                         _dayofweek + "']/@low", nsmgr _                     ).innertext 

or mistake when copy-paste codes ?


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -