用c#处理xml文档
http://tech.ddvip.com 2007年10月05日 社区交流
内容摘要:本文章讲叙了怎样在c#里处理xml文档,都是些比较基本的。
==============================================
(3)把XML文档通过DataSet读入到Repeater中.
你也可把它读入到DataSet.原理是一样的.
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="C#" %>
<html>
<head>
<title>读入到Repeater</title>
<script language="C#" runat=server>
public void Page_Load(Object obj,EventArgs e)
{
string xpath="db/people.xml" ;
try
{
DataSet ds= new DataSet();
FileStream fs= new FileStream(Server.MapPath(xpath),FileMode.Open,FileAccess.Read,FileShare.ReadWrite) ;
ds.ReadXml(new StreamReader(fs));
fs.Close();
Trace.Warn("表记录数",Convert.ToString(ds.Tables[0].Rows.Count));
MyDataList.DataSource=ds.Tables[0].DefaultView;
MyDataList.DataBind();
}
catch (Exception ed)
{
Response.Write("<font color=#FF0000>"+ed.ToString()+"</font>") ;
}
}
</script>
</head>
<body >
<ASP:Repeater id="MyDataList" runat="server">
<headertemplate>
<h5> Viewer Details </h5>
</headertemplate>
<itemtemplate>
<br>
<table class="mainheads" width="60%" style="font: 8pt verdana" >
<tr style="background-color:#FFFFCC">
<td>name:</td>
<td><%# DataBinder.Eval(Container.DataItem, "name") %></td>
</tr>
<tr style="background-color:#FFFFCC">
<td>title:</td>
<td><%# DataBinder.Eval(Container.DataItem, "title")%></td>
</tr>
<tr style="background-color:#FFFFCC">
<td>title2:</td>
<td><%# DataBinder.Eval(Container.DataItem, "title2") %></td>
</tr>
</table><br>
</itemtemplate>
</ASP:Repeater>
</body>
</html>
责编:豆豆技术应用