这是您可以查看的两个示例。如果你真的不想使用 LINQ,那么你需要学习 XPath。
Sub Main()
'This method uses the Xml DOM in the System.Xml namespace with XPath
Dim xmlDoc = New XmlDocument()
xmlDoc.Load("c:\test\test.xml")
Dim membersNode As XmlNode = xmlDoc.DocumentElement.SelectSingleNode("/Tabel/Members")
If membersNode IsNot Nothing Then
Dim memberWithKDof10 As XmlNode = membersNode.SelectSingleNode("Member[KD = '10']")
If memberWithKDof10 IsNot Nothing Then
Console.WriteLine("Name of player with KD of 10 is {0}", memberWithKDof10.SelectSingleNode("Naam").InnerText)
Else
Console.WriteLine("Player not found!")
End If
End If
'This method uses the XDocument classes found in the System.Xml.Linq namespace
Dim xDoc As XDocument = XDocument.Load("c:\test\test.xml", LoadOptions.None)
Dim membersElement As XElement = xDoc.Root.Element("Members")
If membersElement IsNot Nothing Then
Dim memberWithKDof10 As XElement = membersElement.Descendants("Member").FirstOrDefault(Function(e) e.Element("KD").Value = "10")
If memberWithKDof10 IsNot Nothing Then
Console.WriteLine("Name of player with KD of 10 is {0}", memberWithKDof10.Element("Naam").Value)
Else
Console.WriteLine("Player not found!")
End If
End If
Console.WriteLine()
Console.WriteLine("Press ENTER to exit...")
Console.ReadLine()
End Sub