Xpath with XMLDatasource

D

Disccooker

i am trying to use XPath and the XMLDataSource to display data from an
XMLDocument and am getting nowhere. What i would like to do is have a
repeater display a label for Seed, label for Team Name and a Text Box
for each game - like an NCAA bracket.

1. Team1 [__]
16. Bradley [__]

8. Missouri [__]
9. USM [__]

and so on.



I have created an XMLDataSource like so:

<asp:XmlDataSource OnDataBinding="XmlDataSource1_DataBind"
ID="XmlDataSource1" runat="server" DataFile="/ncaa/App_Data/
Round1.xml" XPath="Head2Head/Round[@Id='First']/Bracket[@Id='A']">
</asp:XmlDataSource>

and a repeater like so:
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="XmlDataSource1">
<ItemTemplate>
<%# XPath("@Seed") %>. <%# XPath("@name") %> <asp:TextBox
Width="32" runat="server" ID="txtWager"></asp:TextBox><br />
</ItemTemplate>
<SeparatorTemplate>
-----------------------------<br />
</SeparatorTemplate>
</asp:Repeater>
here is my xml:
<Head2Head xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Head2Head.xsd">
<Round Id="First">
<Bracket Id="A">
<Game Pgm="P01">
<Team Rnr="1" Name="Team 1" Odds="9-1" Seed="1"/>
<Team Rnr="2" Name="Team 16" Odds="2-1" Seed="16"/>
</Game>
<Game Pgm="P02">
<Team Rnr="1" Name="Team 8" Odds="9-1" Seed="8"/>
<Team Rnr="2" Name="Team 9" Odds="2-1" Seed="9"/>
</Game>
</Bracket>
</Round>
</Head2Head>

so, what am i doing wrong? i tried creating two datasources, and two
repeaters, still nothin.
 
G

Guest

Your XPath Query is incorrect
1)Your XPath should be like this:
XPath="Head2Head/Round[@Id='First']/Bracket[@Id='A']/Game"
So your XmlDataSource will be like this
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/App_Data/Round1.xml"

XPath="Head2Head/Round[@Id='First']/Bracket[@Id='A']/Game"></asp:XmlDataSource>

2)Your XPath binding expression in the repeater should be like this as you
wish to display an attribute value
<%# XPath("Team/@Seed")%>
Your final repeater code should be similar to this
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
<ItemTemplate>
<%# XPath("Team/@Seed")%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top