2014-02-20 64 views
0

嗨,我有在網絡上一個XML文件,我想湊它來獲得相關信息HTMLagility包 - 讀取XML頁面

<M MId="1195772" LId="34923" _LId="34921" OId="569" SId="5" KId="122" LNr="2" C0="1392715800" ML="1" HId="13106" GId="5996" W="" HN="Musfat Banyas" GN="Omyyah Idlib" HRC="" HRCi="1" GRC="" GRCi="0" Info="" S1="1-1" S2="1-0" MStan="1" OTv="" L="0" A="3" Ao="11"/> 

我想湊每個M和獲得HN的價值GN S1 S2

我曾嘗試使用下面的代碼嘗試,但我沒有得到任何值返回

Imports System.Net 
Imports System.IO 
Imports System.Xml 
Imports HtmlAgilityPack 


Partial Class Grayhounds_home 
    Inherits System.Web.UI.Page 
    ' Gettodaysmatches(cominguptable, "https://www.betfair.com/sport/football?selectedTabType=TODAY", ".//div[contains(@class, 'match event-information ui-event')]", ".//span[@class='home-team-name']", ".//span[@class='away-team-name']", ".//span[@class='ui-no-score']") 

    Private Sub Grayhounds_home_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     Dim webGet As New HtmlWeb() 'open the system 
     Dim htmlDoc As HtmlDocument = webGet.Load("http://www.futbol24.com/matchDayXml/?Day=20140218") '' get the html from the webpage 
     Dim coll As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//m") 
     If coll IsNot Nothing Then 
      For Each div As Object In coll ' select all the divs wi 
      test.Text = div.Attributes("HN").Value 
      Next 
     End If 
    End Sub 
End Class 

回答

0

您解析XML文件,通過使用.NET更好的選擇,內置類:XDocumentXmlDocument。例如,使用XmlDocument

Dim doc As New XmlDocument 
doc.Load("http://www.futbol24.com/matchDayXml/?Day=20140218") 
Dim coll = doc.SelectNodes("//M") 
For Each M As XmlNode In coll 
    test.Text = M.Attributes("HN").Value 
Next 
+1

這很棒甚至不知道這存在! –