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 / August 2007

Tip: Looking for answers? Try searching our database.

xml nodes and getting random node

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pelegk1 - 31 Jul 2007 23:22 GMT
i have an xml for example:
<xml>
<data>
<var>xxx</var>
</data>
<tip>
<tips active="1">345</tips>
<tips active="1">retertert</tips>
<tips active="1">fdgdfg</tips>
<tips active="0">ert435345</tips>
<tips active="1">fdgdf</tips>
<tips active="1">dfgdfg</tips>
<tips active="0">gdfgdfg</tips>
<tips active="1">dfgdfg</tips>
<tips active="1">dfgdfg</tips>
</tip>
</xml>

and i want to get only the nodes that active="1" and get from then a radnom
one (to get actually its text() )
how can i do this?
thnaks in advance
peleg
Alexey Smirnov - 01 Aug 2007 11:35 GMT
> i have an xml for example:
> <xml>
[quoted text clipped - 19 lines]
> thnaks in advance
> peleg

Try this

XmlNodeList nodes = xmlDoc.SelectNodes("//tip/tips[@active='1']");

Random r = new Random();
int x = r.Next(0, nodes.Count);
int i = 0;

foreach(XmlNode node in nodes) {
 if (i == x) {
     here's your code
     ...
     return;

 } else {
     x++;
 }
}

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.