我第一次尝试使用 xpath 和剥离 xml,
我要做的就是让第一个节点显示在调试窗口中,这是我的代码。
' Create a WebRequest to the remote site
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://hatrafficinfo.dft.gov.uk/feeds/datex/England/CurrentRoadworks/content.xml")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
' Check if the response is OK (status code 200)
If response.StatusCode = System.Net.HttpStatusCode.OK Then
Dim stream As System.IO.Stream = response.GetResponseStream()
Dim reader As New System.IO.StreamReader(stream)
Dim contents As String = reader.ReadToEnd()
Dim document As New System.Xml.XmlDocument()
document.LoadXml(contents)
Dim node As System.Xml.XmlNode
For Each node In document
Debug.Print(node.SelectNodes("/situation").ToString())
Next node
Else
Throw New Exception("Could not retrieve document from the URL, response code: " & response.StatusCode)
End If
感谢任何人都可以提供的任何帮助!!!
这是 xml doument 的开始
<d2LogicalModel modelBaseVersion="1.0">
<exchange>
<supplierIdentification>
<country>gb</country>
<nationalIdentifier>NTCC</nationalIdentifier>
</supplierIdentification>
</exchange><payloadPublication xsi:type="SituationPublication" lang="en"> <publicationTime>2013-09-27T16:09:02+01:00</publicationTime>
国标