導 讀:在中ASP.Net通過DataSet對象的綁定處理XML文件方法,附源代碼
----------------------------------------------------------
*
豆腐制作 都是精品
http://www.ASP888.Net 豆腐技術站
如轉載 請保留版權信息
*/
test.ASPx 是主運行程序 site.xml 是包含有數據的XML 文件
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<Html>
<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>
<h3><font face="Verdana">技術站點一覽</font> <span runat="server" id="MySpan"/></h3>
<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="參觀!"
/>
</property>
</ASP:DataGrid>
</body>
</Html>
site.XML 文件的內容
<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>