Firstly let me confess that I've only used XML with java sax parsers
My instincts tell me that looping within the same loop doesn't seem quite right...
especially if there is only expected to be one firstname and one lastname per person.
I would have thought holding the strings in a couple of variables would be betterCode:For Each Child2 In Child.childNodes If Child2.nodeName = "LastName" And Child2.Text = TextLastName Then For Each Child3 In Child.childNodes If Child3.nodeName = "FirstName" Then ListFirstName.AddItem Child3.Text End If Next Child3 End If Next Child2
Code:Dim lastname As String Dim firstname As String For Each Child In xmlRoot.childNodes If Child.nodeName = "Person" Then For Each Child2 In Child.childNodes If Child2.nodeName = "LastName" Then lastname = Child2.Text End If If Child2.nodeName = "FirstName" Then firstname = Child2.Text End If Next Child2 If lastname = TextLastName Then ListFirstName.AddItem firstname End If lastname = "": firstname = "" Else MsgBox "Node name: " & Child.nodeName, , "Non person!" End If Next Child




Reply With Quote