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")%>
.
<%# XPath("Team/@Name")%>
<asp:TextBox Width="32" runat="server"
ID="txtWager"></asp:TextBox><br />
</ItemTemplate>
<SeparatorTemplate>
-----------------------------
<br />
</SeparatorTemplate>
</asp:Repeater>

I'm sure you'll get the point when you compare this to your XML file

Hope this is helpful
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
MCPD: Enterprise Application Developer


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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top