嘿,我剛剛在VB.net上解析XML。這是我使用解析XML文件,我的代碼:VB.NET XML解析器循環
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))
'reader.ReadStartElement("ip_list")
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)
reader.ReadEndElement()
Loop
reader.Close()
End Using
我把自己do until reader.EOF
但它似乎並沒有工作。在第一次出現後,它會一直給出錯誤。我肯定錯過了什麼?
大衛
你會得到什麼錯誤? – SLaks 2010-05-24 16:43:28