473,761 Members | 10,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
<currentConditi ons>
country>Austria </country>
<city>Vienna</city>
<weatherImageUR L>weather/lrg/sunny.gif</weatherImageURL >
<celcius>1°C</celcius>
<farenheit>34°F </farenheit>
<description>Su nny</description>
<relativeHumidi ty>69%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit> 33°F</highFarenheit>
<lowFarenheit>2 4°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 1°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 25°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>2 8°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<country>Austri a</country>
<city>Innsbruck </city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>74%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPres sure>30.13Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>1 0°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit> 22°F</highFarenheit>
<lowFarenheit>5 °F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 6°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?lo cCode=LOWS-->
<country>Austri a</country>
<city>Salzbur g</city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>86%</relativeHumidit y>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>2 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2° C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit> 35°F</highFarenheit>
<lowFarenheit>1 5°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 24°F</highFarenheit>
<lowFarenheit>1 1°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3° C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3° C</highCelcius>
<lowCelcius>0°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 2°F</lowFarenheit>
<imageURL>weath er/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_currentCondi tions As XmlElement
Dim xe_currentCondi tionsChild As XmlNode
Dim xe_fiveDayForec ast As XmlElement
Dim xe_fiveDayForec astDay As XmlElement
Dim xe_fiveDayForec astDayDetails As XmlNode

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

xDoc.Load(strBa seURL & "weather/" &
Request.QuerySt ring("countryID ") & ".xml")
xe_weatherFeed = xDoc.SelectSing leNode("/weatherFeed")
xe_city = xDoc.SelectSing leNode("/weatherFeed/city")
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
xe_fiveDayForec ast =
xDoc.SelectSing leNode("/weatherFeed/city/fiveDayForecast ")

For Each xe_city In xe_weatherFeed. ChildNodes
If xe_city.NodeTyp e = XmlNodeType.Ele ment Then
ReDim Preserve a(41)
i = 0
For Each xe_currentCondi tionsChild In
xe_currentCondi tions.ChildNode s
If xe_currentCondi tionsChild.Node Type =
XmlNodeType.Ele ment Then
a(i) = xe_currentCondi tionsChild.Inne rText
i += 1
End If
Next

For Each xe_fiveDayForec astDay In xe_fiveDayForec ast
For Each xe_fiveDayForec astDayDetails In
xe_fiveDayForec astDay
If xe_fiveDayForec astDayDetails.N odeType =
XmlNodeType.Ele ment Then
a(i) =
xe_fiveDayForec astDayDetails.I nnerText
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 1683
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_CurrentCondi tions.
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
Your xpath expression is always returns the 1st occurence of the
currentConditio ns element because your search is always occuring from the
top level xml element reference, xDoc.

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

xe_CurrentCondi tions = xe_City.SelectS ingleNode("curr entConditions")

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******@hotma il.com> wrote in message
news:uV******** ******@TK2MSFTN GP11.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>
<currentConditi ons>
country>Austria </country>
<city>Vienna</city>
<weatherImageUR L>weather/lrg/sunny.gif</weatherImageURL >
<celcius>1°C</celcius>
<farenheit>34°F </farenheit>
<description>Su nny</description>
<relativeHumidi ty>69%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit> 33°F</highFarenheit>
<lowFarenheit>2 4°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 1°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 25°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>2 8°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<country>Austri a</country>
<city>Innsbruck </city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>74%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPres sure>30.13Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>1 0°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit> 22°F</highFarenheit>
<lowFarenheit>5 °F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 6°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?lo cCode=LOWS-->
<country>Austri a</country>
<city>Salzbur g</city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>86%</relativeHumidit y>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>2 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2° C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit> 35°F</highFarenheit>
<lowFarenheit>1 5°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 24°F</highFarenheit>
<lowFarenheit>1 1°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3° C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3° C</highCelcius>
<lowCelcius>0°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 2°F</lowFarenheit>
<imageURL>weath er/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_currentCondi tions As XmlElement
Dim xe_currentCondi tionsChild As XmlNode
Dim xe_fiveDayForec ast As XmlElement
Dim xe_fiveDayForec astDay As XmlElement
Dim xe_fiveDayForec astDayDetails As XmlNode

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

xDoc.Load(strBa seURL & "weather/" &
Request.QuerySt ring("countryID ") & ".xml")
xe_weatherFeed = xDoc.SelectSing leNode("/weatherFeed")
xe_city = xDoc.SelectSing leNode("/weatherFeed/city")
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
xe_fiveDayForec ast =
xDoc.SelectSing leNode("/weatherFeed/city/fiveDayForecast ")

