Solved

How to bind a nested xml file to repeater control?

Posted on 2011-03-19
2
864 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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