473,570 Members | 2,995 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>1C</celcius>
<farenheit>34F </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>-4C</lowCelcius>
<highFarenheit> 33F</highFarenheit>
<lowFarenheit>2 4F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 1F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 25F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>2 8F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>3 3F</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>0C</celcius>
<farenheit>32F </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>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0 C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>1 0F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit> 22F</highFarenheit>
<lowFarenheit>5 F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 6F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 7F</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>0C</celcius>
<farenheit>32F </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>-5C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>2 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2 C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit> 35F</highFarenheit>
<lowFarenheit>1 5F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 24F</highFarenheit>
<lowFarenheit>1 1F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3 C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3 C</highCelcius>
<lowCelcius>0C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 2F</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 1669
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>1C</celcius>
<farenheit>34F </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>-4C</lowCelcius>
<highFarenheit> 33F</highFarenheit>
<lowFarenheit>2 4F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 1F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 25F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>2 8F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>3 3F</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>0C</celcius>
<farenheit>32F </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>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0 C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>1 0F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit> 22F</highFarenheit>
<lowFarenheit>5 F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 6F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 7F</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>0C</celcius>
<farenheit>32F </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>-5C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>2 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2 C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit> 35F</highFarenheit>
<lowFarenheit>1 5F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 24F</highFarenheit>
<lowFarenheit>1 1F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3 C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3 C</highCelcius>
<lowCelcius>0C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 2F</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>1C</celcius>
<farenheit>34F </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>-4C</lowCelcius>
<highFarenheit> 33F</highFarenheit>
<lowFarenheit>2 4F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 1F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 25F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>2 8F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>3 3F</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>0C</celcius>
<farenheit>32F </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>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0 C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>1 0F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit> 22F</highFarenheit>
<lowFarenheit>5 F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 6F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 7F</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>0C</celcius>
<farenheit>32F </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>-5C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>2 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2 C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit> 35F</highFarenheit>
<lowFarenheit>1 5F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 24F</highFarenheit>
<lowFarenheit>1 1F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3 C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3 C</highCelcius>
<lowCelcius>0C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 2F</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>1C</celcius>
<farenheit>34F </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>-4C</lowCelcius>
<highFarenheit> 33F</highFarenheit>
<lowFarenheit>2 4F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 1F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 25F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>2 8F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>3 3F</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>0C</celcius>
<farenheit>32F </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>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0 C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>1 0F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit> 22F</highFarenheit>
<lowFarenheit>5 F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 6F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 7F</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>0C</celcius>
<farenheit>32F </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>-5C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>2 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2 C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit> 35F</highFarenheit>
<lowFarenheit>1 5F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 24F</highFarenheit>
<lowFarenheit>1 1F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3 C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3 C</highCelcius>
<lowCelcius>0C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 2F</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>1C</celcius>
<farenheit>34F </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>-4C</lowCelcius>
<highFarenheit> 33F</highFarenheit>
<lowFarenheit>2 4F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-6C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 1F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 25F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>-2C</highCelcius>
<lowCelcius>-2C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>2 8F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>-2C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>3 3F</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>0C</celcius>
<farenheit>32F </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>-2C</highCelcius>
<lowCelcius>-8C</lowCelcius>
<highFarenheit> 29F</highFarenheit>
<lowFarenheit>1 7F</lowFarenheit>
<imageURL>weath er/med/partly.cloudy.g if</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>0 C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>1 0F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-6C</highCelcius>
<lowCelcius>-15C</lowCelcius>
<highFarenheit> 22F</highFarenheit>
<lowFarenheit>5 F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 6F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>1 C</highCelcius>
<lowCelcius>-3C</lowCelcius>
<highFarenheit> 34F</highFarenheit>
<lowFarenheit>2 7F</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>0C</celcius>
<farenheit>32F </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>-5C</lowCelcius>
<highFarenheit> 32F</highFarenheit>
<lowFarenheit>2 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day1>
<Day2>
<day>Tuesday</day>
<highCelcius>2 C</highCelcius>
<lowCelcius>-9C</lowCelcius>
<highFarenheit> 35F</highFarenheit>
<lowFarenheit>1 5F</lowFarenheit>
<imageURL>weath er/med/snow.gif</imageURL>
</Day2>
<Day3>
<day>Wednesda y</day>
<highCelcius>-4C</highCelcius>
<lowCelcius>-12C</lowCelcius>
<highFarenheit> 24F</highFarenheit>
<lowFarenheit>1 1F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day3>
<Day4>
<day>Thursday </day>
<highCelcius>3 C</highCelcius>
<lowCelcius>1C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 3F</lowFarenheit>
<imageURL>weath er/med/cloudy.gif</imageURL>
</Day4>
<Day5>
<day>Friday</day>
<highCelcius>3 C</highCelcius>
<lowCelcius>0C </lowCelcius>
<highFarenheit> 37F</highFarenheit>
<lowFarenheit>3 2F</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
7421
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...
1
1693
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...
3
2683
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
6243
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...
1
1038
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
1287
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 ...
0
2482
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. ...
4
5755
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...
0
7636
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8150
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...
0
8000
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...
0
6329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
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...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3682
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...
1
2131
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
1
1238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.