For Each xe_city In xe_weatherFeed. ChildNodes
If xe_city.NodeTyp e = XmlNodeType.Ele ment Then
ReDim Preserve a(41)
i = 0
For Each xe_currentCondi tionsChild In
xe_currentCondi tions.ChildNode s
If xe_currentCondi tionsChild.Node Type =
XmlNodeType.Ele ment Then
a(i) = xe_currentCondi tionsChild.Inne rText
i += 1
End If
Next

For Each xe_fiveDayForec astDay In xe_fiveDayForec ast For Each xe_fiveDayForec astDayDetails In
xe_fiveDayForec astDay
If xe_fiveDayForec astDayDetails.N odeType =
XmlNodeType.Ele ment Then
a(i) =
xe_fiveDayForec astDayDetails.I nnerText
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.c om> wrote in message
news:r4SOb.7359 $dd6.3614@laker ead02...
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_CurrentCondi tions.
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")


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

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


and change the statement to read:

xe_CurrentCondi tions = xe_City.SelectS ingleNode("curr entConditions")

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******@hotma il.com> wrote in message
news:uV******** ******@TK2MSFTN GP11.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>
<currentConditi ons>
country>Austria </country>
<city>Vienna</city>
<weatherImageUR L>weather/lrg/sunny.gif</weatherImageURL >
<celcius>1°C</celcius>
<farenheit>34°F </farenheit>
<description>Su nny</description>
<relativeHumidi ty>69%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit> 33°F</highFarenheit>
<lowFarenheit>2 4°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 1°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 25°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>2 8°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<country>Austri a</country>
<city>Innsbruck </city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>74%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPres sure>30.13Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>1 0°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit> 22°F</highFarenheit>
<lowFarenheit>5 °F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 6°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?lo cCode=LOWS--> <country>Austri a</country>
<city>Salzbur g</city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>86%</relativeHumidit y>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>2 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2° C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit> 35°F</highFarenheit>
<lowFarenheit>1 5°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 24°F</highFarenheit>
<lowFarenheit>1 1°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3° C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3° C</highCelcius>
<lowCelcius>0°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 2°F</lowFarenheit>
<imageURL>weath er/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_currentCondi tions As XmlElement
Dim xe_currentCondi tionsChild As XmlNode
Dim xe_fiveDayForec ast As XmlElement
Dim xe_fiveDayForec astDay As XmlElement
Dim xe_fiveDayForec astDayDetails As XmlNode

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

xDoc.Load(strBa seURL & "weather/" &
Request.QuerySt ring("countryID ") & ".xml")
xe_weatherFeed = xDoc.SelectSing leNode("/weatherFeed")
xe_city = xDoc.SelectSing leNode("/weatherFeed/city")
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
xe_fiveDayForec ast =
xDoc.SelectSing leNode("/weatherFeed/city/fiveDayForecast ")

For Each xe_city In xe_weatherFeed. ChildNodes
If xe_city.NodeTyp e = XmlNodeType.Ele ment Then
ReDim Preserve a(41)
i = 0
For Each xe_currentCondi tionsChild In
xe_currentCondi tions.ChildNode s
If xe_currentCondi tionsChild.Node Type =
XmlNodeType.Ele ment Then
a(i) = xe_currentCondi tionsChild.Inne rText i += 1
End If
Next

For Each xe_fiveDayForec astDay In

xe_fiveDayForec ast
For Each xe_fiveDayForec astDayDetails In
xe_fiveDayForec astDay
If xe_fiveDayForec astDayDetails.N odeType = XmlNodeType.Ele ment Then
a(i) =
xe_fiveDayForec astDayDetails.I nnerText
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 SelectSingleNod e 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.c om> wrote in message
news:r4SOb.7359 $dd6.3614@laker ead02...
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_CurrentCondi tions.
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")


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

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


and change the statement to read:

xe_CurrentCondi tions = xe_City.SelectS ingleNode("curr entConditions")

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******@hotma il.com> wrote in message
news:uV******** ******@TK2MSFTN GP11.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>
<currentConditi ons>
country>Austria </country>
<city>Vienna</city>
<weatherImageUR L>weather/lrg/sunny.gif</weatherImageURL >
<celcius>1°C</celcius>
<farenheit>34°F </farenheit>
<description>Su nny</description>
<relativeHumidi ty>69%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit> 33°F</highFarenheit>
<lowFarenheit>2 4°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 1°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 25°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>2 8°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<country>Austri a</country>
<city>Innsbruck </city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>74%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPres sure>30.13Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>1 0°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit> 22°F</highFarenheit>
<lowFarenheit>5 °F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 6°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?lo cCode=LOWS--> <country>Austri a</country>
<city>Salzbur g</city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>86%</relativeHumidit y>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>2 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2° C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit> 35°F</highFarenheit>
<lowFarenheit>1 5°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 24°F</highFarenheit>
<lowFarenheit>1 1°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3° C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3° C</highCelcius>
<lowCelcius>0°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 2°F</lowFarenheit>
<imageURL>weath er/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_currentCondi tions As XmlElement
Dim xe_currentCondi tionsChild As XmlNode
Dim xe_fiveDayForec ast As XmlElement
Dim xe_fiveDayForec astDay As XmlElement
Dim xe_fiveDayForec astDayDetails As XmlNode

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

