By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,393 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,393 IT Pros & Developers. It's quick & easy.

help with looping through XML items.

P: n/a
Larry,

i've got an xml file which has multiple cities as the top level item.
When i read it in using XMLReader, and define the variables, as below, it
finds the correct number of cities in the xml file, but repeats the first
one 3 times. I'm sure its something minor but i just cant seem to figure it
out.

here is the XML, and source code below:

--------------------XML---------------------
<?xml version="1.0" encoding="utf-8"?>
<weatherFeed>
<city>
<currentConditions>
country>Austria</country>
<city>Vienna</city>
<weatherImageURL>weather/lrg/sunny.gif</weatherImageURL>
<celcius>1C</celcius>
<farenheit>34F</farenheit>
<description>Sunny</description>
<relativeHumidity>69%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-4C</lowCelcius>
<highFarenheit>33F</highFarenheit>
<lowFarenheit>24F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>21F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>25F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>28F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<country>Austria</country>
<city>Innsbruck</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>74%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPressure>30.13Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>10F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit>22F</highFarenheit>
<lowFarenheit>5F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>26F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>27F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?locCode=LOWS-->
<country>Austria</country>
<city>Salzburg</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>86%</relativeHumidity>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-5C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>23F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit>35F</highFarenheit>
<lowFarenheit>15F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>24F</highFarenheit>
<lowFarenheit>11F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>0C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>32F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
</weatherFeed>

----------------SOURCE CODE-----------------
Dim xDoc As New XmlDocument
Dim xe_weatherFeed As XmlElement
Dim xe_city As XmlNode
Dim xe_currentConditions As XmlElement
Dim xe_currentConditionsChild As XmlNode
Dim xe_fiveDayForecast As XmlElement
Dim xe_fiveDayForecastDay As XmlElement
Dim xe_fiveDayForecastDayDetails As XmlNode

Try
Dim a() As String
Dim al As New ArrayList
Dim i As Integer

xDoc.Load(strBaseURL & "weather/" &
Request.QueryString("countryID") & ".xml")
xe_weatherFeed = xDoc.SelectSingleNode("/weatherFeed")
xe_city = xDoc.SelectSingleNode("/weatherFeed/city")
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
xe_fiveDayForecast =
xDoc.SelectSingleNode("/weatherFeed/city/fiveDayForecast")

For Each xe_city In xe_weatherFeed.ChildNodes
If xe_city.NodeType = XmlNodeType.Element Then
ReDim Preserve a(41)
i = 0
For Each xe_currentConditionsChild In
xe_currentConditions.ChildNodes
If xe_currentConditionsChild.NodeType =
XmlNodeType.Element Then
a(i) = xe_currentConditionsChild.InnerText
i += 1
End If
Next

For Each xe_fiveDayForecastDay In xe_fiveDayForecast
For Each xe_fiveDayForecastDayDetails In
xe_fiveDayForecastDay
If xe_fiveDayForecastDayDetails.NodeType =
XmlNodeType.Element Then
a(i) =
xe_fiveDayForecastDayDetails.InnerText
i += 1
End If
Next
Next
al.Add(a)
End If
Next
weatherRepeater.DataSource = al
weatherRepeater.DataBind()
Catch err As Exception
Response.Write("<br><font color=red><b>" & err.Message &
"</b></font>")
Finally
xDoc = Nothing
End Try

thanks in advance

Paul.

Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Paul,

I think I see why you getting the first city 3 times. It has to do with
your how you are using the xpath expression to assign the variable
xe_CurrentConditions.
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
Your xpath expression is always returns the 1st occurence of the
currentConditions element because your search is always occuring from the
top level xml element reference, xDoc.

Try moving the assignment of xe_CurrentConditions after your
For Each xe_city In xe_weatherFeed.ChildNodes
and change the statement to read:

xe_CurrentConditions = xe_City.SelectSingleNode("currentConditions")

That way your are getting the current conditions child relative to the
current iteration of xe_city
rather than always the first one.

If you are using Visual Studio and have the debugger available to you,
examine the values of the variables as you step through the program. It
will lend a lot of insight to what is happening.

LarryR


"Paul M" <mi******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl... Larry,

i've got an xml file which has multiple cities as the top level item.
When i read it in using XMLReader, and define the variables, as below, it
finds the correct number of cities in the xml file, but repeats the first
one 3 times. I'm sure its something minor but i just cant seem to figure it out.

here is the XML, and source code below:

