Asp.net|xml
ASP.net 2.0 provides a variety of data sources, in general, the XmlDataSource control uses an XML file, and the following example is a method of data binding using a XmlDocument object.
Vb. NET code
<%@ Page language= "VB"%>
<script runat= "Server" >
Protected Sub Page_Load (ByVal sender as Object, ByVal e as System.EventArgs)
Dim Doc as New System.Xml.XmlDocument
Doc. Load ("http://dotnet.aspx.cc/Rss.aspx")
Xmldatasource1.data = doc. InnerXml
Xmldatasource1.xpath = "/rss/channel/item"
End Sub
</script>
<body>
<form id= "Form1" runat= "Server" >
<asp:gridview id= "GridView1" runat= "Server" datasourceid= "XmlDataSource1" autogeneratecolumns= "false" >
<Columns>
<asp:templatefield headertext= "article title" >
<ItemTemplate>
<asp:hyperlink runat= "Server" target= "_blank" navigateurl= ' <% #XPath ("link")%> ' >
<% #XPath ("title")%></asp:hyperlink>
[<% #CType (XPath ("pubdate"), DateTime). ToString ("yyyy m-month D-day")%>]
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:xmldatasource id= "XmlDataSource1" runat= "Server" ></asp:XmlDataSource>
</form>
</body>
C # code
<%@ Page language= "C #" autoeventwireup= "true"%>
<script runat= "Server" >
protected void Page_Load (object sender, System.EventArgs e)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument ();
Doc. Load ("http://dotnet.aspx.cc/Rss.aspx");
Xmldatasource1.data = doc. INNERXML;
Xmldatasource1.xpath = "/rss/channel/item";
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<asp:gridview id= "GridView1" runat= "Server" datasourceid= "XmlDataSource1" autogeneratecolumns= "false" >
<Columns>
<asp:templatefield headertext= "article title" >
<ItemTemplate>
<asp:hyperlink id= "HyperLink1" runat= "server" target= "_blank" navigateurl= ' <% #XPath ("link")%> ' >
<% #XPath ("title")%></asp:hyperlink>
[<%# (DateTime.Parse (XPath ("pubdate"). ToString (). Replace ("GMT", "")). ToString ("yyyy m-month D-day")%>]
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:xmldatasource id= "XmlDataSource1" runat= "Server" ></asp:XmlDataSource>
</form>
</body>