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++;
}
}