DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 31 Jul 2007 15:22:03 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    pelegk1
          2    Alexey Smirnov


xml nodes and getting random node   
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
Date:Tue, 31 Jul 2007 15:22:03 -0700   Author:  

Re: xml nodes and getting random node   
On Aug 1, 12:22 am, pelegk1  wrote:

> 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


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++;
  }
}
Date:Wed, 01 Aug 2007 03:35:59 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us