My "For Each/Next" loop seems to stall after parsing the first Tag correctly and placing in the appropriate field. So I must have the wrong syntax to parse the xml but cant seem to get it working.
Anyone (or hopefully June who is so good at this) care to point out the errors of my way?
Here is the weather api service response xml text that I am trying to parse:
Code:
<response>
<version>0.1</version>
<termsofService>http://www.wunderground.com/weather/api/d/terms.html</termsofService>
<features>
<feature>forecast</feature>
</features>
<forecast>
<txt_forecast>
<date>4:00 PM CDT</date>
<forecastdays>
<forecastday>
<period>0</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Thursday</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy in the morning, then clear. High of 81F. Winds from the NNW at 5 to 10 mph shifting to the ENE in the afternoon.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy in the morning, then clear. High of 27C. Winds from the NNW at 5 to 20 km/h shifting to the ENE in the afternoon.]=]=></fcttext_metric>
<pop>10</pop>
</forecastday>
<forecastday>
<period>1</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Thursday Night</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy. Low of 52F. Winds from the ENE at 5 to 15 mph.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy. Low of 11C. Breezy. Winds from the ENE at 10 to 20 km/h.]=]=></fcttext_metric>
<pop>10</pop>
</forecastday>
<forecastday>
<period>2</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Friday</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy with a chance of a thunderstorm and a chance of rain in the afternoon. High of 75F. Winds from the ENE at 5 to 15 mph. Chance of rain 20%.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy with a chance of a thunderstorm and a chance of rain in the afternoon. High of 24C. Breezy. Winds from the ENE at 10 to 20 km/h.]=]=></fcttext_metric>
<pop>20</pop>
</forecastday>
<forecastday>
<period>3</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Friday Night</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy with a chance of a thunderstorm and a chance of rain. Low of 59F. Winds from the North at 5 to 10 mph shifting to the ESE after midnight. Chance of rain 20%.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy with a chance of a thunderstorm and a chance of rain. Low of 15C. Winds from the North at 10 to 15 km/h shifting to the ESE after midnight.]=]=></fcttext_metric>
<pop>20</pop>
</forecastday>
<forecastday>
<period>4</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Saturday</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy with a chance of a thunderstorm and a chance of rain. High of 73F. Winds from the SE at 5 to 10 mph. Chance of rain 20%.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy with a chance of a thunderstorm and a chance of rain. High of 23C. Breezy. Winds from the SE at 10 to 20 km/h.]=]=></fcttext_metric>
<pop>20</pop>
</forecastday>
<forecastday>
<period>5</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Saturday Night</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy. Low of 57F. Winds from the NE at 5 to 15 mph shifting to the ESE after midnight.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy. Low of 14C. Breezy. Winds from the NE at 10 to 20 km/h shifting to the ESE after midnight.]=]=></fcttext_metric>
<pop>0</pop>
</forecastday>
<forecastday>
<period>6</period>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Sunday</title>
<fcttext><=!=[=C=D=A=T=A=[Mostly cloudy. High of 75F. Winds from the East at 5 to 10 mph.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Mostly cloudy. High of 24C. Winds from the East at 10 to 15 km/h.]=]=></fcttext_metric>
<pop>0</pop>
</forecastday>
<forecastday>
<period>7</period>
<icon>mostlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/mostlycloudy.gif</icon_url>
<title>Sunday Night</title>
<fcttext><=!=[=C=D=A=T=A=[Partly cloudy in the evening, then overcast. Low of 63F. Winds from the SE at 10 to 15 mph.]=]=></fcttext>
<fcttext_metric><=!=[=C=D=A=T=A=[Partly cloudy in the evening, then overcast. Low of 17C. Breezy. Winds from the SE at 15 to 25 km/h.]=]=></fcttext_metric>
<pop>0</pop>
</forecastday>
</forecastdays>
</txt_forecast>
<simpleforecast>
<forecastdays>
<forecastday>
<date>
<epoch>1368759600</epoch>
<pretty_short>10:00 PM CDT</pretty_short>
<pretty>10:00 PM CDT on May 16, 2013</pretty>
<day>16</day>
<month>5</month>
<year>2013</year>
<yday>135</yday>
<hour>22</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>May</monthname>
<weekday_short>Thu</weekday_short>
<weekday>Thursday</weekday>
<ampm>PM</ampm>
<tz_short>CDT</tz_short>
<tz_long>America/Chicago</tz_long>
</date>
<period>1</period>
<high>
<fahrenheit>81</fahrenheit>
<celsius>27</celsius>
</high>
<low>
<fahrenheit>52</fahrenheit>
<celsius>11</celsius>
</low>
<conditions>Partly Cloudy</conditions>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<skyicon>partlycloudy</skyicon>
<pop>10</pop>
<qpf_allday>
<in>0.00</in>
<mm>0.0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0.0</mm>
</qpf_day>
<qpf_night>
<in>0.04</in>
<mm>1.0</mm>
</qpf_night>
<snow_allday>
<in>0</in>
<cm>0</cm>
</snow_allday>
<snow_day>
<in>0</in>
<cm>0</cm>
</snow_day>
<snow_night>
<in>0</in>
<cm>0</cm>
</snow_night>
<maxwind>
<mph>11</mph>
<kph>18</kph>
<dir>NE</dir>
<degrees>55</degrees>
</maxwind>
<avewind>
<mph>8</mph>
<kph>13</kph>
<dir>ENE</dir>
<degrees>73</degrees>
</avewind>
<avehumidity>53</avehumidity>
<maxhumidity>66</maxhumidity>
<minhumidity>29</minhumidity>
</forecastday>
<forecastday>
<date>
<epoch>1368846000</epoch>
<pretty_short>10:00 PM CDT</pretty_short>
<pretty>10:00 PM CDT on May 17, 2013</pretty>
<day>17</day>
<month>5</month>
<year>2013</year>
<yday>136</yday>
<hour>22</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>May</monthname>
<weekday_short>Fri</weekday_short>
<weekday>Friday</weekday>
<ampm>PM</ampm>
<tz_short>CDT</tz_short>
<tz_long>America/Chicago</tz_long>
</date>
<period>2</period>
<high>
<fahrenheit>75</fahrenheit>
<celsius>24</celsius>
</high>
<low>
<fahrenheit>59</fahrenheit>
<celsius>15</celsius>
</low>
<conditions>Chance of a Thunderstorm</conditions>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<skyicon>partlycloudy</skyicon>
<pop>20</pop>
<qpf_allday>
<in>0.04</in>
<mm>1.0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0.0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0.0</mm>
</qpf_night>
<snow_allday>
<in>0</in>
<cm>0</cm>
</snow_allday>
<snow_day>
<in>0</in>
<cm>0</cm>
</snow_day>
<snow_night>
<in>0</in>
<cm>0</cm>
</snow_night>
<maxwind>
<mph>11</mph>
<kph>18</kph>
<dir>ENE</dir>
<degrees>67</degrees>
</maxwind>
<avewind>
<mph>9</mph>
<kph>14</kph>
<dir>ENE</dir>
<degrees>70</degrees>
</avewind>
<avehumidity>61</avehumidity>
<maxhumidity>72</maxhumidity>
<minhumidity>48</minhumidity>
</forecastday>
<forecastday>
<date>
<epoch>1368932400</epoch>
<pretty_short>10:00 PM CDT</pretty_short>
<pretty>10:00 PM CDT on May 18, 2013</pretty>
<day>18</day>
<month>5</month>
<year>2013</year>
<yday>137</yday>
<hour>22</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>May</monthname>
<weekday_short>Sat</weekday_short>
<weekday>Saturday</weekday>
<ampm>PM</ampm>
<tz_short>CDT</tz_short>
<tz_long>America/Chicago</tz_long>
</date>
<period>3</period>
<high>
<fahrenheit>73</fahrenheit>
<celsius>23</celsius>
</high>
<low>
<fahrenheit>57</fahrenheit>
<celsius>14</celsius>
</low>
<conditions>Chance of a Thunderstorm</conditions>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<skyicon>partlycloudy</skyicon>
<pop>20</pop>
<qpf_allday>
<in>0.00</in>
<mm>0.0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0.0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0.0</mm>
</qpf_night>
<snow_allday>
<in>0</in>
<cm>0</cm>
</snow_allday>
<snow_day>
<in>0</in>
<cm>0</cm>
</snow_day>
<snow_night>
<in>0</in>
<cm>0</cm>
</snow_night>
<maxwind>
<mph>10</mph>
<kph>16</kph>
<dir>ENE</dir>
<degrees>59</degrees>
</maxwind>
<avewind>
<mph>9</mph>
<kph>14</kph>
<dir>ENE</dir>
<degrees>69</degrees>
</avewind>
<avehumidity>70</avehumidity>
<maxhumidity>74</maxhumidity>
<minhumidity>52</minhumidity>
</forecastday>
<forecastday>
<date>
<epoch>1369018800</epoch>
<pretty_short>10:00 PM CDT</pretty_short>
<pretty>10:00 PM CDT on May 19, 2013</pretty>
<day>19</day>
<month>5</month>
<year>2013</year>
<yday>138</yday>
<hour>22</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>May</monthname>
<weekday_short>Sun</weekday_short>
<weekday>Sunday</weekday>
<ampm>PM</ampm>
<tz_short>CDT</tz_short>
<tz_long>America/Chicago</tz_long>
</date>
<period>4</period>
<high>
<fahrenheit>75</fahrenheit>
<celsius>24</celsius>
</high>
<low>
<fahrenheit>63</fahrenheit>
<celsius>17</celsius>
</low>
<conditions>Partly Cloudy</conditions>
<icon>partlycloudy</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<skyicon>partlycloudy</skyicon>
<pop>0</pop>
<qpf_allday>
<in>0.00</in>
<mm>0.0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0.0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0.0</mm>
</qpf_night>
<snow_allday>
<in>0</in>
<cm>0</cm>
</snow_allday>
<snow_day>
<in>0</in>
<cm>0</cm>
</snow_day>
<snow_night>
<in>0</in>
<cm>0</cm>
</snow_night>
<maxwind>
<mph>9</mph>
<kph>14</kph>
<dir>East</dir>
<degrees>91</degrees>
</maxwind>
<avewind>
<mph>7</mph>
<kph>11</kph>
<dir>East</dir>
<degrees>89</degrees>
</avewind>
<avehumidity>70</avehumidity>
<maxhumidity>86</maxhumidity>
<minhumidity>58</minhumidity>
</forecastday>
</forecastdays>
</simpleforecast>
</forecast>
</response>
And here is the vba script I am trying to use to parse but seems to stop for some reason after filling in the first correct txtForecast1 field with the correct forecast text:
Private Sub btnGetWeather_Click()
Dim Req As New XMLHTTP
Dim Resp As New DOMDocument
Dim i As Integer
Dim Forecast As IXMLDOMNode
Req.Open "GET", "http://api.wunderground.com/api/YOUR KEY HERE/forecast/q/IL/60603.xml", False
Req.send
Resp.loadXML Req.responseText
For Each Forecast In Resp.getElementsByTagName("forecast")
i = i + 1
Me.Controls("txtForecast" & i) = Forecast.selectNodes("txt_forecast")(0).selectNode s("forecastdays")(0).selectNodes("forecastday")(0) .selectNodes("fcttext")(0).Text
Next
End Sub