How to get the value of the xml attributes


I would like to get the information of an xml file so that I can show it in a clip.

I can import my xml file and print out all of its data with trace() but I can’t make a simple to print the values the attributes of each node.

Here is my very simple xml file, called doc.xml

    <person name="foo" age="18" />
    <person name="bar" age="19" />

My loading function for the xml file works, but not the one with my loop to get the attributes values.

// LOADING OF THE XML (works well)
var loader:URLLoader = new URLLoader();
var adress:URLRequest = new URLRequest ("doc.xml");


loader.addEventListener(Event.COMPLETE, loadXML);

function loadXML(eventObject:Event){
    var xml = new XML(;

// error 1120: Access of undefined property xml.
function printXML(eventObject:Event){
    var myarray = xml.firstChild.childNodes;
    for (var i = 0; i < myarray.length; i++)
        var current = myarray*;

What do I have to modify in my printXML function so that I can get in my loop the value of the attributes of each nodes?

many thanks for your help