我需要创建一个应用程序,其中vb.net应用程序从URL中获取XML文件并将其显示在我的程序中。获取网址的地方的示例是www.example.com/yx3234.xml,然后获取此内容并将其读入我的程序。
答案 0 :(得分:2)
使用Linq XML
。您可以将uri传递给XDocument.Load()
方法。
Dim doc As XDocument
doc = XDocument.Load("http://dl.dropbox.com/u/8842115/sample.xml")
For Each node In doc.Descendants("first")
Console.WriteLine(CType(node.Element("no"), String))
Next
答案 1 :(得分:0)
以下是一个示例,向您展示如何从Internet下载网页到Vb.Net程序中的字符串。您需要创建一个新的WebClient类实例,然后将要下载的URL指定为DownloadString方法的参数,该方法将返回包含HTML源(或您的XML)的字符串。如果未指定accept-encoding,则服务器通常返回纯文本字符串。
Imports System
Imports System.Net
Class Program
Private Shared Sub Main()
' Create web client.
Dim client As New WebClient()
' Download string.
Dim value As String = client.DownloadString("http://battless59.evony.com/default.html?logfile/20111121/4c/6b/4c6b0c2f1ca16b8dbdf971154741dd4c.xml")
' Write values.
Console.WriteLine("--- WebClient result ---")
Console.WriteLine(value.Length)
Console.WriteLine(value)
End Sub
End Class