473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

asp.net random xpath

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

Jul 22 '07 #1
1 1585
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
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"pelegk1" wrote:
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
Jul 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
by: sal achhala | last post by:
I'm working with java and XML documents in order to search for keywords in a given element name, eg element name 'author' == "jo blogs". The problem is the XML documents are downloaded (this...
2
by: Robert | last post by:
I have the XML file which has a structure similar to one I pasted at the end of this post. As you can see many elements are using different id attributes. For example element Window uses WinID...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
13
by: mfreeman | last post by:
The minimal code (VB.NET 2003) needed to show this problem is shown below. All I do is loop through the records in the table and update them without making any changes. Out of 600 records, about...
1
by: rsotolongo | last post by:
I need generate randoms XPath expressions to make queries to XML documents. Someone can help me to find a component (class) that auto generate XPath expressions???. Maybe, someone can say me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.