|
-
Jul 2nd, 2003, 04:18 PM
#1
Thread Starter
Hyperactive Member
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"
-
Jul 2nd, 2003, 04:40 PM
#2
VB Code:
Dim ds As New DataSet
ds.ReadXml("..\xmlfile1.xml")
ComboBox1.DisplayMember = "host_Text"
ComboBox1.DataSource = ds.Tables("host")
-
Jul 2nd, 2003, 04:46 PM
#3
Or if you don't want to use databinding or like the XMLDocument object better then:
VB Code:
Dim dom As New Xml.XmlDocument
dom.Load("..\xmlfile1.xml")
ComboBox1.Items.Clear()
For Each node As Xml.XmlNode In dom.SelectNodes("//chimaera/servers/host")
ComboBox1.Items.Add(node.InnerText)
Next
-
Jul 2nd, 2003, 04:53 PM
#4
Thread Starter
Hyperactive Member
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.
-
Jul 2nd, 2003, 05:13 PM
#5
Thread Starter
Hyperactive Member
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?
-
Jul 2nd, 2003, 05:14 PM
#6
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.
-
Jul 2nd, 2003, 05:20 PM
#7
Sure, you can use the @ to note an attribute:
VB Code:
Dim myAttr As Xml.XmlAttribute
For Each myAttr In myDoc.SelectNodes("/chimaera/servers/host/@ip")
MsgBox(myAttr.InnerText)
Next
-
Jul 2nd, 2003, 05:35 PM
#8
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|