Choose a random XML element

Let’s say I have this xml:

Foligno Madonna, by Raphael Madonna Foligno Madonna, by Raphael Foligno Madonna, by Raphael

… and I want to choose an img element at random. Can someone point me in the right direction?

Thanks.

xmlel = CreateObject("roXmlElement")
xmlel.Parse(xml)  ' should check return value
rndimg = xmlel.img[rnd(xmlel.img.Count())-1]
src = rndimg@src
alt = rndimg@alt

-JT

Given the example parsed into roXmlElement xml:


BrightScript Debugger> choice = rnd(xml.img.count()) - 1    
BrightScript Debugger> ? choice, xml.img[choice]
 2            <Component: roXMLElement>
BrightScript Debugger> ? xml.img[choice].genXML(0)
<img alt="Foligno Madonna, by Raphael" src="madonna3.jpg" />