如何在asp.net中显示xml数据
这是我的xml文件:如何在asp.net中显示xml数据,asp.net,xml,data-representation,Asp.net,Xml,Data Representation,这是我的xml文件: <?xml version="1.0" encoding="utf-8"?> <entry> <comment Name="xxx" Location="India" Email="xxx@email.com" Gender="Male" /> <comment Name="yyy" Location="usa" Email="yyy@email.com" Gender="Male" /> <comment Nam
<?xml version="1.0" encoding="utf-8"?>
<entry>
<comment Name="xxx" Location="India" Email="xxx@email.com" Gender="Male" />
<comment Name="yyy" Location="usa" Email="yyy@email.com" Gender="Male" />
<comment Name="zzz" Location="uae" Email="zzz@email.com" Gender="Male" />
<comment Name="abc" Location="china" Email="abc@email.com" Gender="Male" />
</entry>
如何在ASP.NET中仅显示注释标记的数据(例如名称、位置、电子邮件、性别)?请帮忙。谢谢。输出
代码隐藏
加价
在项目中添加Xml文件您可以使用具有树视图、中继器控件的Xml数据源
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" XPath="entry" >
</asp:XmlDataSource>
//Repeater
<asp:Repeater ID="Repeater1"
runat="server"
DataSourceID="XmlDataSource1">
<ItemTemplate>
<h2>Entry</h2>
<table>
<tr>
<td><%#XPath("comment[1]/@Name")%></td>
<td><%#XPath("comment[1]/@Location")%></td>
<td><%#XPath("comment[1]/@Email")%></td>
<td><%#XPath("comment[1]/@Gender")%></td>
</tr>
<tr>
<td><%#XPath("comment[2]/@Name")%></td>
<td><%#XPath("comment[2]/@Location")%></td>
<td><%#XPath("comment[2]/@Email")%></td>
<td><%#XPath("comment[2]/@Gender")%></td>
</tr>
<td><%#XPath("comment[3]/@Name")%></td>
<td><%#XPath("comment[3]/@Location")%></td>
<td><%#XPath("comment[3]/@Email")%></td>
<td><%#XPath("comment[3]/@Gender")%></td>
</tr>
<tr>
<td><%#XPath("comment[4]/@Name")%></td>
<td><%#XPath("comment[4]/@Location")%></td>
<td><%#XPath("comment[4]/@Email")%></td>
<td><%#XPath("comment[4]/@Gender")%></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
// Output
Entry
xxx India xxx@email.com Male
yyy usa yyy@email.com Male
zzz uae zzz@email.com Male
abc china abc@email.com Male
//中继器
进入
//输出
进入
xxx印度xxx@email.com男性
yyy美国yyy@email.com男性
zzz阿联酋zzz@email.com男性
abc中国abc@email.com男性
您还应该投票选出最能满足您需求的答案
<asp:GridView ID="grd" runat="server"></asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" XPath="entry" >
</asp:XmlDataSource>
//Repeater
<asp:Repeater ID="Repeater1"
runat="server"
DataSourceID="XmlDataSource1">
<ItemTemplate>
<h2>Entry</h2>
<table>
<tr>
<td><%#XPath("comment[1]/@Name")%></td>
<td><%#XPath("comment[1]/@Location")%></td>
<td><%#XPath("comment[1]/@Email")%></td>
<td><%#XPath("comment[1]/@Gender")%></td>
</tr>
<tr>
<td><%#XPath("comment[2]/@Name")%></td>
<td><%#XPath("comment[2]/@Location")%></td>
<td><%#XPath("comment[2]/@Email")%></td>
<td><%#XPath("comment[2]/@Gender")%></td>
</tr>
<td><%#XPath("comment[3]/@Name")%></td>
<td><%#XPath("comment[3]/@Location")%></td>
<td><%#XPath("comment[3]/@Email")%></td>
<td><%#XPath("comment[3]/@Gender")%></td>
</tr>
<tr>
<td><%#XPath("comment[4]/@Name")%></td>
<td><%#XPath("comment[4]/@Location")%></td>
<td><%#XPath("comment[4]/@Email")%></td>
<td><%#XPath("comment[4]/@Gender")%></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
// Output
Entry
xxx India xxx@email.com Male
yyy usa yyy@email.com Male
zzz uae zzz@email.com Male
abc china abc@email.com Male