首页/技术开发/内容

asp+ 运用数据绑定来处理XML文件

技术开发2024-01-29 阅读()
/*
豆腐制作 都是精品
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>
<element name="content" type="string" minOccurs="0" maxoccurs="1"></element>
</complexType>
</element>
</schema>

<allsite>
<sites>
<url>http://www.asp888.net</url>
<site>豆腐</site>
<content>豆腐制作 都是精品</content>
</sites>
</allsite>

</root>

作者:豆腐




……

相关阅读