Imports System.Xml
Public Class frmXMLExample
Inherits System.Windows.Forms.Form
Private Structure ComboItem
Public Text As String
Public Value As Object
Public Sub New(ByVal itemText As String, ByVal itemValue As Object)
Text = itemText
Value = itemValue
End Sub
Public Overrides Function ToString() As String
Return Text
End Function
End Structure
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(32, 32)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
Me.ComboBox1.TabIndex = 0
Me.ComboBox1.Text = "ComboBox1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(160, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "TextBox1"
'
'frmXMLExample
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 272)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.ComboBox1)
Me.Name = "frmXMLExample"
Me.Text = "frmXMLExample"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmXMLExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlDoc As New XmlDocument
Dim nodes As XmlNodeList
Dim node As XmlNode
Dim xmlString As String
xmlString = xmlString & "<XML>"
xmlString = xmlString & "<book section='newspaper'>"
xmlString = xmlString & "<new id='100'>China News</new>"
xmlString = xmlString & "<new id='101'>Street Paper</new>"
xmlString = xmlString & "<new id='0'>None</new>"
xmlString = xmlString & "</book>"
xmlString = xmlString & "</XML>"
xmlDoc.LoadXml(xmlString)
nodes = xmlDoc.DocumentElement.SelectNodes("book/new")
For Each node In nodes
ComboBox1.Items.Add(New ComboItem(node.InnerText, node.Attributes.GetNamedItem("id").InnerText))
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim item As ComboItem = ComboBox1.SelectedItem
TextBox1.Text = item.Value
End Sub
End Class