A few questions about XML

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
Hi,

I'm just learning VB, and I have a few questions. For the app I'm developing, I am accessing a website that's in XML format and for now I'm saving it to a file. I'd like to have my application save it to an array and have the information accessed from there, but I can't seem to figure out how to do it. An even better idea, if possible, would be to analyze each piece being downloaded, and only save it to the array if it's a certain XML line. I'm making a program to look up XML weather by zip code, so for example, I'd like it to only save a few lines. Here are some examples:
<tmp>53</tmp>
<flik>53</flik>

<t>Cloudy</t>

Thanks for any help. I've been looking online alot, but haven't found answers
 
Blake81, another tip, read the forum FAQ on how to put code in code boxes for better readability, it's really off-putting that mess in several of your posts, it makes me for one want to delete your post rather than help you. Use 'post reply' button to get to the better editor and the 'preview post' button to make sure it looks as intended before you post.
 
Thanks, I figured out how to do it. I do have another question though. I thought this part would be easy, but I'm having trouble with it. I have a label called Day1HighTemp (and Day1LowTemp, and one for each day for 1 through 5). I'm using a loop to get the info for each day, but this isn't working. You'll see what I'm trying to do with this code.
VB.NET:
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] x = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] 4
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] FSib.Attributes(1).InnerText = x [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] attr [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] FSib.Attributes
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] attr.Name = [/SIZE][SIZE=2][COLOR=#800000]"hi"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day + x + HighTemp.Text = attr.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][SIZE=2] x[/SIZE]


The part where I'm trying to get the right Day label isn't working. For example, when x = 1, I want it to use Day1HighTemp, when x =2, Day2HighTemp, etc.
 
I'm having problems getting this to loop and get the info for each day. It's the same XML source that I've posted before.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Fxml [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Xml.XmlDocument
Fxml = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Xml.XmlDocument
Fxml.Load([/SIZE][SIZE=2][COLOR=#800000]"http://xoap.weather.com/weather/local/30117?cc=*&dayf=5&prod=xoap&par=1017300893&key=268086eb4218acff"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Fnodes [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlNodeList
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Fnode [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlNode
Fnode = Fxml.SelectSingleNode([/SIZE][SIZE=2][COLOR=#800000]"/weather/dayf/day"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] FSib [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlNode = Fnode.NextSibling
Fnodes = FSib.ChildNodes
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] attr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlAttribute
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] attr [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] Fnode.Attributes
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] attr.Name = [/SIZE][SIZE=2][COLOR=#800000]"dt"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day1Label.Text = attr.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] FNext [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlNode
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 1
FNext = Fnode.NextSibling
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] FNext [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] Fnodes
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] x = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] 4
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Fnode.Name = [/SIZE][SIZE=2][COLOR=#800000]"hi"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] x = 1 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day1HighTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] x = 2 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day2HighTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] x = 3 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day3HighTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] x = 4 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day4HighTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] Fnode.Name = [/SIZE][SIZE=2][COLOR=#800000]"low"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] x = 1 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day1LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] x = 2 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day2LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] x = 3 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day3LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] x = 4 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day4LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][SIZE=2] x
Fnode = FNext
[/SIZE][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][SIZE=2] FNext
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

It's posting the high and low temp for the first day in the high/low labels for all the days.
 
You have set Fnodes to be the childnodes of the second day and iterate them 4 times thinking they are the day nodes. Very funny :)
This is the collection of day nodes:
VB.NET:
Fnodes = Fxml.SelectNodes([SIZE=2][COLOR=#800000]"/weather/dayf/day"[/COLOR][/SIZE][SIZE=2])[/SIZE]
 
Here's some code that fixes it along with some other edits.

VB.NET:
        Dim Fxml As New System.Xml.XmlDocument
        Fxml = New System.Xml.XmlDocument
        Fxml.Load("[URL="http://xoap.weather.com/weather/local/30117?cc=*&dayf=5&prod=xoap&par=1017300893&key=268086eb4218acff"]http://xoap.weather.com/weather/local/30117?cc=*&dayf=5&prod=xoap&par=1017300893&key=268086eb4218acff[/URL]")
        Dim Fnodes As System.Xml.XmlNodeList
        Dim Fnode As System.Xml.XmlNode
        Fnode = Fxml.SelectSingleNode("/weather/dayf") 'I moved this a level up so that you can access all the days, rather than just the first
        Fnodes = Fnode.ChildNodes
        Day1Label.Text = Fnode.SelectSingleNode("day").Attributes("dt").InnerText 'Instead of going through a for loop, just request the attribute directly
        Dim FNext As System.Xml.XmlNode
        Dim x As Integer = 1
        For Each FNext In Fnodes
            If FNext.Name = "day" Then
                x = FNext.Attributes("d").InnerText '+ 1 if you want to x to be 1 when the day is today.
                Fnode = FNext.SelectSingleNode("hi")
                Select Case x 'Changed the if statments to a select
                    Case 1
                        Day1HighTemp.Text = Fnode.InnerText
                    Case 2
                        Day2HighTemp.Text = Fnode.InnerText
                    Case 3
                        Day3HighTemp.Text = Fnode.InnerText
                    Case 4
                        Day4HighTemp.Text = Fnode.InnerText
                End Select
                Fnode = FNext.SelectSingleNode("low")
                Select Case x
                    Case 1
                        Day1LowTemp.Text = Fnode.InnerText
                    Case 2
                        Day2LowTemp.Text = Fnode.InnerText
                    Case 3
                        Day3LowTemp.Text = Fnode.InnerText
                    Case 4
                        Day4LowTemp.Text = Fnode.InnerText
                End Select
            End If
        Next FNext
As you can see I edited quite a lot, but I tried to comment most of the edits I made.
 
Wow, thank you. That works. Actually, I didn't need to use your one comment about using +1 when the day is 0. It actually started on day 1 (which is what I wanted anyway), and I'm not really sure why, especially since you have this line:
VB.NET:
[SIZE=2]x = FNext.Attributes([/SIZE][SIZE=2][COLOR=#800000]"d"[/COLOR][/SIZE][SIZE=2]).InnerText [/SIZE][SIZE=2][COLOR=#008000]'+ 1 if you want to x to be 1 when the day is today.[/COLOR][/SIZE]
I'd think that would make it use day 0 since you set x equal to the value of that first attribute. I still need to fix the Day1Label line though. I left that there because I was just testing something. That's still showing the day 0 date, and I also have a label for each date, so I need to work that out. Thanks for your help. I really appreciate it, since I was really stuck on this one.

I had another question posted, but I fixed it. Thanks again for your help. :)
 
Last edited:
I'm still not sure about working with attributes. I'm having a problem getting the right icon number for each day from the XML. Here's a small piece.
VB.NET:
[SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]day[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]d[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff]1[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#ff0000]t[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff]Wednesday[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#ff0000]dt[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff]Feb 22[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff]>
<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]hi[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE][SIZE=2]59[/SIZE][SIZE=2][COLOR=#0000ff]</[/COLOR][/SIZE][SIZE=2][COLOR=#800000]hi[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>
<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]low[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE][SIZE=2]45[/SIZE][SIZE=2][COLOR=#0000ff]</[/COLOR][/SIZE][SIZE=2][COLOR=#800000]low[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>
<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]sunr[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE][SIZE=2]7:17 AM[/SIZE][SIZE=2][COLOR=#0000ff]</[/COLOR][/SIZE][SIZE=2][COLOR=#800000]sunr[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>
<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]suns[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE][SIZE=2]6:31 PM[/SIZE][SIZE=2][COLOR=#0000ff]</[/COLOR][/SIZE][SIZE=2][COLOR=#800000]suns[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>
<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]part[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]p[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff]d[/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff]>
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]icon[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE][SIZE=2]12[/SIZE][SIZE=2][COLOR=#0000ff]</[/COLOR][/SIZE][SIZE=2][COLOR=#800000]icon[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>
[/COLOR][/SIZE][code]
 
I need that icon value, and as you can see, it has to be for the right day, and I need to specify that "part p = d", because there are two part p sections in each day. Thanks.
I tried this code, but it didn't work.
[code]
[SIZE=2]Fnode = Fxml.SelectSingleNode([/SIZE][SIZE=2][COLOR=#800000]"/weather/dayf/day/part/icon"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] x
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 1
Day1Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 2
Day2Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 3
Day3Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 4
Day4Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]


I've got half of it working. I can get to the icon, but it's starting at day 0. Here's what I have
VB.NET:
[SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2][COLOR=#000000] x[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 1
Day1LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 2
Day2LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 3
Day3LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 4
Day4LowTemp.Text = Fnode.InnerText
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Select
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] DayIcon [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlNode = Fxml.SelectSingleNode([/SIZE][SIZE=2][COLOR=#800000]"/weather/dayf/day/part/icon"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] y = [/SIZE][SIZE=2][COLOR=#800000]"d"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Day1Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + DayIcon.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
Last edited:
The problem with your code is that you are not specifying which day or part. Using the code I posted previously, you could add this right after the select statements:
VB.NET:
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] Fnode2 [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] FNext.SelectNodes([/SIZE][SIZE=2][COLOR=#800000]"part"[/COLOR][/SIZE][SIZE=2])[SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000]'Starting from the day node, select each node in the part node
[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Fnode2.Attributes([/SIZE][SIZE=2][COLOR=#800000]"p"[/COLOR][/SIZE][SIZE=2]).InnerText = [/SIZE][SIZE=2][COLOR=#800000]"d"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000]'Check if the attribute in the part node is "d"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select [SIZE=2]Case[/SIZE][/COLOR][SIZE=2] Fnode2.SelectSingleNode([SIZE=2][COLOR=#800000]"icon"[/COLOR][/SIZE][SIZE=2]).InnerText [SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000]'Get the icon value from the part node[/COLOR][/SIZE][/SIZE]
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 1
Day1Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 2
Day2Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 3
Day3Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 4
Day4Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE]
You also have to create a variable Fnode2 before the for loop:
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Fnode2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Xml.XmlNode
[/SIZE]
Hope this helps :)

BTW, the comment about the +1 was there in case you wanted to include today's temperature as well.
 
In this line"
VB.NET:
[SIZE=2]Day1Pic.Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + Fnode.InnerText + [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]
[/SIZE]
Should that be Fnode2? I ran it both ways, and it didn't put any icons in the boxes. Not sure if I did something wrong or not.
 
You can also access an icon node directly by specifying which nodes/attributes to use in the xpath expression. (refer post 15)
As for your question:
VB.NET:
/weather/dayf/day/part/icon
is the same as:
VB.NET:
/weather/dayf/day[0]/part[0]/icon
as you would want this for daytime day 1 (day 0 is current day):
VB.NET:
/weather/dayf/day[@d='1']/part[@p='d']/icon
and this for nighttime day 1:
VB.NET:
/weather/dayf/day[@d='1']/part[@p='n']/icon
since relativity is the key to xml, you rarely hardcode such a full path from root node, but take it from where you are when getting the different parts of data, for instance when iterating the day nodes you already got a reference to a 'daynode' and want the 'icon' childnode of its 'part' childnode where attribute 'p' is 'n' or 'd', so you just query something like this:
VB.NET:
Dim IconString As String = daynode.SelectSingleNode("part[@p='d']/icon").InnerText

http://www.w3schools.com/xpath/default.asp
 
My mistake, rushed the code a bit too much, I got confused with the select statment. Tell me if this code works, it should (I hope):
VB.NET:
Select Case x
'Get the day Here's where I went wrong
Case 1
Day1Pic.Image = Image.FromFile("..\..\32\" + Fnode2.SelectSingleNode("icon").InnerText + ".jpg")
'Just continue the replacing it down here

Alternatively, you could asign the Fnode2.SelectSingleNode("icon").InnerText value to a string to make the code slightly smaller.
VB.NET:
dim iconnum as string
...
For ...
...
iconnum = Fnode2.SelectSingleNode([SIZE=2][COLOR=#800000]"icon"[/COLOR][/SIZE][SIZE=2]).InnerText[/SIZE]
Select Case x
...
Day1Pic.Image = Image.FromFile([SIZE=2][COLOR=#800000]"..\..\32\"[/COLOR][/SIZE][SIZE=2] + iconnum+ [/SIZE][SIZE=2][COLOR=#800000]".jpg"[/COLOR][/SIZE][SIZE=2])[/SIZE]

Didn't realise you could use xpath in that fashion to specify the attributes, so that would make coding easier, if you only wanted the day icon, instead of both.
 
Thanks for your help. I got it working now. I have a tool strip drop down menu for each zip code they want to add to their favorites and I'm trying to add the functionality to a "delete favorite" button. I've been looking into it, and There's a ToolStripMenuItem.Add, but there isn't a remove. Any ideas on how I'd do that? I am also saving their favorite zip codes in My.Settings as they add them, and I'm not totally sure that my method for deleting from there will work either. It says you have to reference the items on the list by number, as if they're in some kind of array, but I don't know how to do that, since I don't know what zip codes they'll have and in what order. Here's the code for something I tried. Not sure if this will do it.
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] DeleteFavLocation_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] DeleteFavLocation.Click
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ZIP.Text <> [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipOne = ZIP.Text [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] DelFindOne [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Array = ChooseFavLocation.DropDownItems.Find([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipOne, 1)
[/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipOne = [/SIZE][SIZE=2][COLOR=#800000]""
[/COLOR][/SIZE][SIZE=2]ChooseFavLocation.DropDownItems.Remove(DelFindOne(1))
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipTwo = ZIP.Text [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] DelFindTwo [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Array = ChooseFavLocation.DropDownItems.Find([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipTwo, 1)
[/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipTwo = [/SIZE][SIZE=2][COLOR=#800000]""
[/COLOR][/SIZE][SIZE=2]ChooseFavLocation.DropDownItems.Remove(DelFindTwo(1))
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipThree = ZIP.Text [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] DelFindThree [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Array = ChooseFavLocation.DropDownItems.Find([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipThree, 1)
[/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.FavoriteZipThree = [/SIZE][SIZE=2][COLOR=#800000]""
[/COLOR][/SIZE][SIZE=2]ChooseFavLocation.DropDownItems.Remove(DelFindThree(1))
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
Back
Top