asp.net random xpath

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

if for example i have an xml with 10 childnodes
and i want by random to get 1 of them how do i do that?
my current code that work with is :
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
XPath="MainPage"
DataFile="~/xml/MainPage.xml"></asp:XmlDataSource>
<asp:DataList ID="FeedList" runat="server" DataSourceID="XmlDataSource1">
<ItemTemplate>
....html page
<a href="<%#XPath("logo/@url")%>">xxx</a>
</ItemTemplate>
</asp:DataList>

is this possible?
thnaks i nadvance
peleg
 
Hi,
You can try something like this:
nNodes = root.childNodes.length;
// Generate random number
var nRand = Math.floor(Math.random() * nNodes) + 1;
var node = root.selectSingleNode("logo[" + nRand + "]");
Although above code is in javascript you can easily convert it to C# OR VB.NET
 
Back
Top