xDoc.Load(strBa seURL & "weather/" &
Request.QuerySt ring("countryID ") & ".xml")
xe_weatherFeed = xDoc.SelectSing leNode("/weatherFeed")
xe_city = xDoc.SelectSing leNode("/weatherFeed/city")
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
xe_fiveDayForec ast =
xDoc.SelectSing leNode("/weatherFeed/city/fiveDayForecast ")

For Each xe_city In xe_weatherFeed. ChildNodes
If xe_city.NodeTyp e = XmlNodeType.Ele ment Then
ReDim Preserve a(41)
i = 0
For Each xe_currentCondi tionsChild In
xe_currentCondi tions.ChildNode s
If xe_currentCondi tionsChild.Node Type =
XmlNodeType.Ele ment Then
a(i) = xe_currentCondi tionsChild.Inne rText i += 1
End If
Next

For Each xe_fiveDayForec astDay In

xe_fiveDayForec ast
For Each xe_fiveDayForec astDayDetails In
xe_fiveDayForec astDay
If xe_fiveDayForec astDayDetails.N odeType = XmlNodeType.Ele ment Then
a(i) =
xe_fiveDayForec astDayDetails.I nnerText
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******@hotma il.com> wrote in message
news:O$******** ******@tk2msftn gp13.phx.gbl...
Hi Larry,

thanks for that. As hard as i was staring at the code i didnt realise that
the SelectSingleNod e 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.c om> wrote in message
news:r4SOb.7359 $dd6.3614@laker ead02...
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_CurrentCondi tions.
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
Your xpath expression is always returns the 1st occurence of the
currentConditio ns element because your search is always occuring from the top level xml element reference, xDoc.

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


and change the statement to read:

xe_CurrentCondi tions = xe_City.SelectS ingleNode("curr entConditions")

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******@hotma il.com> wrote in message
news:uV******** ******@TK2MSFTN GP11.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>
<currentConditi ons>
country>Austria </country>
<city>Vienna</city>
<weatherImageUR L>weather/lrg/sunny.gif</weatherImageURL >
<celcius>1°C</celcius>
<farenheit>34°F </farenheit>
<description>Su nny</description>
<relativeHumidi ty>69%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:37 AM</sunrise>
<sunset>4:32 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-4°C</lowCelcius>
<highFarenheit> 33°F</highFarenheit>
<lowFarenheit>2 4°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-6°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 1°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 25°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-2°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>2 8°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<country>Austri a</country>
<city>Innsbruck </city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>74%</relativeHumidit y>
<wind>N at 1 mph (2 km/h)</wind>
<sunrise>7:55 AM</sunrise>
<sunset>4:56 PM</sunset>
<barometricPres sure>30.13Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<!--5 Day Weather Forecast-->
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>-2°C</highCelcius>
<lowCelcius>-8°C</lowCelcius>
<highFarenheit> 29°F</highFarenheit>
<lowFarenheit>1 7°F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>1 0°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6°C</highCelcius>
<lowCelcius>-15°C</lowCelcius>
<highFarenheit> 22°F</highFarenheit>
<lowFarenheit>5 °F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 6°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1° C</highCelcius>
<lowCelcius>-3°C</lowCelcius>
<highFarenheit> 34°F</highFarenheit>
<lowFarenheit>2 7°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day5>
</fiveDayForecast >
</city>
<city>
<currentConditi ons>
<!--URL: http://weather.cnn.com/weather/forecast.jsp?lo cCode=LOWS--> <country>Austri a</country>
<city>Salzbur g</city>
<weatherImageUR L>weather/lrg/mostly.cloudy.g if</weatherImageURL >
<celcius>0°C</celcius>
<farenheit>32°F </farenheit>
<description>Mo stly Cloudy</description>
<relativeHumidi ty>86%</relativeHumidit y>
<wind>NNW at 2 mph (3 km/h)</wind>
<sunrise>7:50 AM</sunrise>
<sunset>4:48 PM</sunset>
<barometricPres sure>30.1Hg (F)</barometricPress ure>
<lastUpdated> 1/19/2004 4:01:12 AM</lastUpdated>
</currentConditio ns>
<fiveDayForecas t>
<Day1>
<day>Monday</day>
<highCelcius>0° C</highCelcius>
<lowCelcius>-5°C</lowCelcius>
<highFarenheit> 32°F</highFarenheit>
<lowFarenheit>2 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2° C</highCelcius>
<lowCelcius>-9°C</lowCelcius>
<highFarenheit> 35°F</highFarenheit>
<lowFarenheit>1 5°F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4°C</highCelcius>
<lowCelcius>-12°C</lowCelcius>
<highFarenheit> 24°F</highFarenheit>
<lowFarenheit>1 1°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3° C</highCelcius>
<lowCelcius>1°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 3°F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3° C</highCelcius>
<lowCelcius>0°C </lowCelcius>
<highFarenheit> 37°F</highFarenheit>
<lowFarenheit>3 2°F</lowFarenheit>
<imageURL>weath er/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_currentCondi tions As XmlElement
Dim xe_currentCondi tionsChild As XmlNode
Dim xe_fiveDayForec ast As XmlElement
Dim xe_fiveDayForec astDay As XmlElement
Dim xe_fiveDayForec astDayDetails As XmlNode

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

