Results 1 to 8 of 8

Thread: Read XML file into combo box....

  1. #1

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    Read XML file into combo box....

    <?xml version="1.0"?>
    <chimaera>
    <servers>
    <host ip="172.16.1.30">Chimaera</host>
    <host ip="172.16.1.31">MySQL1</host>
    <host ip="172.16.1.32">Ares</host>
    </servers>
    </chimaera>

    How can I read the above xml file into a combobox with the server names?

    While myXML.Read
    If XmlNodeType.Element Then
    If myXML.Name = "hosts" Then
    myXML.MoveToAttribute("ip")
    MsgBox(myXML.ReadAttributeValue)
    End If
    End If
    End While

    this is what i have but it won't work. i'm trying to read the attribute "IP"

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Dim ds As New DataSet
    2.         ds.ReadXml("..\xmlfile1.xml")
    3.         ComboBox1.DisplayMember = "host_Text"
    4.         ComboBox1.DataSource = ds.Tables("host")

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Or if you don't want to use databinding or like the XMLDocument object better then:
    VB Code:
    1. Dim dom As New Xml.XmlDocument
    2.         dom.Load("..\xmlfile1.xml")
    3.         ComboBox1.Items.Clear()
    4.         For Each node As Xml.XmlNode In dom.SelectNodes("//chimaera/servers/host")
    5.             ComboBox1.Items.Add(node.InnerText)
    6.         Next

  4. #4

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    thanks

    thank you. that sure cut down on a lot of code! do you have any links or tutorials more info regarding xml and vb.net? thanks. code works great btw.

  5. #5

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    attributes

    Dim myAttr As XmlAttribute
    For Each myAttr In myDoc.SelectNodes("/chimaera/servers/host")
    MsgBox(myAttr.InnerText)
    Next

    can you use something like that to get the attributes? such as the ip?

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sorry I don't have any links off the top of my head, but a search for for xml and vb.net might work. Or you want to learn more about using the xmldocument and SelectNodes then check the help and google for xpath or xquery. You can do some cool queries in an xml file.

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sure, you can use the @ to note an attribute:
    VB Code:
    1. Dim myAttr As Xml.XmlAttribute
    2.         For Each myAttr In myDoc.SelectNodes("/chimaera/servers/host/@ip")
    3.             MsgBox(myAttr.InnerText)
    4.         Next

  8. #8

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    thank you

    Thank you.

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