--------------------XML---------------------
<?xml version="1.0" encoding="utf-8"?>
<weatherFeed>
<city>
<currentConditions>
country>Austria</country>
<city>Vienna</city>
<weatherImageURL>weather/lrg/sunny.gif</weatherImageURL>
<celcius>1C</celcius>
<farenheit>34F</farenheit>
<description>Sunny</description>
<relativeHumidity>69%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-4C</lowCelcius>
<highFarenheit>33F</highFarenheit>
<lowFarenheit>24F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>21F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>25F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>28F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<country>Austria</country>
<city>Innsbruck</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>74%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPressure>30.13Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>10F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit>22F</highFarenheit>
<lowFarenheit>5F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>26F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>27F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?locCode=LOWS-->
<country>Austria</country>
<city>Salzburg</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>86%</relativeHumidity>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-5C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>23F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit>35F</highFarenheit>
<lowFarenheit>15F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>24F</highFarenheit>
<lowFarenheit>11F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>0C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>32F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
</weatherFeed>

----------------SOURCE CODE-----------------
Dim xDoc As New XmlDocument
Dim xe_weatherFeed As XmlElement
Dim xe_city As XmlNode
Dim xe_currentConditions As XmlElement
Dim xe_currentConditionsChild As XmlNode
Dim xe_fiveDayForecast As XmlElement
Dim xe_fiveDayForecastDay As XmlElement
Dim xe_fiveDayForecastDayDetails As XmlNode

Try
Dim a() As String
Dim al As New ArrayList
Dim i As Integer

xDoc.Load(strBaseURL & "weather/" &
Request.QueryString("countryID") & ".xml")
xe_weatherFeed = xDoc.SelectSingleNode("/weatherFeed")
xe_city = xDoc.SelectSingleNode("/weatherFeed/city")
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
xe_fiveDayForecast =
xDoc.SelectSingleNode("/weatherFeed/city/fiveDayForecast")

For Each xe_city In xe_weatherFeed.ChildNodes
If xe_city.NodeType = XmlNodeType.Element Then
ReDim Preserve a(41)
i = 0
For Each xe_currentConditionsChild In
xe_currentConditions.ChildNodes
If xe_currentConditionsChild.NodeType =
XmlNodeType.Element Then
a(i) = xe_currentConditionsChild.InnerText
i += 1
End If
Next

For Each xe_fiveDayForecastDay In xe_fiveDayForecast For Each xe_fiveDayForecastDayDetails In
xe_fiveDayForecastDay
If xe_fiveDayForecastDayDetails.NodeType =
XmlNodeType.Element Then
a(i) =
xe_fiveDayForecastDayDetails.InnerText
i += 1
End If
Next
Next
al.Add(a)
End If
Next
weatherRepeater.DataSource = al
weatherRepeater.DataBind()
Catch err As Exception
Response.Write("<br><font color=red><b>" & err.Message &
"</b></font>")
Finally
xDoc = Nothing
End Try

thanks in advance

Paul.

Nov 12 '05 #2

P: n/a
Thanks larry,

i've got it on the debugger and can see it looping through the cities, and i
have experimented with moving the assigning of the variables inside the for
loop.
I'm sure i'm close and shall get it soon.
thanks again for your help and i'll reply with a result.

regards,
Paul.

"LarryR" <me@somewhere.com> wrote in message
news:r4SOb.7359$dd6.3614@lakeread02...
Hi Paul,

I think I see why you getting the first city 3 times. It has to do with
your how you are using the xpath expression to assign the variable
xe_CurrentConditions.
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")


Your xpath expression is always returns the 1st occurence of the
currentConditions element because your search is always occuring from the
top level xml element reference, xDoc.

Try moving the assignment of xe_CurrentConditions after your
> For Each xe_city In xe_weatherFeed.ChildNodes


and change the statement to read:

xe_CurrentConditions = xe_City.SelectSingleNode("currentConditions")

That way your are getting the current conditions child relative to the
current iteration of xe_city
rather than always the first one.

If you are using Visual Studio and have the debugger available to you,
examine the values of the variables as you step through the program. It
will lend a lot of insight to what is happening.

LarryR


"Paul M" <mi******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
Larry,

i've got an xml file which has multiple cities as the top level item.
When i read it in using XMLReader, and define the variables, as below, it finds the correct number of cities in the xml file, but repeats the first one 3 times. I'm sure its something minor but i just cant seem to figure

it
out.

here is the XML, and source code below:

