Using data binding to process XML files in asp.net

Source: Internet
Author: User
Tags object net string xmlns
asp.net|xml| Data guide: In the ASP.net through the DataSet object binding processing XML file method, with source code
----------------------------------------------------------
*
Tofu production is a boutique
Http://www.asp888.net Tofu Technology Station
If reproduced please retain the copyright information
*/
Test.aspx is the main run program Site.xml is an XML file that contains data

<%@ Import namespace= "System.IO"%>
<%@ Import namespace= "System.Data"%>

<script language= "VB" runat= "Server" >
Sub Page_Load (Src as Object, E as EventArgs)
' Http://www.asp888.net
Dim DS as New DataSet
Dim FS as FileStream
Dim Reader as StreamReader

FS = New FileStream (Server.MapPath ("Site.xml"), FileMode.Open,FileAccess.Read)
Reader = New StreamReader (FS)
Ds. READXML (Reader)
Fs. Close ()
Dim Source as DataView
Source = new DataView (ds. Tables (0))
Mydatagrid.datasource = Source
Mydatagrid.databind ()
End Sub
</script>

<body>


<asp:datagrid id= "Mydatagrid" runat= "Server"
Width= "800"
Bordercolor= "BLACK"
Showfooter= "false"
Cellpadding=3
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
>
<property name= "Columns" >
<asp:hyperlinkcolumn
datanavigateurlfield= "url"
DATANAVIGATEURLFORMATSTRING={0}
text= "Visit!"
/>
</property>
</ASP:DataGrid>


</body>

Contents of Site.xml File

<root>
<schema id= "Allsite" targetnamespace= "xmlns=" Http://www.w3.org/1999/XMLSchema "xmlns:xdo=" urn: Schemas-microsoft-com:xml-xdo "xdo:datasetname=" Books ">
<element name= "Sites" >
<complextype content= "Elementonly" >
<element name= "url" type= "string" minoccurs= "1" allownull= "" ></element>
<element name= "Site" type= "string" minoccurs= "1" ></element>
<element name= "Content" type= "string" minoccurs= "0" maxoccurs= "1" ></element>
</complexType>
</element>
</schema>

<allsite>
<sites>
<url>http://www.asp888.net</url>
<site> Tofu </site>
<content> tofu production are fine </content>
</sites>
</allsite>

</root>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.