可能是简单的问题,但我自己无法解决。我得到的xml包含很多节点,我想得到的只是那些节点元素是" equipment.FanTray"的节点。问题是它首先进行,然后进入第3,然后进入第5,依此类推......
equipment.FanTray <----found
equipment.FanTray
equipment.FanTray <----found
equipment.FanTray
equipment.FanTray <----found
equipment.FanTray
equipment.FanTray <----found
equipment.FanTray
equipment.FanTray <----found
我的代码很简单:
Dim reader As Xml.XmlTextReader = New Xml.XmlTextReader("C:\Users\user\Desktop\ifile.xml")
Dim myList As New List(Of String)
While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element
If reader.Name = "equipment.FanTray" And reader.IsStartElement Then
Console.WriteLine(reader.ReadOuterXml())
End If
End Select
End While
答案 0 :(得分:1)
对我来说很好看。你只用1 Select Case
怎么样?
那是Select Case
;)
Dim reader As Xml.XmlTextReader = New Xml.XmlTextReader("C:\Users\user\Desktop\ifile.xml")
Dim myList As New List(Of String)
While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'Display beginning of element.
If reader.Name = "equipment.FanTray" And reader.IsStartElement Then
Console.WriteLine(reader.ReadOuterXml())
End If
End Select
End While