asp.net random xpath

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
 
G

Guest

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
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top