I have the following xml file:
<settings>
<setting>
<enabled>1</enabled>
<urls>
<url>http://ift.tt/1qCAPBs;
<url>http://ift.tt/1sH0nfg;
<url>http://ift.tt/UiCU9h;
</urls>
<keycode>123</keycode>
</setting>
</settings>
I am trying to access the items so that i may select one at random. My idea was to count the items and ten retrieve one based on a random number generation. Something like this...
XMLNodeList urlList = xml.SelectNodes("/settings/setting/urls");
int count = urlList.Count;
int rnd = new Random().Next(0,count);
Console.WriteLine(urlList.Item(rnd).InnerText);
However, my problem seems to be that urlList.Item
will only retrieve item 0 and not any other number. Is there a better way of doing this, or am i going about the entire thing incorrectly?
No comments:
Post a Comment