1。读取xml文件,并且采用数据绑定控件(datalist、gridview、repeater) 或者 采用 树形控件 显示
前台:
用表显示:<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<asp:GridViewID="GridView2"runat="server">
</asp:GridView>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
<asp:GridViewID="GridView3"runat="server">
</asp:GridView>
<br/>
树形显示<br/>
<asp:LabelID="Label4"runat="server"Text="Label"></asp:Label>
2。后台文件
DataSetds=newDataSet();
ds.ReadXml(MapPath("RecipeList.xml"));
//如果以表显示XML,则用DataSet
Label1.Text=ds.Tables[0].TableName;
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
Label2.Text=ds.Tables[1].TableName;
GridView2.DataSource=ds.Tables[1];
GridView2.DataBind();
Label3.Text=ds.Tables[2].TableName;
GridView3.DataSource=ds.Tables[2];
GridView3.DataBind();
//如果用树显示DataSet,则选用xmlDataDocument
XmlDataDocumentxdd=newXmlDataDocument(ds);
XmlNodeListrecipes=xdd.GetElementsByTagName("Ingredient");
foreach(XmlNoderecipeinrecipes)
...{
Label4.Text+=recipe.InnerText+"<br/>";
}
xml文件
<?xmlversion="1.0"encoding="utf-8"?>
<RecipeList>
<Recipe>
<Name>FrechToast</Name>
<Ingredients>
<Ingredient>Bread</Ingredient>
<Ingredient>Butter</Ingredient>
<Ingredient>Sugar</Ingredient>
</Ingredients>
</Recipe>
<Recipe>
<Name>TomatoSoup</Name>
<Ingredients>
<Ingredient>Tomatoes</Ingredient>
<Ingredient>Water</Ingredient>
</Ingredients>
</Recipe>
</RecipeList>
2213

被折叠的 条评论
为什么被折叠?



