Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

asp.net random xpath

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pelegk1 - 22 Jul 2007 22:32 GMT
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
Manish Bafna - 23 Jul 2007 04:12 GMT
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
Signature

Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> 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?
[quoted text clipped - 12 lines]
> thnaks i nadvance
> peleg

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.