VB.net XML Parser loop
- by StealthRT
Hey all i am new to XML parsing on VB.net. This is the code i am using to parse an XML file i have:
Dim output As StringBuilder = New StringBuilder()
Dim xmlString As String = _
"<ip_list>" & _
"<ip>" & _
"<ip>192.168.1.1</ip>" & _
"<ping>9 ms</ping>" & _
"<hostname>N/A</hostname>" & _
"</ip>" & _
"<ip>" & _
"<ip>192.168.1.6</ip>" & _
"<ping>0 ms</ping>" & _
"<hostname>N/A</hostname>" & _
"</ip>" & _
"</ip_list>"
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
Do Until reader.EOF
reader.ReadStartElement("ip_list")
reader.ReadStartElement("ip")
reader.ReadStartElement("ip")
reader.MoveToFirstAttribute()
Dim theIP As String = reader.Value.ToString
reader.ReadToFollowing("ping")
Dim thePing As String = reader.ReadElementContentAsString().ToString
reader.ReadToFollowing("hostname")
Dim theHN As String = reader.ReadElementContentAsString().ToString
MsgBox(theIP & " " & thePing & " " & theHN)
Loop
End Using
I put the "do until reader.EOF" myself but it does not seem to work. It keeps giving an error after the first go around. I must be missing something?
David