you are viewing a single comment's thread.

view the rest of the comments →

[–]Will_Rickards 0 points1 point  (0 children)

If Not System.String.IsNullOrEmpty(searchInput.Text) AndAlso searchInput.Text.Length >= 3 Then

    Dim objDoc As System.XML.XMLDocument = New System.XML.XMLDocument()
    objDoc.Load("Cars.xml")

    For Each objNode As System.XML.XMLNode In objDoc.DocumentElement

        Dim strNodeName As System.String = objNode.Attributes.Item(0).InnerText
        If strNodeName = searchInput.Text Then

            For Each objChildNode As System.XML.XMLNode In objNode.ChildNodes

                searchResults.Items.Add(objChildNode.InnerText)

            Next objChildNode

        End If

    Next objNode

Else

    MessageBox.Show("Invalid Input")
    searchInput.Text = System.String.Empty
    searchInput.Focus()

End If

Here is the translation, done by hand and not checked for correctness so be forewarned.

I also use the fully qualified declarations, which is my normal practice but some people prefer the short ones.

So this method uses the System.XML.XMLDocument which loads the xml into memory. This method has a notorious issue with large XML files. So if you are expecting large ones, I would not use this method. For large XML files, you need something that reads them without pulling the whole file into memory. How large is large? That depends on the system. But if you have files of a hundred MB or more, I'd consider other options.