--------------------XML---------------------
<?xml version="1.0" encoding="utf-8"?>
<weatherFeed>
<city>
<currentConditions>
country>Austria</country>
<city>Vienna</city>
<weatherImageURL>weather/lrg/sunny.gif</weatherImageURL>
<celcius>1C</celcius>
<farenheit>34F</farenheit>
<description>Sunny</description>
<relativeHumidity>69%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-4C</lowCelcius>
<highFarenheit>33F</highFarenheit>
<lowFarenheit>24F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>21F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>25F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>28F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<country>Austria</country>
<city>Innsbruck</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>74%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPressure>30.13Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>10F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit>22F</highFarenheit>
<lowFarenheit>5F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>26F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>27F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?locCode=LOWS--> <country>Austria</country>
<city>Salzburg</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>86%</relativeHumidity>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-5C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>23F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit>35F</highFarenheit>
<lowFarenheit>15F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>24F</highFarenheit>
<lowFarenheit>11F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>0C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>32F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
</weatherFeed>

----------------SOURCE CODE-----------------
Dim xDoc As New XmlDocument
Dim xe_weatherFeed As XmlElement
Dim xe_city As XmlNode
Dim xe_currentConditions As XmlElement
Dim xe_currentConditionsChild As XmlNode
Dim xe_fiveDayForecast As XmlElement
Dim xe_fiveDayForecastDay As XmlElement
Dim xe_fiveDayForecastDayDetails As XmlNode

Try
Dim a() As String
Dim al As New ArrayList
Dim i As Integer

xDoc.Load(strBaseURL & "weather/" &
Request.QueryString("countryID") & ".xml")
xe_weatherFeed = xDoc.SelectSingleNode("/weatherFeed")
xe_city = xDoc.SelectSingleNode("/weatherFeed/city")
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
xe_fiveDayForecast =
xDoc.SelectSingleNode("/weatherFeed/city/fiveDayForecast")

For Each xe_city In xe_weatherFeed.ChildNodes
If xe_city.NodeType = XmlNodeType.Element Then
ReDim Preserve a(41)
i = 0
For Each xe_currentConditionsChild In
xe_currentConditions.ChildNodes
If xe_currentConditionsChild.NodeType =
XmlNodeType.Element Then
a(i) = xe_currentConditionsChild.InnerText i += 1
End If
Next

For Each xe_fiveDayForecastDay In

xe_fiveDayForecast
For Each xe_fiveDayForecastDayDetails In
xe_fiveDayForecastDay
If xe_fiveDayForecastDayDetails.NodeType = XmlNodeType.Element Then
a(i) =
xe_fiveDayForecastDayDetails.InnerText
i += 1
End If
Next
Next
al.Add(a)
End If
Next
weatherRepeater.DataSource = al
weatherRepeater.DataBind()
Catch err As Exception
Response.Write("<br><font color=red><b>" & err.Message &
"</b></font>")
Finally
xDoc = Nothing
End Try

thanks in advance

Paul.


Nov 12 '05 #3

P: n/a
Hi Larry,

thanks for that. As hard as i was staring at the code i didnt realise that
the SelectSingleNode method was always referencing xDoc instead of xe_city.
Everything is working exactly as i want now.
Many thanks again for your help and i appreciate the time you've taken to
help me out with your useful responses.

regards,
Paul.
"LarryR" <me@somewhere.com> wrote in message
news:r4SOb.7359$dd6.3614@lakeread02...
Hi Paul,

I think I see why you getting the first city 3 times. It has to do with
your how you are using the xpath expression to assign the variable
xe_CurrentConditions.
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")


Your xpath expression is always returns the 1st occurence of the
currentConditions element because your search is always occuring from the
top level xml element reference, xDoc.

Try moving the assignment of xe_CurrentConditions after your
> For Each xe_city In xe_weatherFeed.ChildNodes


and change the statement to read:

xe_CurrentConditions = xe_City.SelectSingleNode("currentConditions")

That way your are getting the current conditions child relative to the
current iteration of xe_city
rather than always the first one.

If you are using Visual Studio and have the debugger available to you,
examine the values of the variables as you step through the program. It
will lend a lot of insight to what is happening.

LarryR


"Paul M" <mi******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
Larry,

i've got an xml file which has multiple cities as the top level item.
When i read it in using XMLReader, and define the variables, as below, it finds the correct number of cities in the xml file, but repeats the first one 3 times. I'm sure its something minor but i just cant seem to figure

