Complete newview here with XML, to it seems possible that either my data is poorly build, or I'm just missing something major with Xpath. I've read the XPath turorial at W3school (href="http://www.w3schools.com/xpath/default.asp) and thought I understood
it. But that seems not to be the case.
My goal: create a checkboxlist with the slide child node from the Crocus node.
gardenerhand...
Member
7 Points
20 Posts
Newbie who is in the dark waters of xpath and xml
Mar 07, 2012 01:51 AM|LINK
Hi All,
Complete newview here with XML, to it seems possible that either my data is poorly build, or I'm just missing something major with Xpath. I've read the XPath turorial at W3school (href="http://www.w3schools.com/xpath/default.asp) and thought I understood it. But that seems not to be the case.
My goal: create a checkboxlist with the slide child node from the Crocus node.
My xml datafile (Cardsets.xml)
<?xml version="1.0" encoding="utf-8" ?> <root> <Cardset id="1" Name="Crocus" Price="20.00"> <Show> <slide num="1" file="Crocus00" caption="Sample Text1" bg="96C1E2" orient="H" /> <slide num="2" file="Crocus01" caption="Sample 2" bg="F3DFA2" orient="V" /> <slide num="3" file="Crocus02" caption="Last sample (4)" bg="7C8AA7" orient="H" /> </Show> </Cardset> <Cardset id="2" Name="Daffodils" Price="20.00"> <Show > <slide num="1" file="Daffodils00" caption="First sample" bg="7C8AA7" orient="V" /> <slide num="2" file="Daffodils01" caption="Second sample" bg="96C1E2" orient="V" /> <slide num="3" file="Daffodils02" caption="Third sample" bg="F3DFA2" orient="H" /> </Show> </Cardset> </root> My code (I'm not opposed to using vb is that makes things easier)asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Cardsets.xml" XPath="Root/Cardset[@id='1']/Show/*"></asp:XmlDataSource> <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="XmlDataSource1" DataTextField="Name" DataValueField="Name"> </asp:CheckBoxList>xpath
jigarbjpatel
Member
454 Points
88 Posts
Re: Newbie who is in the dark waters of xpath and xml
Mar 07, 2012 03:02 AM|LINK
Please use the following code. Set DataTextField and DataValueField values appropriately.
<form action="default.aspx" method="post" runat="server"> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Cardsets.xml" XPath="/root/Cardset[@id='1']/Show/slide"></asp:XmlDataSource> <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="XmlDataSource1" DataTextField="caption" DataValueField="num" > </asp:CheckBoxList> </form>Please mark it as answer if it helped you
gardenerhand...
Member
7 Points
20 Posts
Re: Newbie who is in the dark waters of xpath and xml
Mar 07, 2012 04:57 AM|LINK
Thank you jigarbjpatel. So many typos on my part, but a mixed up syntax.