# Return XML from Function

**URL:** <https://forum.kirupa.com/t/return-xml-from-function/311928>\
**Category:** flash\
**Created:** [July 20, 2010, 4:09pm UTC](https://forum.kirupa.com/t/return-xml-from-function/311928 "2010-07-20T16:09:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KiKaL](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@KiKaL](https://forum.kirupa.com/u/KiKaL)\
**Post date:** [July 20, 2010, 4:09pm UTC](https://forum.kirupa.com/t/return-xml-from-function/311928/1 "2010-07-20T16:09:02Z")

</div>

I feel like this should be correct but the trace always returns ‘undefined’

```php

function loadXML(xmlFile:String):XML{ 
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData = new XML(xmlLoader.load(new URLRequest(xmlFile)));
    return xmlData;
}

var xmlData:XML = loadXML("xml/nav.xml"); 
trace(xmlData.link.image.text() [0]);

```

Here’s the XML

```php
<nav>
    <link id="1">
        <name>home </name>
        <image>images/home.jpg</image>
        <path>http://www.bing.com/</path>
    </link>
    <link id="2">
        <name>outdoor</name>
        <image>images/kitchen.jpg</image>
        <path>http://www.google.com/</path>
    </link>
    <link id="3">
        <name>living</name>
        <image>images/bath.jpg</image>
        <path>http://www.yahoo.com/</path>
    </link>
    <link id="4">
        <name>kitchen</name>
        <image>images/kitchen.jpg</image>
        <path>http://www.dogpile.com/</path>
    </link>
    <link id="5">
        <name>bedroom</name>
        <image>images/bath.jpg</image>
        <path>http://www.google.com/</path>
    </link>
    <link id="6">
        <name>workspace</name>
        <image>images/home.jpg</image>
        <path>http://www.yahoo.com/</path>
    </link>
        <link id="7">
        <name>bath</name>
        <image>images/bath.jpg</image>
        <path>http://www.bing.com/</path>
    </link>
</nav>

```

What am I doing wrong?
