1

Here is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<entry>
 <comment Name="xxx" Location="India" Email="[email protected]" Gender="Male" />
 <comment Name="yyy" Location="usa" Email="[email protected]" Gender="Male" />
 <comment Name="zzz" Location="uae" Email="[email protected]" Gender="Male" />
 <comment Name="abc" Location="china" Email="[email protected]" Gender="Male" />
</entry>

How do I display only the comment tags' data (e.g. name,location,email,gender) in ASP.NET? Please help. Thank you.

1
  • you should also upvote answers that best adresses ur needs Commented Aug 7, 2012 at 5:35

2 Answers 2

1

Output

enter image description here


Code Behind

using (DataSet ds = new DataSet())
{
    ds.ReadXml(MapPath("XMLFile1.xml"));
    grd.DataSource = ds;
    grd.DataBind();
}

Mark Up

<asp:GridView ID="grd" runat="server"></asp:GridView>

Add an Xml File in the Project

Sign up to request clarification or add additional context in comments.

Comments

1

You can use an Xml Data Source with Tree view, Repeater control as

<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   [email protected]   Male
yyy usa [email protected]   Male
zzz uae [email protected]   Male
abc china   [email protected]   Male

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.