In this article I will explain with an example, how to read (parse) XML from URL in ASP.Net using C# and VB.Net.
The XML will be first downloaded from an URL using WebClient class and then will be converted to DataSet.
Finally, the DataSet will be used to populate the GridView control in ASP.Net using C# and VB.Net.
ASPSnippets Test API
The following URL will be used in this article.
The URL returns the following XML.
<?xml version="1.0" standalone="yes"?>
       <Name>John Hammond</Name>
       <Country>United States</Country>
       <Name>Mudassar Khan</Name>
       <Name>Suzanne Mathews</Name>
       <Name>Robert Schidner</Name>
HTML Markup
The following HTML Markup consists of an ASP.Net GridView control.
<asp:GridView ID="gvCustomers" runat="server"></asp:GridView>
You will need to import the following namespaces.
using System.Net;
using System.Data;
using System.IO;
Imports System.Net
Imports System.Data
Imports System.IO
Reading (Parsing) XML from URL in ASP.Net
Inside the Page Load event handler, first the contents of XML file are downloaded from an URL using DownloadString method of the WebClient class.
Then, the XML string is read using StringReader class and converted to DataSet using ReadXml method.
Finally, the DataSet is used to populate the GridView control in ASP.Net using C# and VB.Net.
protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        string xml = (new WebClient()).DownloadString("");
        using (DataSet ds = new DataSet())
            using (StringReader sr = new StringReader(xml))
                gvCustomers.DataSource = ds;
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) HandlesMe.Load
    If NotMe.IsPostBack Then
        ServicePointManager.Expect100Continue = True
        ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
        Dim xml As String = (New WebClient()).DownloadString("")
        Using ds As DataSet = New DataSet()
            Using sr As StringReader = New StringReader(xml)
                gvCustomers.DataSource = ds
            End Using
        End Using
    End If
End Sub
Read (Parse) XML from URL in ASP.Net using C# and VB.Net