xDoc.Load(strBa seURL & "weather/" &
Request.QuerySt ring("countryID ") & ".xml")
xe_weatherFeed = xDoc.SelectSing leNode("/weatherFeed")
xe_city = xDoc.SelectSing leNode("/weatherFeed/city")
xe_currentCondi tions =
xDoc.SelectSing leNode("/weatherFeed/city/currentConditio ns")
xe_fiveDayForec ast =
xDoc.SelectSing leNode("/weatherFeed/city/fiveDayForecast ")

For Each xe_city In xe_weatherFeed. ChildNodes
If xe_city.NodeTyp e = XmlNodeType.Ele ment Then
ReDim Preserve a(41)
i = 0
For Each xe_currentCondi tionsChild In
xe_currentCondi tions.ChildNode s
If xe_currentCondi tionsChild.Node Type =
XmlNodeType.Ele ment Then
a(i) = xe_currentCondi tionsChild.Inne rText i += 1
End If
Next

For Each xe_fiveDayForec astDay In

xe_fiveDayForec ast
For Each xe_fiveDayForec astDayDetails In
xe_fiveDayForec astDay
If
xe_fiveDayForec astDayDetails.N odeType = XmlNodeType.Ele ment Then
a(i) =
xe_fiveDayForec astDayDetails.I nnerText
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
7472
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286) word size was 16 bits same as an integer. Now with a 32 bit CPU I would have expected the long to be faster as it's the same size as the CPU's word size so wouldn't need sawing in half like a magician's assistant to calculate on like an...
1
1706
by: Tim | last post by:
Hi, I'm very new to .NET and am programming in C#. I have a web application where i have two list boxes. Its kind of like a shopping card where you can add items from one 'locations' list box to the 'locations selected' (cart) listbox. I have a hirarchy of locations - main locations and sub locations. main locations being the parent locations, and the sub locations being the child locations. I want to be able to check to see if the...
3
2698
by: VB Programmer | last post by:
Here's the code: For Each li As ListItem In Me.lstAssignedEmailAddresses.Items If li.Selected = True Then Me.lstAssignedEmailAddresses.Items.Remove(li) End If Next When I remove an item I get this error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at
2
6252
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript that enables the items -- this works perfectly. However, when I then click a LinkButton that does a postback and I loop through the items on serverside to pick up the selected ones, it doesn't pick them up. IMHO it seems to loop though the items...
1
1043
by: Mr. SweatyFinger | last post by:
Given this: *************************** For Each entryName In Request.Form Response.Write("Name: " & entryName & "<br/>") Response.Write("Value: " & Request.Form(entryName) & "<br/>") Next
2
1294
by: olud | last post by:
Hi All, I am trying to insert selected contents of a listbox into a database by looping through the collection. The loop is working and the contents are going into the database. Starnge thing is i come up with this error as soon as the contents are inserted in the database!. Dim iCount As Integer Dim ddlcount As Integer Dim strItem As String For iCount = 0 To CInt(ddlSelectedLocations.Items.Count)
0
2492
by: LLM | last post by:
Ok I fill a CheckedListBox this way clbRoles.DataSource = objSecurity.ReturnRoleList(); clbRoles.DisplayMember = "RoleName"; clbRoles.ValueMember = "RoleID"; #1 Issue: I want to select certain items in those list for roles the user already has. I tried the following but the last part doesn't work. How do I get the ID of the item as I am looping through? for (int x = 0; x <=...
4
5761
by: adiel_g | last post by:
I am trying to loop through a repeater to retrieve a dataitem field but am getting a NullReferenceException. I can find a checkbox control but cannot find a dataitem field. Here is the code that is looping through the repeater: Dim rc As RepeaterItemCollection = rptReport.Items Dim ri As RepeaterItem Dim chkSelected As System.Web.UI.WebControls.CheckBox Dim customer As String
0
9521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9945
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.