Results 1 to 6 of 6

Thread: [RESOLVED] XML string help

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2012
    Posts
    51

    Resolved [RESOLVED] XML string help

    (Using the url http://weather.yahooapis.com/forecastrss?w=2459115)
    For the XML I can easily display the "ttl" element into a label, but for the

    Code:
    <yweather:forecast day="Mon" date="28 Apr 2014" low="49" high="61" text="Showers Late" code="45"/>
    ,

    I can't figure out how to separate the Monday, monday's low, and and Monday's high, ext., into multiple labels.
    Any help? I'm using the code below to get the current temp and stuff.

    Code:
    Dim wc As New WebClient
            Dim mytext As String
    
            mytext = wc.DownloadString("http://weather.yahooapis.com/forecastrss?w=2459115")
    
            Dim mt As New Xml.XmlDocument
            mt.LoadXml(mytext)
    
            Dim rr As Xml.XmlNodeList = mt.GetElementsByTagName("ttl")
    
            For Each ee As Xml.XmlElement In rr
                MsgBox(ee.InnerText)
            Next
    Thank you very much!
    Last edited by jj103; Apr 28th, 2014 at 08:24 PM. Reason: Turns out ttl isn't the current temp...duh...

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: XML string help

    this is the simplest way I can think of. in the code, I removed the namespace:

    Code:
    Dim xml As XElement = XElement.Parse("<yweather:forecast day=""Mon"" date=""28 Apr 2014"" low=""49"" high=""61"" text=""Showers Late"" code=""45""/>".Replace("yweather:", ""))
    Label1.Text = xml.@day
    Label2.Text = xml.@date
    Label3.Text = xml.@low
    Label4.Text = xml.@high
    Label5.Text = xml.@text
    Label6.Text = xml.@code

  3. #3
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    Re: XML string help

    or as i said last time have a look at what I gave you

    Code:
    Dim tt As Xml.XmlNodeList = mt.GetElementsByTagName("yweather:forecast")
    For Each ee As Xml.XmlElement In tt
    MsgBox(ee.GetAttribute("day").ToString) 'can get day or any of the others by their name
    Next
    My CodeBank Submissions
    • Listbox with transparency and picture support - Click Here
    • Check for a true internet connection - Click Here
    • Open Cash drawer connected to receipt printer - Click Here
    • Custom color and size border around form - Click Here
    • Upload file to website without user logins, includes PHP - Click Here
    • List All Removable USB Storage Devices - Click Here
    • Custom On/Off Slide Control - Click Here
    • Insert multiple rows of data into one database table using parameters - Click Here
    • Trigger USB/Serial Cash Drawer - Click Here

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2012
    Posts
    51

    Re: XML string help

    Thank you!
    But the problem with that is when I set it to a label it just displays the last one, and on the message box it just floods me with messageboxs. Any suggestions?

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2012
    Posts
    51

    Re: XML string help

    Thank for the help!
    But the issue with that is it's just using that particular string. I need it to download the xml from the source and break up the different days.
    Perhaps I'd have it go through and get the specific line of code (like in numbers, line 1 being the top line of code going down)?
    Any suggestions?

  6. #6
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    Re: XML string help

    well this would depend on how you want to display it, if in a listbox with days then easy but into a label like the below is easy

    Code:
    Dim tt As Xml.XmlNodeList = mt.GetElementsByTagName("yweather:forecast")
    For Each ee As Xml.XmlElement In tt
    if ee.GetAttribute("day").ToString ="Mon" then
    label1.text = ee.GetAttribute("day").ToString
    end if
    'MsgBox(ee.GetAttribute("day").ToString) 'can get day or any of the others by their name
    Next
    or if adding to a listbox

    Code:
    Dim tt As Xml.XmlNodeList = mt.GetElementsByTagName("yweather:forecast")
            For Each ee As Xml.XmlElement In tt
                ListBox1.Items.Add(ee.GetAttribute("day").ToString & " " & ee.GetAttribute("date").ToString & " Low: " & ee.GetAttribute("low").ToString & " High: " & ee.GetAttribute("high").ToString & " Text: " & ee.GetAttribute("text").ToString)
            Next
    my listbox isnt pretty but gets all data like so:

    Name:  Capture.jpg
Views: 190
Size:  23.6 KB
    My CodeBank Submissions
    • Listbox with transparency and picture support - Click Here
    • Check for a true internet connection - Click Here
    • Open Cash drawer connected to receipt printer - Click Here
    • Custom color and size border around form - Click Here
    • Upload file to website without user logins, includes PHP - Click Here
    • List All Removable USB Storage Devices - Click Here
    • Custom On/Off Slide Control - Click Here
    • Insert multiple rows of data into one database table using parameters - Click Here
    • Trigger USB/Serial Cash Drawer - Click Here

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width