VB.net XML Parser loop

Posted by StealthRT on Stack Overflow See other posts from Stack Overflow or by StealthRT
Published on 2010-05-24T16:35:38Z Indexed on 2010/05/24 16:51 UTC
Read the original article Hit count: 239

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about visual-studio-2008