Use a variable's value as the element name to find:
package{
import flash.display.Sprite;
publicclass Main extends Sprite{
public function Main(){
var nodeName:String = "color";
var fruit:XML = <fruit><color>red</color></fruit>;
trace( fruit[nodeName] );
}
}
}