it
out.

here is the XML, and source code below:

--------------------XML---------------------
<?xml version="1.0" encoding="utf-8"?>
<weatherFeed>
<city>
<currentConditions>
country>Austria</country>
<city>Vienna</city>
<weatherImageURL>weather/lrg/sunny.gif</weatherImageURL>
<celcius>1C</celcius>
<farenheit>34F</farenheit>
<description>Sunny</description>
<relativeHumidity>69%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-4C</lowCelcius>
<highFarenheit>33F</highFarenheit>
<lowFarenheit>24F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>21F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>25F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>28F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<country>Austria</country>
<city>Innsbruck</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>74%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPressure>30.13Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>10F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit>22F</highFarenheit>
<lowFarenheit>5F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>26F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>27F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?locCode=LOWS--> <country>Austria</country>
<city>Salzburg</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>86%</relativeHumidity>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-5C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>23F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit>35F</highFarenheit>
<lowFarenheit>15F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>24F</highFarenheit>
<lowFarenheit>11F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>0C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>32F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
</weatherFeed>

----------------SOURCE CODE-----------------
Dim xDoc As New XmlDocument
Dim xe_weatherFeed As XmlElement
Dim xe_city As XmlNode
Dim xe_currentConditions As XmlElement
Dim xe_currentConditionsChild As XmlNode
Dim xe_fiveDayForecast As XmlElement
Dim xe_fiveDayForecastDay As XmlElement
Dim xe_fiveDayForecastDayDetails As XmlNode

Try
Dim a() As String
Dim al As New ArrayList
Dim i As Integer

xDoc.Load(strBaseURL & "weather/" &
Request.QueryString("countryID") & ".xml")
xe_weatherFeed = xDoc.SelectSingleNode("/weatherFeed")
xe_city = xDoc.SelectSingleNode("/weatherFeed/city")
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
xe_fiveDayForecast =
xDoc.SelectSingleNode("/weatherFeed/city/fiveDayForecast")

For Each xe_city In xe_weatherFeed.ChildNodes
If xe_city.NodeType = XmlNodeType.Element Then
ReDim Preserve a(41)
i = 0
For Each xe_currentConditionsChild In
xe_currentConditions.ChildNodes
If xe_currentConditionsChild.NodeType =
XmlNodeType.Element Then
a(i) = xe_currentConditionsChild.InnerText i += 1
End If
Next

For Each xe_fiveDayForecastDay In

xe_fiveDayForecast
For Each xe_fiveDayForecastDayDetails In
xe_fiveDayForecastDay
If xe_fiveDayForecastDayDetails.NodeType = XmlNodeType.Element Then
a(i) =
xe_fiveDayForecastDayDetails.InnerText
i += 1
End If
Next
Next
al.Add(a)
End If
Next
weatherRepeater.DataSource = al
weatherRepeater.DataBind()
Catch err As Exception
Response.Write("<br><font color=red><b>" & err.Message &
"</b></font>")
Finally
xDoc = Nothing
End Try

thanks in advance

Paul.


Nov 12 '05 #4

P: n/a
Paul,

Good deal, Paul. The more you work with it, the more it will sense. I'm
glad the examples helped.

Larry
"Paul M" <mi******@hotmail.com> wrote in message
news:O$**************@tk2msftngp13.phx.gbl...
Hi Larry,

thanks for that. As hard as i was staring at the code i didnt realise that
the SelectSingleNode method was always referencing xDoc instead of xe_city. Everything is working exactly as i want now.
Many thanks again for your help and i appreciate the time you've taken to
help me out with your useful responses.

regards,
Paul.
"LarryR" <me@somewhere.com> wrote in message
news:r4SOb.7359$dd6.3614@lakeread02...
Hi Paul,

I think I see why you getting the first city 3 times. It has to do with
your how you are using the xpath expression to assign the variable
xe_CurrentConditions.
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
Your xpath expression is always returns the 1st occurence of the
currentConditions element because your search is always occuring from the top level xml element reference, xDoc.

Try moving the assignment of xe_CurrentConditions after your
> For Each xe_city In xe_weatherFeed.ChildNodes


and change the statement to read:

xe_CurrentConditions = xe_City.SelectSingleNode("currentConditions")

That way your are getting the current conditions child relative to the
current iteration of xe_city
rather than always the first one.

If you are using Visual Studio and have the debugger available to you,
examine the values of the variables as you step through the program. It
will lend a lot of insight to what is happening.

