How to target an XML dynamicly?


private var myXML:XML = 
        <companies>
            <company name="Sun Inc.">
                <department name="Accounting">
                    <employee name="Paul"/>
                    <employee name="Jill"/>
                </department>
                <department name="Development">
                    <employee name="Ann"/>
                    <employee name="Peter"/>
                </department>
            </company>
            <company name="Moon Inc.">
                <department name="Accounting">
                    <employee name="Bill"/>
                    <employee name="Sam"/>
                </department>
                <department name="Development">
                    <employee name="Jenny"/>
                    <employee name="John"/>
                </department>
            </company>
        </companies>;

private var myNewXML:XML;

private function init():void {
    myNewXML = myXML.copy();
    delete myNewXML.company.department.employee;

    getContent(myNewXML.company[1].department[1]);
}

private function getContent(xml:XML):void {
    //get xml employees from myXML based on the xmlobject i get
}

Based on the position in myNewXML, how do I dynamicly get the content in the original myXML (I want to extract the employees from the myXML)?

I know I can get the position with xml.childIndex() and traverse through parents with xml.parent() but I dont know how I would write the syntax to actually target the original myXML.

(This code is simplified and cut down from a larger context, it may seem abit pointless in this context)