472,103 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,103 software developers and data experts.

help with looping through XML items.

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>1°C</celcius>
<farenheit>34°F</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>1°C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit>33°F</highFarenheit>
<lowFarenheit>24°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>21°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>25°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>28°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>33°F</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>0°C</celcius>
<farenheit>32°F</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>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>10°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit>22°F</highFarenheit>
<lowFarenheit>5°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>26°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>27°F</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>0°C</celcius>
<farenheit>32°F</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>0°C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>23°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2°C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit>35°F</highFarenheit>
<lowFarenheit>15°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>24°F</highFarenheit>
<lowFarenheit>11°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>33°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>0°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>32°F</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
4 1581
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>1°C</celcius>
<farenheit>34°F</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>1°C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit>33°F</highFarenheit>
<lowFarenheit>24°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>21°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>25°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>28°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>33°F</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>0°C</celcius>
<farenheit>32°F</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>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>10°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit>22°F</highFarenheit>
<lowFarenheit>5°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>26°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>27°F</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>0°C</celcius>
<farenheit>32°F</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>0°C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>23°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2°C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit>35°F</highFarenheit>
<lowFarenheit>15°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>24°F</highFarenheit>
<lowFarenheit>11°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>33°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>0°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>32°F</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
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>1°C</celcius>
<farenheit>34°F</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>1°C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit>33°F</highFarenheit>
<lowFarenheit>24°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>21°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>25°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>28°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>33°F</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>0°C</celcius>
<farenheit>32°F</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>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>10°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit>22°F</highFarenheit>
<lowFarenheit>5°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>26°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>27°F</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>0°C</celcius>
<farenheit>32°F</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>0°C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>23°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2°C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit>35°F</highFarenheit>
<lowFarenheit>15°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>24°F</highFarenheit>
<lowFarenheit>11°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>33°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>0°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>32°F</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
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>1°C</celcius>
<farenheit>34°F</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>1°C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit>33°F</highFarenheit>
<lowFarenheit>24°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>21°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>25°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>28°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>33°F</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>0°C</celcius>
<farenheit>32°F</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>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>10°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit>22°F</highFarenheit>
<lowFarenheit>5°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>26°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>27°F</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>0°C</celcius>
<farenheit>32°F</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>0°C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>23°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2°C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit>35°F</highFarenheit>
<lowFarenheit>15°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>24°F</highFarenheit>
<lowFarenheit>11°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>33°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>0°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>32°F</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
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>1°C</celcius>
<farenheit>34°F</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>1°C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit>33°F</highFarenheit>
<lowFarenheit>24°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>21°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>25°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>28°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>33°F</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>0°C</celcius>
<farenheit>32°F</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>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit>29°F</highFarenheit>
<lowFarenheit>17°F</lowFarenheit>
<imageURL>weather/med/partly.cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>10°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit>22°F</highFarenheit>
<lowFarenheit>5°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>26°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1°C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit>34°F</highFarenheit>
<lowFarenheit>27°F</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>0°C</celcius>
<farenheit>32°F</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>0°C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit>32°F</highFarenheit>
<lowFarenheit>23°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2°C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit>35°F</highFarenheit>
<lowFarenheit>15°F</lowFarenheit>
<imageURL>weather/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesday</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit>24°F</highFarenheit>
<lowFarenheit>11°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>1°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>33°F</lowFarenheit>
<imageURL>weather/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3°C</highCelcius>
<lowCelcius>0°C</lowCelcius>
<highFarenheit>37°F</highFarenheit>
<lowFarenheit>32°F</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.

Similar topics

45 posts views Thread by Trevor Best | last post: by
3 posts views Thread by VB Programmer | last post: by
1 post views Thread by Mr. SweatyFinger | last post: by
reply views Thread by LLM | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.