LarryR


"Paul M" <mi******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
Larry,

i've got an xml file which has multiple cities as the top level item.
When i read it in using XMLReader, and define the variables, as below, it finds the correct number of cities in the xml file, but repeats the first one 3 times. I'm sure its something minor but i just cant seem to figure it
out.

here is the XML, and source code below:

--------------------XML---------------------
<?xml version="1.0" encoding="utf-8"?>
<weatherFeed>
<city>
<currentConditions>
country>Austria</country>
<city>Vienna</city>
<weatherImageURL>weather/lrg/sunny.gif</weatherImageURL>
<celcius>1C</celcius>
<farenheit>34F</farenheit>
<description>Sunny</description>
<relativeHumidity>69%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-4C</lowCelcius>
<highFarenheit>33F</highFarenheit>
<lowFarenheit>24F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>21F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>25F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>28F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<country>Austria</country>
<city>Innsbruck</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>74%</relativeHumidity>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPressure>30.13Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<!--5 Day Weather Forecast-->
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit>29F</highFarenheit>
<lowFarenheit>17F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>10F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit>22F</highFarenheit>
<lowFarenheit>5F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>26F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit>34F</highFarenheit>
<lowFarenheit>27F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
<city>
<currentConditions>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?locCode=LOWS--> <country>Austria</country>
<city>Salzburg</city>
<weatherImageURL>weather/lrg/mostly.cloudy.gif</weatherImageURL>
<celcius>0C</celcius>
<farenheit>32F</farenheit>
<description>Mostly Cloudy</description>
<relativeHumidity>86%</relativeHumidity>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPressure>30.1Hg (F)</barometricPressure>
<lastUpdated>1/19/2004 4:01:12 AM</lastUpdated>
</currentConditions>
<fiveDayForecast>
<Day1>
<day>Monday</day>
<highCelcius>0C</highCelcius>
<lowCelcius>-5C</lowCelcius>
<highFarenheit>32F</highFarenheit>
<lowFarenheit>23F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit>35F</highFarenheit>
<lowFarenheit>15F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit>24F</highFarenheit>
<lowFarenheit>11F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>1C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>33F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3C</highCelcius>
<lowCelcius>0C</lowCelcius>
<highFarenheit>37F</highFarenheit>
<lowFarenheit>32F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast>
</city>
</weatherFeed>

----------------SOURCE CODE-----------------
Dim xDoc As New XmlDocument
Dim xe_weatherFeed As XmlElement
Dim xe_city As XmlNode
Dim xe_currentConditions As XmlElement
Dim xe_currentConditionsChild As XmlNode
Dim xe_fiveDayForecast As XmlElement
Dim xe_fiveDayForecastDay As XmlElement
Dim xe_fiveDayForecastDayDetails As XmlNode

Try
Dim a() As String
Dim al As New ArrayList
Dim i As Integer

xDoc.Load(strBaseURL & "weather/" &
Request.QueryString("countryID") & ".xml")
xe_weatherFeed = xDoc.SelectSingleNode("/weatherFeed")
xe_city = xDoc.SelectSingleNode("/weatherFeed/city")
xe_currentConditions =
xDoc.SelectSingleNode("/weatherFeed/city/currentConditions")
xe_fiveDayForecast =
xDoc.SelectSingleNode("/weatherFeed/city/fiveDayForecast")

For Each xe_city In xe_weatherFeed.ChildNodes
If xe_city.NodeType = XmlNodeType.Element Then
ReDim Preserve a(41)
i = 0
For Each xe_currentConditionsChild In
xe_currentConditions.ChildNodes
If xe_currentConditionsChild.NodeType =
XmlNodeType.Element Then
a(i) = xe_currentConditionsChild.InnerText i += 1
End If
Next

For Each xe_fiveDayForecastDay In

xe_fiveDayForecast
For Each xe_fiveDayForecastDayDetails In
xe_fiveDayForecastDay
If
xe_fiveDayForecastDayDetails.NodeType = XmlNodeType.Element Then
a(i) =
xe_fiveDayForecastDayDetails.InnerText
i += 1
End If
Next
Next
al.Add(a)
End If
Next
weatherRepeater.DataSource = al
weatherRepeater.DataBind()
Catch err As Exception
Response.Write("<br><font color=red><b>" & err.Message

& "</b></font>")
Finally
xDoc = Nothing
End Try

thanks in advance

Paul.



Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.