Solved

How to bind a nested xml file to repeater control?

Posted on 2011-03-19
2
855 Views
Last Modified: 2012-05-11
Hello experts,

I have had some expert help with binding a flat xml file.  Now I need to bind a nested xml file to a repeater (in my case two repeaters, one indide the other).  I have attached the file and my current code which works in that it displays the teams, the team id (ident) and team homes but does not display the members.

My display looks like:

QU
3
QATAR

VCU
1
Vancouver

MUN
2
Memorial

CNAQ
0
Newfoundland

I need the team members to display.  I have read a lot on the net about this but I cannot, no matter what I try, get this to work.

Please save me.

Interestingly, if I delete the home and positions nnodes, I can display the team members.  I don't, however, have any control over the structure of the xml file.

Thanks

Vince
<asp:Repeater ID="Repeater" runat="server" DataSourceID="XmlDataSource">
         <ItemTemplate>
              <strong><%# XPath("@name") %><br /></strong>
              
              <%#XPath("@ident")%><br />
              <%#XPath("home")%><br /><br />
              <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# XPathSelect("round/team/home/positions/member") %>'>                   
              <ItemTemplate>
              Speaker: <asp:Label ID="LabelSpeaker" runat="server" Text='<%# XPath("@name") %>' />
                             
              </ItemTemplate>                    
              <SeparatorTemplate><br /></SeparatorTemplate>                
              </asp:Repeater>
            </ItemTemplate>
        </asp:Repeater>
        <asp:XmlDataSource ID="XmlDataSource" runat="server" DataFile="~/Data/teams1-main.xml" >
        </asp:XmlDataSource>

Open in new window

<?xml version='1.0' encoding='utf-8'?>
<round name="main" parent="main" knockout="no">
  <team name="QU" ident="3" pullups="0">
    <home>QATAR</home>
    <positions></positions>
    <member name="Queenie">
      <points>0</points>
      <rounds>0</rounds>
    </member>
    <member name="Queller">
      <points>0</points>
      <rounds>0</rounds>
    </member>
  </team>
  <team name="VCU" ident="1" pullups="0">
    <home>Vancouver</home>
    <positions></positions>
    <member name="Victor">
      <points>0</points>
      <rounds>0</rounds>
    </member>
    <member name="Victoria">
      <points>0</points>
      <rounds>0</rounds>
    </member>
  </team>
  <team name="MUN" ident="2" pullups="0">
    <home>Memorial</home>
    <positions></positions>
    <member name="Mandy">
      <points>0</points>
      <rounds>0</rounds>
    </member>
    <member name="Mary">
      <points>0</points>
      <rounds>0</rounds>
    </member>
  </team>
  <team name="CNAQ" ident="0" pullups="0">
    <home>Newfoundland</home>
    <positions></positions>
    <member name="Feras">
      <points>0</points>
      <rounds>0</rounds>
    </member>
    <member name="Mohd">
      <points>0</points>
      <rounds>0</rounds>
    </member>
  </team>
</round>

Open in new window

0
Comment
Question by:vstack
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35179051
The following:
XPathSelect("round/team/home/positions/member")

Open in new window

Should say:
 XPathSelect("member")

Open in new window

As you are binding the nested repeater to a child node of the "team" node, you need to specify the XPath relative to the context node.
0
 

Author Closing Comment

by:vstack
ID: 35908583
Ok.  It's tken me some time to figure out nested xml files.  Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacing HTML tags in Textarea/Textbox 5 47
ASP.NET reading ATOM 2 51
Problem to page 4 74
Syntax error 9 45
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now