-
[2008] XML Help
Ok I am trying to write a program that has a combolist box to drop down the rooms (shortened xml for example). Once you choose a room it will populate the second combolist box which contains the Serial Number1. When I choose a Serial Number I want it to populate textboxes of SID, User Name, CPU Name, MAC, and IP Address.
What I can't figure out is once I have the room and the serial number choosen how to get the rest from that specific selection?
I am using 2008 and can use linq but can't figure out how to do this.
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
xmldoc.Load(xmlPath)
GetLocationInfo()
End Sub
Private Sub GetRoomInfo()
root = xmldoc.FirstChild
If root.Value = "version=""1.0"" encoding=""utf-8""" Then
root = root.NextSibling
End If
If root.HasChildNodes Then
Dim i As Integer
For i = 0 To root.ChildNodes.Count - 1
'If Strings.InStr(root.ChildNodes(i).InnerText, machineName) <> 0 Then
Console.WriteLine(root.ChildNodes(i).Name)
LabLocation = root.ChildNodes(i).Name
cboLocation.Items.Add(root.ChildNodes(i).Name)
'AddText(logFile, "The Code Version was pulled from " & envVar)
'Exit For
'End If
Next
End If
End Sub
Private Sub cboLocation_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLocation.SelectedIndexChanged
Dim xmlNodeList As XmlNodeList
xmlNodeList = xmldoc.SelectNodes("/" & root.Name & "/" & cboLocation.SelectedItem & "/ws/SerialNum")
For Each xmln As XmlNode In xmldoc.SelectNodes("/" & root.Name & "/" & cboLocation.SelectedItem & "/ws/SerialNum")
Dim strSerialNum As String = Strings.Trim(xmln.FirstChild.InnerText)
strSerialNum = Strings.Replace(strSerialNum, vbCrLf, "")
cboSerialNum.Items.Add(strSerialNum)
'MessageBox.Show(strSerialNum)
Next
End Sub
Private Sub cboSerialNum_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSerialNum.SelectedIndexChanged
'THIS IS WHERE I NEED HELP.
End Sub
<WorkstationInfo>
<Room1>
<ws>
<SerialNum>SerialNum1</SerialNum>
<SID>SID1</SID>
<UserName>User Name1</UserName>
<CPUName>DTSerialNum1</CPUName>
<MAC>00-03-04-05-06-07</MAC>
<IPAddress>192.168.1.102</IPAddress>
</ws>
<ws>
<SerialNum>SerialNum2</SerialNum>
<SID>SID2</SID>
<UserName>User Name2</UserName>
<CPUName>DTSerialNum2</CPUName>
<MAC>00-02-03-04-05-06</MAC>
<IPAddress>192.168.1.103</IPAddress>
</ws>
<ws>
<SerialNum>SerialNum3</SerialNum>
<SID>SID3</SID>
<UserName>User Name3</UserName>
<CPUName>DTSerialNum3</CPUName>
<MAC>00-01-02-03-04-05</MAC>
<IPAddress>192.168.1.104</IPAddress>
</ws>
</Room1>
</WorkstationInfo>
-
Re: [2008] XML Help
I'm not sure if this will help you much, but instead of trying to go thru all the Xml by hand, I would simply define some classes that mimic the structure of the Xml. Then you can Deserialize that Xml right into a class and you can bind the classes to your dropdowns. Then it would just be a matter of searching thru your data to find the correct object.