2015-05-21 123 views
0

可能很簡單的問題,但我無法自己解決它。我得到了包含很多節點的xml,我想要的只是那些節點元素是「equipment.FanTray」的節點。問題是其採取先接下來到了第三個則進入第五等..XmlTextReader跳過每個下一個節點

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 

回答

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 
+0

我使用的只有一個 - 我粘貼不正確的 - 現在我更正,但相同的行爲也需要總是跳過下一個和跳躍到+ 1進一步 –

相關問題