Solved

How to bind a nested xml file to repeater control?

Posted on 2011-03-19
2
846 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
Comment Utility
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
Comment Utility
Ok.  It's tken me some time to figure out nested xml files.  Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

16 Experts available now in Live!

Get 1:1 Help Now